a
    ñ»j*  ã                   @   sN  d Z ddlZddlmZ ddlZe d¡Ze dejejB ej	B ¡Z
e dejejB ejB ¡Ze dej¡ZG dd	„ d	eƒZG d
d„ deƒZd6dd„Zd7dd„Zd8dd„Zd9dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zi Zdd „ Zd!d"„ Zd:d#d$„Zd;d&d'„Z G d(d)„ d)ƒZ!d*d+„ Z"d,d-„ Z#d.d/„ Z$G d0d1„ d1eƒZ%d<e&d3œd4d5„Z'dS )=z´
    pygments.util
    ~~~~~~~~~~~~~

    Utility functions.

    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)ÚTextIOWrapperz[/\\ ]z”
    <!DOCTYPE\s+(
     [a-zA-Z_][a-zA-Z0-9]*
     (?: \s+      # optional in HTML5
     [a-zA-Z_][a-zA-Z0-9]*\s+
     "[^"]*")?
     )
     [^>]*>
z1<([a-zA-Z][a-zA-Z0-9._:-]*)(\s[^>]*)?>.*?</\1\s*>z\s*<\?xml[^>]*\?>c                   @   s   e Zd ZdZdS )ÚClassNotFoundzCRaised if one of the lookup functions didn't find a matching class.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r	   r	   ú3E:\soccer\ml_env\Lib\site-packages\pygments/util.pyr      s   r   c                   @   s   e Zd ZdZdS )ÚOptionErrorzƒ
    This exception will be raised by all option processing functions if
    the type or value of the argument is not correct.
    Nr   r	   r	   r	   r
   r   #   s   r   Fc              	   C   s@   |   ||¡}|r| ¡ }||vr<td |d tt|ƒ¡¡ƒ‚|S )z}
    If the key `optname` from the dictionary is not in the sequence
    `allowed`, raise an error, otherwise return it.
    z%Value for option {} must be one of {}z, )ÚgetÚlowerr   ÚformatÚjoinÚmapÚstr)ÚoptionsÚoptnameÚallowedÚdefaultÚnormcaseÚstringr	   r	   r
   Úget_choice_opt)   s    r   c                 C   sˆ   |   ||¡}t|tƒr|S t|tƒr,t|ƒS t|tƒsNtd|›d|› d�ƒ‚n6| ¡ dv r^dS | ¡ dv rndS td|›d|› d�ƒ‚d	S )
a@  
    Intuitively, this is `options.get(optname, default)`, but restricted to
    Boolean value. The Booleans can be represented as string, in order to accept
    Boolean value from the command line arguments. If the key `optname` is
    present in the dictionary `options` and is not associated with a Boolean,
    raise an `OptionError`. If it is absent, `default` is returned instead.

    The valid string values for ``True`` are ``1``, ``yes``, ``true`` and
    ``on``, the ones for ``False`` are ``0``, ``no``, ``false`` and ``off``
    (matched case-insensitively).
    úInvalid type ú for option z%; use 1/0, yes/no, true/false, on/off)Ú1ÚyesÚtrueÚonT)Ú0ÚnoÚfalseÚoffFúInvalid value N)r   Ú
isinstanceÚboolÚintr   r   r   ©r   r   r   r   r	   r	   r
   Úget_bool_opt6   s    


r(   c              	   C   sj   |   ||¡}z
t|ƒW S  ty>   td|›d|› d�ƒ‚Y n( tyd   td|›d|› d�ƒ‚Y n0 dS )z?As :func:`get_bool_opt`, but interpret the value as an integer.r   r   z ; you must give an integer valuer#   N)r   r&   Ú	TypeErrorr   Ú
ValueErrorr'   r	   r	   r
   Úget_int_optS   s    
r+   c                 C   sN   |   ||¡}t|tƒr| ¡ S t|ttfƒr4t|ƒS td|›d|› d�ƒ‚dS )zµ
    If the key `optname` from the dictionary `options` is a string,
    split it at whitespace and return it. If it is already a list
    or a tuple, it is returned as a list.
    r   r   z; you must give a list valueN)r   r$   r   ÚsplitÚlistÚtupler   )r   r   r   Úvalr	   r	   r
   Úget_list_opt_   s    
