o
    ‡ÎÖaÛ  ã                   @   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-2021 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   ú>/usr/lib/python3/dist-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ÚmodÚformatter_nameÚclsr   r   r   Ú_load_formatters$   s
   

þr   c                  c   sP   � 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 ]\}}}}}| |v r|tvrt|ƒ t|   S qtƒ D ]\}}| |jv r.|  S q!d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|  ƒ‚|di |¤ŽS )zYLookup and instantiate a formatter by alias.

    Raises ClassNotFound if not found.
    Nzno formatter found for name %rr   )r'   r   )Ú_aliasÚoptionsr   r   r   r   r   F   s   r   ÚCustomFormatterc              
   K   sÆ   z6i }t | dƒ�}t| ¡ |ƒ W d  ƒ n1 sw   Y  ||vr+td|| f ƒ‚|| }|di |¤ŽW S  tyJ } ztd| |f ƒ‚d}~w tyQ   ‚  tyb } ztd| ƒ‚d}~ww )a!  Load a formatter from a file.

    This method expects a file located relative to the current working
    directory, which contains a class named CustomFormatter. By default,
    it expects the Formatter to be named CustomFormatter; you can specify
    your own class name as the second argument to this function.

    Users should be very careful with the input, because this method
    is equivalent to running eval on the input file.

    Raises ClassNotFound if there are any problems importing the Formatter.

    .. versionadded:: 2.2
    ÚrbNzno valid %s class found in %szcannot read %s: %sz'error when loading custom formatter: %sr   )ÚopenÚexecÚreadr   ÚOSErrorÚ	Exception)ÚfilenameÚformatternamer)   Úcustom_namespaceÚfÚformatter_classÚerrr   r   r   r	   Q   s(   ÿÿ€€ÿr	   c                 K   s¢   t | ƒ} t ¡ D ]&\}}}}}|D ]}t| |ƒr-|tvr t|ƒ t| di |¤Ž    S qqtƒ D ]}|jD ]}t| |ƒrI|di |¤Ž    S q7q2td|  ƒ‚)zdLookup and instantiate a formatter by filename pattern.

    Raises ClassNotFound if not found.
    z#no formatter found for file name %rNr   )	r   r   r!   r   r   r   r   Ú	filenamesr   )r   r)   Úmodnamer   r#   r7   r1   r   r   r   r   r   u   s    
ýÿ


ÿÿr   c                   @   s   e Zd ZdZdd„ ZdS )Ú_automodulez Automatically import formatters.c                 C   s>   t  |¡}|rt|d ƒ t|d  }t| ||ƒ |S t|ƒ‚)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   r9   ˆ   s    r9   )r*   ) rB   r   ÚsysÚtypesr   Úos.pathr   Úpygments.formatters._mappingr   Úpygments.pluginr   Úpygments.utilr   Úlistr   r   r
   r   r   r   r'   r   r	   r   Ú
ModuleTyper9   Úmodulesr?   ÚoldmodÚnewmodÚ__dict__Úupdater   r   r   r   Ú<module>   s6    
ÿ
$

