
    '                     (   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-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                       \ 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        lib/third_party/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;  a0  [        SU< SSR                  [	        [
        U5      5      < 3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 z must be one of z, )getlowerr   joinmapstr)optionsoptnamealloweddefaultnormcasestrings         r   get_choice_optr    (   sU    
 [[*F"DIIc#w.?$@B C 	C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_optr1   6   s     [[*F&$	FC	 	 F|$$$g/ 0 	0 
5	5	6	6$g/ 0 	0r   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   r/   	TypeErrorr   
ValueErrorr0   s       r   get_int_optr5   U   sf    [[*F	06{ 0$g/ 0 	0  0$g/ 0 	00s	   
 <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;   c   s]     ++g
'C#syy{	C$	'	'Cy!7, - 	-r   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_headlinerF   t   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floatr4   r3   )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)rO   rP   s   ` r   make_analysatorrS      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-  [        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#!   -Fz^%s(\.(exe|cmd|bat|bin))?$T)findr   
startswithsplit_path_rer7   r?   
IndexErrorrecompile
IGNORECASEsearch)rM   regexindex
first_linexfounds         r   shebang_matchesrf      s    8 IIdOEz&5\'')
ZZ\
T""	 - 3 3JqrN4H4H4J K 5 K1 "#,,s"3  K 5579E 

85@"--P<<*5 		s0   (C/ ;C*
C*"C*(C/ *C/ /
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_rer`   groupr]   r^   Imatchr?   )rM   ra   mdoctypes       r   doctype_matchesro      sT     	  &AyggajG::eRTT"((9EEr   c                     [        U S5      $ )z3Check if the file looks like it has a html doctype.html)ro   )rM   s    r   html_doctype_matchesrr      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_rerl   hash_looks_like_xml_cacheKeyErrorri   r`   tag_re)rM   keyrm   rN   s       r   looks_like_xmlrz      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>      rh   z = (,"NrX   )rU   )rA   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.
)setrA   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)rM   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   )rM   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   ?  s-    tZ&&}}&&((r   c                       \ rS rSrS rSrg)UnclosingTextIOWrapperiG  c                 $    U R                  5         g r   )flushr   s    r   closeUnclosingTextIOWrapper.closeI  s    

r   r   N)r	   r
   r   r   r   r   r   r   r   r   r   G  s    r   r   )NFr   )Fr   )r   )%r   r]   ior   r^   r[   DOTALL	MULTILINEVERBOSEri   r_   rx   rk   rt   r4   r   rI   r   r    r1   r5   r;   rF   rS   rf   ro   rr   rv   rz   r~   r   r   r   r   r   r   r   r   r   r   <module>r      s   
  

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

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