
    if'                        d Z ddlZddlmZ  ej        d          Z ej        dej        ej        z  ej        z            Z	 ej        dej
        ej        z  ej        z            Z ej        dej                  Z G d d	e          Z G d
 de          Zd"dZd#dZd#dZd#dZd Zd Zd Zd Zd Zi Zd Zd Zd$dZd%dZ G d d          Z d Z!d Z"d Z# G d  d!e          Z$dS )&z
    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__     K/var/www/html/env/lib/python3.11/site-packages/pip/_vendor/pygments/util.pyr   r      s        MMMMr   r   c                       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   r   Fc                     |                      ||          }|r|                                }||vr;t          d|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 z must be one of z, )getlowerr   joinmapstr)optionsoptnamealloweddefaultnormcasestrings         r   get_choice_optr   (   s{    
 [['**F  Wk"77DIIc#w.?.?$@$@$@B C C 	CMr   c                    |                      ||          }t          |t                    r|S t          |t                    rt          |          S t          |t                    st          d|d|d          |                                dv rdS |                                dv rdS t          d|d|d          )	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 )r   
isinstanceboolintr   r   r   r   r   r   r   s       r   get_bool_optr-   6   s     [['**F&$ 0	FC	 	  0F||$$ 0k$ffggg/ 0 0 	0 
5	5	5t	6	6	6uk$ffggg/ 0 0 	0r   c                     |                      ||          }	 t          |          S # t          $ r t          d|d|d          t          $ r t          d|d|d          w xY w)z?As :func:`get_bool_opt`, but interpret the value as an integer.r   r   z ; you must give an integer valuer(   )r   r+   	TypeErrorr   
ValueErrorr,   s       r   get_int_optr1   U   s    [['**F	06{{ 0 0 0k$ffggg/ 0 0 	0  0 0 0k$ffggg/ 0 0 	00s
   ' A A'c                    |                      ||          }t          |t                    r|                                S t          |t          t
          f          rt	          |          S t          d|d|d          )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 value)r   r)   r   splitlisttupler   )r   r   r   vals       r   get_list_optr7   c   s     ++gw
'
'C#s -yy{{	C$	'	' -Cyyk!cc777, - - 	-r   c                 @   | j         sdS g }| j                                                                         D ]A}|                                r+|                    d|                                z              A d                    |                                          S )N  )r
   strip
splitlinesappendr   lstrip)objreslines      r   docstring_headlinerB   t   s    ; r
C!!##..00  ::<< 	JJsTZZ\\)****773<<   r   c                 D      fd} j         |_         t          |          S )zAReturn a static text analyser function that returns float values.c           	          	  |           }n# t           $ r Y dS w xY w|sdS 	 t          dt          dt          |                              S # t          t
          f$ r Y dS w xY w)Ng        g      ?)	Exceptionminmaxfloatr0   r/   )textrvfs     r   text_analysez%make_analysator.<locals>.text_analyse   s    	4BB 	 	 	33	 	3	sCU2YY//000I& 	 	 	33	s    
*A A%$A%)r
   staticmethod)rK   rL   s   ` r   make_analysatorrN      s6    
 
 
 
 
 9L%%%r   c                    |                      d          }|dk    r| d|                                         }n|                                 }|                    d          r	 d t                              |dd                                                   D             d         }n# t          $ r Y dS w xY wt          j        d	|z  t          j	                  }|
                    |          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                 @    g | ]}||                     d           |S )-)
startswith).0xs     r   
<listcomp>z#shebang_matches.<locals>.<listcomp>   s@     5 5 515"#,,s"3"35Q 5 5 5r      Fz^%s(\.(exe|cmd|bat|bin))?$T)findr   rS   split_path_rer3   r;   
IndexErrorrecompile
IGNORECASEsearch)rI   regexindex
first_linefounds        r   shebang_matchesrd      s    8 IIdOOEzz&5&\''))

ZZ\\
T"" 	5 5 3 3JqrrN4H4H4J4J K K 5 5 5579EE 	 	 	55	
85@"-PP<<*45s   #AB( (
B65B6c                     t                               |           }|dS |                    d          }t          j        |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_rer_   groupr\   r]   Imatchr;   )rI   r`   mdoctypes       r   doctype_matchesrm      s_     	  &&AyuggajjG:eRT""((99EEr   c                 "    t          | d          S )z3Check if the file looks like it has a html doctype.html)rm   )rI   s    r   html_doctype_matchesrp      s    4)))r   c                 2   t                               |           rdS t          |           }	 t          |         S # t          $ rR t
                              |           }|Y dS t                              | dd                   du}|t          |<   |cY S w xY w)z2Check if a doctype exists or if we have some tags.TNi  )xml_decl_rerj   hash_looks_like_xml_cacheKeyErrorrg   r_   tag_re)rI   keyrk   rJ   s       r   looks_like_xmlrx      s     t
