
    Kxh#                        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-2022 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__     L/var/www/html/what/lib/python3.11/site-packages/pip/_vendor/pygments/util.pyr   r      s        MMMMr   r   c                       e Zd ZdS )OptionErrorN)r   r   r   r
   r   r   r   r   "   s        Dr   r   Fc                     |                      ||          }|r|                                }||vr;t          d|dd                    t	          t
          |                              |S )NzValue for option z must be one of z, )getlowerr   joinmapstr)optionsoptnamealloweddefaultnormcasestrings         r   get_choice_optr   &   sy    [['**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          )	N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,   0   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)Nr   r   z ; you must give an integer valuer'   )r   r*   	TypeErrorr   
ValueErrorr+   s       r   get_int_optr0   D   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          )Nr   r   z; you must give a list value)r   r(   r   splitlisttupler   )r   r   r   vals       r   get_list_optr6   R   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_headlinerA   ^   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floatr/   r.   )textrvfs     r   text_analysez%make_analysator.<locals>.text_analysel   s    	4BB 	 	 	33	 	3	sCU2YY//000I& 	 	 	33	s    
*A A%$A%)r	   staticmethod)rJ   rK   s   ` r   make_analysatorrM   j   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   rR   split_path_rer2   r:   
IndexErrorrecompile
IGNORECASEsearch)rH   regexindex
first_linefounds        r   shebang_matchesrc   {   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:   )rH   r_   mdoctypes       r   doctype_matchesrl      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)rl   )rH   s    r   html_doctype_matchesro      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_reri   hash_looks_like_xml_cacheKeyErrorrf   r^   tag_re)rH   keyrj   rI   s       r   looks_like_xmlrw      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.r9      re   z = (,"NrW   )rO   )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)rH   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   )rH   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.close3  s    

r   N)r   r   r   r   r
   r   r   r   r   1  s#            r   r   )NFr   )Fr   )r
   )%r	   r[   ior   r\   rY   DOTALL	MULTILINEVERBOSErf   r]   ru   rh   rq   r/   r   rD   r   r   r,   r0   r6   rA   rM   rc   rl   ro   rs   rw   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   