o
    	ȷev+                     @   sH  d 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lmZ ddlmZmZ d	d
dZg dee ee Zi Zdd Zd)ddZdd Zdd Zdd Zd*ddZd+ddZd+ddZdd  Zd)d!d"Z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.lexers
    ~~~~~~~~~~~~~~~

    Pygments lexers.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)fnmatch)basename)LEXERS)get_filetype_from_buffer)find_plugin_lexers)ClassNotFoundguess_decodePythonLexerPythonTracebackLexer)Python3LexerPython3TracebackLexer)get_lexer_by_nameget_lexer_for_filenamefind_lexer_classguess_lexerload_lexer_from_filec                 C   s4   t | dddg}|jD ]}t||}|t|j< qdS )z0Load a lexer (and all others in the module too).N__all__)
__import__r   getattr_lexer_cachename)module_namemod
lexer_namecls r   O/var/www/ideatree/venv/lib/python3.10/site-packages/pygments/lexers/__init__.py_load_lexers    s
   

r   Tc                 c   sL    t  D ]	}|dd V  q| r"t D ]}|j|j|j|jfV  qdS dS )a  Return a generator of tuples in the form ``(name, aliases,
    filenames, mimetypes)`` of all know lexers.

    If *plugins* is true (the default), plugin lexers supplied by entrypoints
    are also returned.  Otherwise, only builtin ones are considered.
       N)r   valuesr   r   aliases	filenames	mimetypes)pluginsitemlexerr   r   r   get_all_lexers(   s   
r&   c                 C   sf   | t v rt |  S t D ]\}}}}}| |kr!t| t |    S qt D ]}|j| kr0|  S q%dS )zALookup a lexer class by name.

    Return None if not found.
    N)r   r   r   r   r   r   )r   r   lnamer    _r   r   r   r   r   6   s   

r   c                 C   s~   | st d|  t D ]\}}}}}|  |v r'|tvr!t| t|   S qt D ]}|  |jv r8|  S q+t d|  )zLookup a lexer class by alias.

    Like `get_lexer_by_name`, but does not instantiate the class.

    .. versionadded:: 2.2
    no lexer for alias %r foundr   r   r   lowerr   r   r   r    )_aliasr   r   r    r(   r   r   r   r   find_lexer_class_by_nameH   s   
r-   c                 K   s   | st d|  t D ] \}}}}}|  |v r,|tvr!t| t| di |  S qt D ]}|  |jv rB|di |  S q0t d|  )zEGet a lexer by an alias.

    Raises ClassNotFound if not found.
    r)   Nr   r*   )r,   optionsr   r   r    r(   r   r   r   r   r   ^   s   
r   CustomLexerc              
   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 lexer from a file.

    This method expects a file located relative to the current working
    directory, which contains a Lexer class. By default, it expects the
    Lexer to be name CustomLexer; 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 Lexer.

    .. versionadded:: 2.2
    rbNzno valid %s class found in %szcannot read %s: %sz#error when loading custom lexer: %sr   )openexecreadr   OSError	Exception)filename	lexernamer.   custom_namespaceflexer_classerrr   r   r   r   s   s(   r   c                    s   g }t | }t D ]"\}}}}}|D ]}t||r+|tvr"t| |t| |f qq
t D ]}	|	jD ]}t||rC||	|f q5q0t	 t
rNt   fdd}
|rb|j|
d |d d S dS )zGet a lexer for a filename.

    If multiple lexers match the filename pattern, use ``analyse_text()`` to
    figure out which one is more appropriate.

    Returns None if not found.
    c                    s@   | \}}d|vr
dpd} r|  | |jfS |j| |jfS )N*g      ?r   )analyse_text__name__priority)infor   r6   bonuscoder   r   
get_rating   s
   z1find_lexer_class_for_filename.<locals>.get_ratingkeyr   N)r   r   r   r   r   r   appendr   r!   
