o
    Zh                     @   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-2023 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   S/var/www/html/lang_env/lib/python3.10/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   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 )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 %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#  
    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 %s class found in %szcannot read %s: %sz'error when loading custom formatter: %sr   )openexecreadr   OSError	Exception)filenameZformatternamer(   custom_namespacefformatter_classerrr   r   r   r	   T   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| |rK|di |    S q9q2td|  )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 %rNr   )	r   r   r    r   r   r   r   	filenamesr   )	r   r(   modnamer   r"   r5   r0   _namer   r   r   r   r   w   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   r8      s    r8   )r)   ) rA   r   systypesr   Z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>   s6    

#