t**C$S))   $$T**=44]]4;''t3%'c"			s   : &B#0BBc                 "    d| dz	  z   d| dz  z   fS )zoGiven a unicode character code with length greater than 16 bits,
    return the two 16 bit surrogate pair.
    i  
   i   i  r   )cs    r   surrogatepairr|      s!     a2g1u9!577r   c                    g }d|z  dz  }d|dz   z  dz  }|                     || z   dz              |r!|D ]}|                     ||z   dz              nC|D ]@}t          |dz             }|                     ||dd         z   |d	         z   dz              A|                     |d
z              d                    |          S )z)Formats a sequence of strings for output.r:      rf   z = (,"NrX   )rP   )r=   reprr   )	var_nameseqrawindent_levellinesbase_indentinner_indentirs	            r   format_linesr      s    E$q(K,*+a/L	LLx'&0111
 > 	1 	1ALL)C/0000	1  	> 	>AQWALL#2#.26<====	LLs"###99Ur   r   c                     g }t                      }| D ]5}||v s||v r|                    |           |                    |           6|S )za
    Returns a list with duplicates removed from the iterable `it`.

    Order is preserved.
    )setr=   add)italready_seenlstseenr   s        r   duplicates_removedr      s\     C55D  99\))

1Jr   c                       e Zd ZdZd ZdS )FuturezGeneric class to defer some work.

    Handled specially in RegexLexerMeta, to support regex string construction at
    first use.
    c                     t           N)NotImplementedErrorselfs    r   r   z
Future.get  s    !!r   N)r   r   r	   r
   r   r   r   r   r   r     s-         
" " " " "r   r   c                    	 |                      d          } | dfS # t          $ rf 	 ddl}|                                }|                                  } | |fcY S # t          t          f$ r |                      d          } | dfcY cY S w xY ww xY 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)rI   r   prefencodings      r   guess_decoder     s    "{{7##W} " " "	"MMM!6688L;;==D%%%%"K0 	" 	" 	";;x((D>!!!!!	""s,    
B/AB*BBBBc                     t          |dd          r4	 |                     |j                  } | |j        fS # t          $ r Y nw xY w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   )rI   terms     r   guess_decode_from_terminalr   .  sq     tZ&& '	';;t}--D && " 	 	 	D	 s   6 
AAc                 b    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   s     r   terminal_encodingr   ?  s9    tZ&& }MMM&&(((r   c                       e Zd Zd ZdS )UnclosingTextIOWrapperc                 .    |                                   d S r   )flushr   s    r   closezUnclosingTextIOWrapper.closeI  s    

r   N)r   r   r	   r   r   r   r   r   r   G  s#            r   r   )NFr   )Fr   )r   )%r
   r\   ior   r]   rZ   DOTALL	MULTILINEVERBOSErg   r^   rv   ri   rr   r0   r   rE   r   r   r-   r1   r7   rB   rN   rd   rm   rp   rt   rx   r|   r   r   r   r   r   r   r   r   r   r   <module>r      s    
			       
9%%BJ   Y
*, ,  
/MBI-<
> 
>bj-rt44N N N N NJ N N N    )      0 0 0 0>0 0 0 0- - - -"	! 	! 	!& & &"* * *Z
F 
F 
F* * *
     8 8 8   &    " " " " " " " "" " "*  ") ) )    ]     r   