a
    €˜ëjè  ã                   @   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 g d¢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-present 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 v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   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/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v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    r   c                 C   sb   t  ¡ D ]2\}}}}}| |v r|tvr.t|ƒ t|   S qtƒ D ]\}}| |jv 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u rtd| ›�ƒ‚|f i |¤Ž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    r   ÚCustomFormatterc              
   K   sð   zpi }t | dƒ�}t| ¡ |ƒ W d  ƒ n1 s40    Y  ||vrZtd|› d| › �ƒ‚|| }|f i |¤ŽW S  ty¨ } z td| › d|› �ƒ‚W Y d}~nLd}~0  tyº   ‚ Y n2 tyê } ztd|› �ƒ‚W Y d}~n
d}~0 0 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
    ÚrbNz	no valid z class found in zcannot read z: z%error when loading custom formatter: )ÚopenÚexecÚreadr   ÚOSErrorÚ	Exception)ÚfilenameZformatternamer(   Zcustom_namespaceÚfÚformatter_classÚerrr   r   r   r	   T   s    ,(r	   c           	      K   s¬   t | ƒ} t ¡ D ]L\}}}}}|D ]8}t| |ƒr"|tvr@t|ƒ t| f i |¤Ž    S q"qtƒ D ]4\}}|jD ]$}t| |ƒrr|f i |¤Ž    S qrqdt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"   r4   r0   Ú_namer   r   r   r   r   v   s    


r   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   r7   Œ   s   r7   )r)   ) r@   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   Ú
ModuleTyper7   Úmodulesr=   ZoldmodZnewmodÚ__dict__Úupdater   r   r   r   Ú<module>   s4   
ÿ
"