isinstancebytesr   sort)_fnrC   matchesfnmodnamer   r(   r!   r6   r   rD   r   rB   r   find_lexer_class_for_filename   s.   




rP   c                 K   s(   t | |}|std|  |di |S )zGet a lexer for a filename.

    If multiple lexers match the filename pattern, use ``analyse_text()`` to
    figure out which one is more appropriate.

    Raises ClassNotFound if not found.
    no lexer for filename %r foundNr   )rP   r   )rL   rC   r.   resr   r   r   r      s   
r   c                 K   sz   t  D ]\}}}}}| |v r"|tvrt| t| di |  S qt D ]}| |jv r6|di |  S q&td|  )zHGet a lexer for a mimetype.

    Raises ClassNotFound if not found.
    zno lexer for mimetype %r foundNr   )r   r   r   r   r   r"   r   )_mimer.   rO   r   r(   r"   r   r   r   r   get_lexer_for_mimetype   s   

rT   c                 c   sV    t tD ]}t| dd \}}|tvrt| t| V  q| r)t E dH  dS dS )z*Return an iterator over all lexer classes.N   )sortedr   r   r   r   )r#   rF   r   r   r   r   r   _iter_lexerclasses   s   rW   c           
         s
  t | }i  t }t D ]*}|jD ]}t||r!|| d |< q|jD ]}t||r5|| d |< q%q|s?td| t|dkrN|	 di |S g }|D ]}|
|}|dkrf|di |  S |||f qR fdd}	|j|	d |d	 d di |S )a  
    Lookup all lexers that handle those filenames primary (``filenames``)
    or secondary (``alias_filenames``). Then run a text analysis for those
    lexers and choose the best result.

    usage::

        >>> from pygments.lexers import guess_lexer_for_filename
        >>> guess_lexer_for_filename('hello.html', '<%= @foo %>')
        <pygments.lexers.templates.RhtmlLexer object at 0xb7d2f32c>
        >>> guess_lexer_for_filename('hello.html', '<h1>{{ title|e }}</h1>')
        <pygments.lexers.templates.HtmlDjangoLexer object at 0xb7d2f2ac>
        >>> guess_lexer_for_filename('style.css', 'a { color: <?= $link ?> }')
        <pygments.lexers.templates.CssPhpLexer object at 0xb7ba518c>
    TFrQ   r         ?c                    s$   | d  | d  | d j | d jfS Nr   r   )r?   r>   )tprimaryr   r   	type_sort  s   $z+guess_lexer_for_filename.<locals>.type_sortrE   rG   Nr   )r   setrW   r!   r   addalias_filenamesr   lenpopr=   rH   rK   )
rL   _textr.   rN   matching_lexersr%   r6   resultrvr]   r   r[   r   guess_lexer_for_filename   s8   







rg   c                 K   s   t | ts|d|d}|r| |pd} nt| \} }t| }|dur9z	t|fi |W S  ty8   Y nw ddg}t D ]"}|	| }|dkrT|d
i |  S ||d krb||f|dd< q@|d rm|d du rqtd	|d d
i |S )z?Guess a lexer by strong distinctions in the text (eg, shebang).
inencodingencodingutf8Ng        rX   r   r   z no lexer matching the text foundr   )
rI   strgetdecoder   r   r   r   rW   r=   )rc   r.   rh   r(   ft
best_lexerr%   rf   r   r   r   r     s.   


r   c                   @   s   e Zd ZdZdd ZdS )_automodulezAutomatically import lexers.c                 C   sT   t |}|rt|d  t|d  }t| || |S |tv r&t| t| S t|rY   )r   rl   r   r   setattrCOMPATr   AttributeError)selfr   r@   r   r   r   r   __getattr__?  s   
z_automodule.__getattr__N)r>   
__module____qualname____doc__ru   r   r   r   r   rp   <  s    rp   )T)r/   )N)(rx   resystypesr   os.pathr   pygments.lexers._mappingr   pygments.modeliner   pygments.pluginr   pygments.utilr   r   rr   listr   r   r   r&   r   r-   r   r   rP   r   rT   rW   rg   r   
ModuleTyperp   modulesr>   oldmodnewmod__dict__updater   r   r   r   <module>   sJ    



#
+
3

