o
    EJe'                     @   s6  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 ZedejZG dd	 d	eZG d
d deZd2ddZd3ddZd3ddZd3d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d4d#d$Zd5d&d'ZG d(d) d)Z d*d+ Z!d,d- Z"d.d/ Z#G d0d1 d1eZ$dS )6z
    pygments.util
    ~~~~~~~~~~~~~

    Utility functions.

    :copyright: Copyright 2006-2023 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                   @      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
   g/home/seandotau/au.memorygallery.club/gallery/lib/python3.10/site-packages/pip/_vendor/pygments/util.pyr          r   c                   @   r   )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   "   r   r   Fc                 C   s@   |  ||}|r| }||vrtd|dtt|f |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 %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   sv   |  ||}t|tr|S t|trt|S t|ts#td||f | dv r+dS | dv r3dS td||f )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).
    zBInvalid 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_opt6   s$   


r&   c                 C   sR   |  ||}zt|W S  ty   td||f  ty(   td||f w )z?As :func:`get_bool_opt`, but interpret the value as an integer.z=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_optU   s   
r)   c                 C   sD   |  ||}t|tr| S t|ttfrt|S td||f )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.
    z9Invalid 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_optc   s   
r.   c                 C   sL   | j sdS g }| j   D ]}| r|d|   q d| S )N  )r	   strip
splitlinesappendr   lstrip)objresliner
   r
   r   docstring_headlinet   s   r8   c                    s    fdd} j |_ t|S )zAReturn a static text analyser function that returns float values.c              	      sZ   z | }W n
 t y   Y dS w |sdS ztdtdt|W S  ttfy,   Y dS w )Ng        g      ?)	Exceptionminmaxfloatr(   r'   )textrvfr
   r   text_analyse   s   z%make_analysator.<locals>.text_analyse)r	   staticmethod)r@   rA   r
   r?   r   make_analysator   s   rC   c                 C   s   |  d}|dkr| d|  }n|  }|drLzdd t|dd  D d }W n
 ty9   Y d	S w td
| tj	}|
|durLd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   rF   split_path_rer*   r1   
IndexErrorrecompile
IGNORECASEsearch)r=   regexindex
first_linefoundr
   r
   r   shebang_matches   s    

rW   c                 C   s<   t | }|du rdS |d}t|tj| duS )zCheck 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_rerR   grouprO   rP   Imatchr1   )r=   rS   mZ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   sn   t | rdS t| }zt| W S  ty6   t| }|dur#Y dS t| dd du}|t|< | Y S w )z2Check if a doctype exists or if we have some tags.TNi  )xml_decl_rer\   hash_looks_like_xml_cacheKeyErrorrY   rR   tag_re)r=   keyr]   r>   r
   r
   r   looks_like_xml   s   


rg   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   rj   c           	      C   s   g }d| d }d|d  d }| ||  d  |r*|D ]}| || d  qn|D ]}t|d }| ||dd  |d	  d  q,| |d
  d|S )z)Formats a sequence of strings for output.r0      rX   z = (,"NrK   )rD   )r3   reprr   )	Zvar_nameseqrawindent_levellinesZbase_indentZinner_indentirr
   r
   r   format_lines   s   $
rw   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.
    )setr3   add)itZalready_seenZlstseenru   r
   r
   r   duplicates_removed   s   
r|   c                   @   s   e Zd ZdZdd ZdS )FuturezGeneric class to defer some work.

    Handled specially in RegexLexerMeta, to support regex string construction at
    first use.
    c                 C   s   t N)NotImplementedErrorselfr
   r
   r   r     s   z
Future.getN)r   r   r   r	   r   r
   r
   r
   r   r}     s    r}   c                 C   sx   z
|  d} | dfW S  ty;   zddl}| }|   } | |fW  Y S  ttfy:   |  d} | df Y  Y S w w )zDecode *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   Zprefencodingr
   r
   r   guess_decode  s   


r   c                 C   sH   t |ddr z| |j} W n ty   Y t| S w | |jfS t| S )zDecode *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   closeI  s   zUnclosingTextIOWrapper.closeN)r   r   r   r   r
   r
   r
   r   r   G  s    r   )NFr~   )Fr   )r
   )%r	   rO   ior   rP   rM   DOTALL	MULTILINEVERBOSErY   rQ   re   r[   ra   r(   r   r9   r   r   r&   r)   r.   r8   rC   rW   r^   r`   rc   rg   rj   rw   r|   r}   r   r   r   r   r
   r
   r
   r   <module>   s@    

	



-
	

