U
    YSh                     @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddd	d
gee Zi Zi Zdd Zdd Zdd	 Zdd Zdd Zddd
Zdd ZG dd dejZeje ZeeZejej eeje< e`e`e`e`dS )z
    pygments.formatters
    ~~~~~~~~~~~~~~~~~~~

    Pygments formatters.

    :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)basename)
FORMATTERS)find_plugin_formatters)ClassNotFoundget_formatter_by_nameget_formatter_for_filenameget_all_formattersload_formatter_from_filec                 C   s8   |t kr*tt| }t |< || S t | | S )zBReturn whether the supplied file name fn matches pattern filename.)_pattern_cacherecompilefnmatch	translatematch)fnglobpattern r   O/root/rtd-docs/venv/lib/python3.8/site-packages/pygments/formatters/__init__.py_fn_matches   s    
r   c                 C   s4   t | dddg}|jD ]}t||}|t|j< qdS )z4Load a formatter (and all others in the module too).N__all__)
__import__r   getattr_formatter_cachename)module_namemodZformatter_nameclsr   r   r   _load_formatters$   s    

r   c                  c   sN   t  D ]*} | d tkr$t| d  t| d  V  qt D ]\}}|V  q:dS )z-Return a generator for all formatter classes.   r   N)r   valuesr   r   r   )info_	formatterr   r   r   r   ,   s    c                 C   sb   t  D ]2\}}}}}| |kr|tkr.t| t|   S qt D ]\}}| |jkrB|  S qBdS )zALookup a formatter by alias.

    Returns None if not found.
    N)r   r    r   r   r   aliases)aliasr   r   r$   r"   r   r   r   r   find_formatter_class7   s    
r&   c                 K   s(   t | }|dkrtd| |f |S )a  
    Return an instance of a :class:`.Formatter` subclass that has `alias` in its
    aliases list. The formatter is given the `options` at its instantiation.

    Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that
    alias is found.
    Nzno formatter found for name )r&   r   )_aliasoptionsr   r   r   r   r   F   s    CustomFormatterc              
   K   s   zXi }t | d}t| | W 5 Q R X ||krFtd| d|  || }|f |W S  tk
r } ztd|  d| W 5 d}~X Y nD tk
r    Y n0 tk
r } ztd| W 5 d}~X Y nX dS )a#  
    Return a `Formatter` subclass instance loaded from the provided file, relative
    to the current directory.

    The file is expected to contain a Formatter class named ``formattername``
    (by default, CustomFormatter). Users should be very careful with the input, because
    this method is equivalent to running ``eval()`` on the input file. The formatter is
    given the `options` at its instantiation.

    :exc:`pygments.util.ClassNotFound` is raised if there are any errors loading
    the formatter.

    .. versionadded:: 2.2
    rbz	no valid z class found in zcannot read z: Nz%error when loading custom formatter: )openexecreadr   OSError	Exception)filenameZformatternamer(   custom_namespacefformatter_classerrr   r   r   r	   T   s    $c           	      K   s   t | } t D ]H\}}}}}|D ]4}t| |r"|tkr@t| t| f |    S q"qt D ]0\}}|jD ] }t| |rn|f |    S qnq`td| dS )a  
    Return a :class:`.Formatter` subclass instance that has a filename pattern
    matching `fn`. The formatter is given the `options` at its instantiation.

    Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename
    is found.
    z!no formatter found for file name N)	r   r   r    r   r   r   r   	filenamesr   )	r   r(   modnamer   r"   r5   r0   _namer   r   r   r   r   v   s    


c                   @   s   e Zd ZdZdd ZdS )_automodulez Automatically import formatters.c                 C   sB   t |}|r6t|d  t|d  }t| || |S t|d S )Nr   r   )r   getr   r   setattrAttributeError)selfr   r!   r   r   r   r   __getattr__   s    
z_automodule.__getattr__N)__name__
__module____qualname____doc__r=   r   r   r   r   r8      s   r8   )r)   ) rA   r   systypesr   os.pathr   Zpygments.formatters._mappingr   Zpygments.pluginr   Zpygments.utilr   listr   r   r
   r   r   r   r&   r   r	   r   
ModuleTyper8   modulesr>   oldmodnewmod__dict__updater   r   r   r   <module>   s:   
 
"