r0   c                 C   sP   | j s
dS g }| j  ¡  ¡ D ]$}| ¡ r<| d| ¡  ¡ q qBqd |¡ ¡ S )NÚ ú )r   ÚstripÚ
splitlinesÚappendr   Úlstrip)ÚobjÚresÚliner	   r	   r
   Údocstring_headlineo   s    r:   c                    s   ‡ fdd„}ˆ j |_ t|ƒS )zAReturn a static text analyser function that returns float values.c              	      s^   zˆ | ƒ}W n t y    Y dS 0 |s*dS ztdtdt|ƒƒƒW S  ttfyX   Y dS 0 d S )Ng        g      ð?)Ú	ExceptionÚminÚmaxÚfloatr*   r)   )ÚtextÚrv©Úfr	   r
   Útext_analyse}   s    z%make_analysator.<locals>.text_analyse)r   Ústaticmethod)rB   rC   r	   rA   r
   Úmake_analysator{   s    rE   c                 C   s    |   d¡}|dkr$| d|…  ¡ }n|  ¡ }| d¡rœz(dd„ t |dd…  ¡ ¡D ƒd }W n tyr   Y d	S 0 t d
|› d�tj	¡}| 
|¡durœdS d	S )aò  Check if the given regular expression matches the last part of the
    shebang if one exists.

        >>> from pygments.util import shebang_matches
        >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?')
        True
        >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
        True
        >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
        False
        >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
        False
        >>> shebang_matches('#!/usr/bin/startsomethingwith python',
        ...                 r'python(2\.\d)?')
        True

    It also checks for common windows executable file extensions::

        >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')
        True

    Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does
    the same as ``'perl -e'``)

    Note that this method automatically searches the whole string (eg:
    the regular expression is wrapped in ``'^$'``)
    Ú
r   Nz#!c                 S   s   g | ]}|r|  d ¡s|‘qS )ú-)Ú
startswith)Ú.0Úxr	   r	   r
   Ú
<listcomp>¯   s   ÿz#shebang_matches.<locals>.<listcomp>é   éÿÿÿÿFú^z(\.(exe|cmd|bat|bin))?$T)Úfindr   rH   Úsplit_path_rer,   r3   Ú
IndexErrorÚreÚcompileÚ
IGNORECASEÚsearch)r?   ÚregexÚindexÚ
first_lineÚfoundr	   r	   r
   Úshebang_matchesŒ   s    

ÿrZ   c                 C   s<   t  | ¡}|du rdS | d¡}t |tj¡ | ¡ ¡duS )zÁCheck if the doctype matches a regular expression (if present).

    Note that this method only checks the first part of a DOCTYPE.
    eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
    NFé   )Údoctype_lookup_rerU   ÚgrouprR   rS   ÚIÚmatchr3   )r?   rV   ÚmÚdoctyper	   r	   r
   Údoctype_matches¹   s
    

rb   c                 C   s
   t | dƒS )z3Check if the file looks like it has a html doctype.Úhtml)rb   )r?   r	   r	   r
   Úhtml_doctype_matchesÆ   s    rd   c                 C   sr   t  | ¡rdS t| ƒ}z
