a
    hbòf£#  ã                   @   s<  d Z ddlZddlm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 ejB ¡Ze dej¡ZG dd	„ d	eƒZG d
d„ deƒZd2dd„Zd3dd„Zd4dd„Zd5d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d6d#d$„Zd7d&d'„Z G d(d)„ d)ƒZ!d*d+„ Z"d,d-„ Z#d.d/„ Z$G d0d1„ d1eƒZ%dS )8z±
    pygments.util
    ~~~~~~~~~~~~~

    Utility functions.

    :copyright: Copyright 2006-2021 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+
     "[^"]*")?
     )
     [^>]*>
z<(.+?)(\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   úV/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/pygments/util.pyr      s   r   c                   @   s   e Zd ZdS )ÚOptionErrorN)r   r   r   r   r   r   r	   r
   "   s   r
   Fc                 C   s@   |   ||¡}|r| ¡ }||vr<td|d tt|ƒ¡f ƒ‚|S )Nz%Value for option %s must be one of %sz, )ÚgetÚlowerr
   Ú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ƒsHtd||f ƒ‚n0| ¡ dv rXdS | ¡ dv rhdS td||f ƒ‚d S )NzBInvalid type %r for option %s; use 1/0, yes/no, true/false, on/off)Ú1ÚyesÚtrueÚonT)Ú0ÚnoÚfalseÚoffFzCInvalid value %r for option %s; use 1/0, yes/no, true/false, on/off)r   Ú
isinstanceÚboolÚintr   r
   r   ©r   r   r   r   r   r   r	   Úget_bool_opt0   s$    


ÿÿÿÿr#   c                 C   s^   |   ||¡}z
t|ƒW S  ty8   td||f ƒ‚Y n" tyX   td||f ƒ‚Y n0 d S )Nz=Invalid type %r for option %s; you must give an integer valuez>Invalid value %r for option %s; you must give an integer value)r   r!   Ú	TypeErrorr
   Ú
ValueErrorr"   r   r   r	   Úget_int_optD   s    
ÿÿ
ÿÿr&   c                 C   sH   |   ||¡}t|tƒr| ¡ S t|ttfƒr4t|ƒS td||f ƒ‚d S )Nz9Invalid type %r for option %s; you must give a list value)r   r   r   ÚsplitÚlistÚtupler
   )r   r   r   Úvalr   r   r	   Úget_list_optR   s    
ÿÿr+   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_headline^   s    r5   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_analysel   s    z%make_analysator.<locals>.text_analyse)r   Ústaticmethod)r=   r>   r   r<   r	   Úmake_analysatorj   s    r@   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
| 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>é   éÿÿÿÿFz^%s(\.(exe|cmd|bat|bin))?$T)Úfindr   rC   Úsplit_path_rer'   r.   Ú
IndexErrorÚreÚcompileÚ
IGNORECASEÚsearch)r:   ÚregexÚindexÚ
first_lineÚfoundr   r   r	   Úshebang_matches{   s    

ÿrT   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_rerO   ÚgrouprL   rM   ÚIÚmatchr.   )r:   rP   ÚmÚdoctyper   r   r	   Údoctype_matches¨   s
    

r\   c                 C   s
   t | dƒS )z3Check if the file looks like it has a html doctype.Úhtml)r\   )r:   r   r   r	   Úhtml_doctype_matchesµ   s    r^   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_rerY   ÚhashÚ_looks_like_xml_cacheÚKeyErrorrV   rO   Útag_re)r:   ÚkeyrZ   r;   r   r   r	   Úlooks_like_xml½   s    


re   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    rh   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.r-   é   rU   z = (ú,ú"NéþÿÿÿrH   ú)rA   )r0   Úreprr   )	Úvar_nameÚseqÚrawÚindent_levelÚlinesÚbase_indentÚinner_indentÚiÚrr   r   r	   Úformat_linesÖ   s    $rx   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.
    )Úsetr0   Úadd)ÚitÚalready_seenÚlstÚseenrv   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yz   z&ddl}| ¡ }|   ¡ } | |fW  Y S  ttfyt   |   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	   Úclose3  s    zUnclosingTextIOWrapper.closeN)r   r   r   r”   r   r   r   r	   r’   1  s   r’   )NF)N)N)N)Fr   )r   )&r   rL   Úior   rM   rJ   ÚDOTALLÚ	MULTILINEÚVERBOSErV   ÚUNICODErN   rc   rX   r_   r%   r   r6   r
   r   r#   r&   r+   r5   r@   rT   r\   r^   ra   re   rh   rx   r   r€   rŒ   r�   r‘   r’   r   r   r   r	   Ú<module>   s>   

ø	ÿ




-	


