
    q"h/'                     (   S r SSKrSSKJr  \R                  " S5      r\R                  " S\R                  \R                  -  \R                  -  5      r	\R                  " S\R                  \R                  -  \R                  -  5      r\R                  " S\R                  5      r " S S	\5      r " S
 S\5      rS S jrS!S jrS!S jrS!S jrS rS rS rS rS r0 rS rS rS"S jrS#S jr " S S5      r S r!S r"S r# " S S\5      r$g)$z
pygments.util
~~~~~~~~~~~~~

Utility functions.

:copyright: Copyright 2006-2025 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                       \ rS rSrSrSrg)ClassNotFound   zCRaised if one of the lookup functions didn't find a matching class. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       K/var/www/html/env/lib/python3.13/site-packages/pip/_vendor/pygments/util.pyr   r      s    Mr   r   c                       \ rS rSrSrSrg)OptionError"   zw
This exception will be raised by all option processing functions if
the type or value of the argument is not correct.
r   Nr   r   r   r   r   r   "   s    r   r   c                     U R                  X5      nU(       a  UR                  5       nXR;  a8  [        SR                  USR	                  [        [        U5      5      5      5      eU$ )zq
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strings         r   get_choice_optr!   (   sZ    
 [[*FAHHRVR[R[\_`cel\mRnoppMr   c                 \   U R                  X5      n[        U[        5      (       a  U$ [        U[        5      (       a  [        U5      $ [        U[        5      (       d  [        SU< SU S35      eUR                  5       S;   a  gUR                  5       S;   a  g[        SU< SU S35      e)	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_optr2   5   s     [[*F&$	FC	 	 F|$$M&<y I< < = 	=	5	5	6	6N6*L	 J< < = 	=r   c                     U R                  X5      n [        U5      $ ! [         a    [        SU< SU S35      e[         a    [        SU< SU S35      ef = f)z?As :func:`get_bool_opt`, but interpret the value as an integer.r#   r$   z ; you must give an integer valuer-   )r   r0   	TypeErrorr   
ValueErrorr1   s       r   get_int_optr6   R   s~    [[*F86{ 8M&<y I7 7 8 	8 8N6*L	 J7 7 8 	88s	   
 :Ac                     U R                  X5      n[        U[        5      (       a  UR                  5       $ [        U[        [
        45      (       a  [	        U5      $ [        SU< SU S35      e)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_optr<   ^   sj     ++g
'C#syy{	C$	'	'CyM#WI F3 3 4 	4r   c                 8   U R                   (       d  g/ nU R                   R                  5       R                  5        H<  nUR                  5       (       a$  UR                  SUR                  5       -   5        M<    O   SR	                  U5      R                  5       $ )N  )r   strip
splitlinesappendr   lstrip)objreslines      r   docstring_headlinerG   n   so    ;;
C!!#..0::<<JJsTZZ\)*	 1
 773<  r   c                 H   ^  U 4S jnT R                   Ul         [        U5      $ )zAReturn a static text analyser function that returns float values.c           	         >  T" U 5      nU(       d  g [        S[        S[        U5      5      5      $ ! [          a     gf = f! [        [
        4 a     gf = f)Ng        g      ?)	Exceptionminmaxfloatr5   r4   )textrvfs     r   text_analyse%make_analysator.<locals>.text_analyse|   sb    	4B 	sCU2Y/00  		 I& 		s   3 A 
A A AA)r   staticmethod)rP   rQ   s   ` r   make_analysatorrT   z   s!    
 99L%%r   c                     U R                  S5      nUS:  a  U SU R                  5       nOU R                  5       nUR                  S5      (       a   [        R	                  USS R                  5       5       Vs/ s H&  nU(       d  M  UR                  S5      (       a  M$  UPM(     snS   n[        R                  " S	U S
3[        R                  5      nUR                  U5      b  ggs  snf ! [         a     gf = f)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#!   -F^z(\.(exe|cmd|bat|bin))?$T)findr   
startswithsplit_path_rer8   r@   
IndexErrorrecompile
IGNORECASEsearch)rN   regexindex
first_linexfounds         r   shebang_matchesrh      s    8 IIdOEz&5\'')
ZZ\
T""	 - 3 3JqrN4H4H4J K 5 K1 "#,,s"3  K 5579E 

aw&=>N<<*5 		s0   (C0 ;C+
C+"C+(C0 +C0 0
C=<C=c                     [         R                  U 5      nUc  gUR                  S5      n[        R                  " U[        R
                  5      R                  UR                  5       5      SL$ )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_rerb   groupr_   r`   Imatchr@   )rN   rc   mdoctypes       r   doctype_matchesrq      sT     	  &AyggajG::eRTT"((9EEr   c                     [        U S5      $ )z3Check if the file looks like it has a html doctype.html)rq   )rN   s    r   html_doctype_matchesrt      s    4))r   c                     [         R                  U 5      (       a  g[        U 5      n [        U   $ ! [         aB    [
        R                  U 5      nUb   g[        R                  U SS 5      SLnU[        U'   Us $ f = f)z2Check if a doctype exists or if we have some tags.TNi  )xml_decl_rern   hash_looks_like_xml_cacheKeyErrorrk   rb   tag_re)rN   keyro   rO   s       r   looks_like_xmlr|      s    
t*C$S)) $$T*=]]4;'t3%'c"	s   1 "A=%A=<A=c                 "    SU S-	  -   SU S-  -   4$ )zgGiven 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                 \   / nSU-  S-  nSUS-   -  S-  nUR                  XP-   S-   5        U(       a   U H  nUR                  Xg-   S-   5        M     O6U H0  n[        US-   5      nUR                  XhSS -   US	   -   S-   5        M2     UR                  US
-   5        SR                  U5      $ )z)Formats a sequence of strings for output.r?      rj   z = (,"NrY   )rV   )rB   reprr   )	var_nameseqrawindent_levellinesbase_indentinner_indentirs	            r   format_linesr      s    E$q(K,*+a/L	LL'&01
ALL)C/0  AQWALL#2.26<=  
LLs"#99Ur   c                     / n[        5       nU  H1  nXC;   d  XA;   a  M  UR                  U5        UR                  U5        M3     U$ )zU
Returns a list with duplicates removed from the iterable `it`.

Order is preserved.
)setrB   add)italready_seenlstseenr   s        r   duplicates_removedr      sD     C5D9)

1	 
 Jr   c                       \ rS rSrSrS rSrg)Futurei	  z{Generic class to defer some work.

Handled specially in RegexLexerMeta, to support regex string construction at
first use.
c                     [         eN)NotImplementedErrorselfs    r   r   
Future.get  s    !!r   r   N)r	   r
   r   r   r   r   r   r   r   r   r   r   	  s    
"r   r   c                      U R                  S5      n U S4$ ! [         aX     SSKnUR                  5       nU R                  5       n X4s $ ! [        [        4 a    U R                  S5      n U S4s s $ f = ff = f)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)rN   r   prefencodings      r   guess_decoder     s    "{{7#W} "	"!668L;;=D%%"K0 	";;x(D>!	""s,    
A9&AA9%A50A94A55A9c                     [        USS5      (       a)   U R                  UR                  5      n XR                  4$ [	        U 5      $ ! [         a     Nf = f)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   )rN   terms     r   guess_decode_from_terminalr   (  sX     tZ&&	';;t}}-D &&	 " 		s   A 
AAc                 f    [        U SS5      (       a  U R                  $ SSKnUR                  5       $ )z7Return our best guess of encoding for the given *term*.r   Nr   )r   r   r   r   )r   r   s     r   terminal_encodingr   9  s-    tZ&&}}&&((r   c                       \ rS rSrS rSrg)UnclosingTextIOWrapperiA  c                 $    U R                  5         g r   )flushr   s    r   closeUnclosingTextIOWrapper.closeC  s    

r   r   N)r	   r
   r   r   r   r   r   r   r   r   r   A  s    r   r   )NFr   )Fr   )r   )%r   r_   ior   r`   r]   DOTALL	MULTILINEVERBOSErk   ra   rz   rm   rv   r5   r   rJ   r   r!   r2   r6   r<   rG   rT   rh   rq   rt   rx   r|   r   r   r   r   r   r   r   r   r   r   r   <module>r      s   
  

9%JJ   YY

*,  
/MMBII-<
>jj-rtt4NJ N) 
=:
84 	!&"*Z
F*
   8& " ""*")] r   