t| W S  tyl   t | ¡}|durFY dS t | dd… ¡du}|t|< | Y S 0 dS )z2Check if a doctype exists or if we have some tags.TNiè  )Úxml_decl_rer_   ÚhashÚ_looks_like_xml_cacheÚKeyErrorr\   rU   Útag_re)r?   Úkeyr`   r@   r	   r	   r
   Úlooks_like_xmlÎ   s    


rk   c                 C   s   d| d?  d| d@  fS )zoGiven a unicode character code with length greater than 16 bits,
    return the two 16 bit surrogate pair.
    iÀ×  é
   i Ü  iÿ  r	   )Úcr	   r	   r
   ÚsurrogatepairÞ   s    rn   c           	      C   s¤   g }d| d }d|d  d }|  ||  d ¡ |rT|D ]}|  || d ¡ q:n8|D ]2}t|d ƒ}|  ||dd…  |d	  d ¡ qX|  |d
 ¡ d |¡S )z)Formats a sequence of strings for output.r2   é   r[   z = (ú,ú"NéþÿÿÿrM   ú)rF   )r5   Úreprr   )	Úvar_nameÚseqÚrawÚindent_levelÚlinesÚbase_indentÚinner_indentÚiÚrr	   r	   r
   Úformat_linesç   s    $r~   r	   c                 C   s>   g }t ƒ }| D ]*}||v s||v r$q| |¡ | |¡ q|S )za
    Returns a list with duplicates removed from the iterable `it`.

    Order is preserved.
    )Úsetr5   Úadd)ÚitÚalready_seenÚlstÚseenr|   r	   r	   r
   Úduplicates_removedú   s    
r…   c                   @   s   e Zd ZdZdd„ ZdS )ÚFuturez‡Generic class to defer some work.

    Handled specially in RegexLexerMeta, to support regex string construction at
    first use.
    c                 C   s   t ‚d S ©N)ÚNotImplementedError©Úselfr	   r	   r
   r     s    z
Future.getN)r   r   r   r   r   r	   r	   r	   r
   r†   
  s   r†   c                 C   s‚   z|   d¡} | dfW S  ty|   z(ddl}| ¡ }|   |¡} | |fW  Y S  ttfyv   |   d¡} | df Y  Y S 0 Y n0 dS )zÃDecode *text* with guessed encoding.

    First try UTF-8; this should fail for non-UTF-8 encodings.
    Then try the preferred locale encoding.
    Fall back to latin-1, which always works.
    zutf-8r   NÚlatin1)ÚdecodeÚUnicodeDecodeErrorÚlocaleÚgetpreferredencodingÚLookupError)r?   rŽ   Úprefencodingr	   r	   r
   Úguess_decode  s    



r’   c                 C   sB   t |ddƒr:z|  |j¡} W n ty.   Y n0 | |jfS t| ƒS )zÊDecode *text* coming from terminal *term*.

    First try the terminal encoding, if given.
    Then try UTF-8.  Then try the preferred locale encoding.
    Fall back to latin-1, which always works.
    ÚencodingN)ÚgetattrrŒ   r“   r�   r’   )r?   Útermr	   r	   r
   Úguess_decode_from_terminal)  s    
r–   c                 C   s"   t | ddƒr| jS ddl}| ¡ S )z7Return our best guess of encoding for the given *term*.r“   Nr   )r”   r“   rŽ   r�   )r•   rŽ   r	   r	   r
   Úterminal_encoding:  s    r—   c                   @   s   e Zd Zdd„ ZdS )ÚUnclosingTextIOWrapperc                 C   s   |   ¡  d S r‡   )Úflushr‰   r	   r	   r
   ÚcloseD  s    zUnclosingTextIOWrapper.closeN)r   r   r   rš   r	   r	   r	   r
   r˜   B  s   r˜   T)Úreturnc                 C   s   | durt jt| ƒ|d�S dS )a¥  Return a safe version of the passed `string`,
    and an empty string if `None`.

    `NoneType` is not supported by `html.escape`, as `html.escape`
    uses the built-in `replace` function on `string`, so we need to
    check for it first.

    Optional flag quote is true by default, which also escapes
    double and single quotes.
    See https://docs.python.org/3/library/html.html#html.escape for more details.
    N)Úquoter1   )rc   Úescaper   )r   rœ   r	   r	   r
   Úhtml_escapeH  s    rž   )NF)N)N)N)Fr   )r	   )T)(r   rR   Úior   rc   rS   rP   ÚDOTALLÚ	MULTILINEÚVERBOSEr\   rT   ri   r^   re   r*   r   r;   r   r   r(   r+   r0   r:   rE   rZ   rb   rd   rg   rk   rn   r~   r…   r†   r’   r–   r—   r˜   r   rž   r	   r	   r	   r
   Ú<module>   sB   

ø	ÿ



-	


