3

V'íc–#ã@s8dZddlZddlmZejdƒZejdejejBejBƒZ	ejdej
ejBejBƒZejdejƒZ
Gdd	„d	eƒZGd
d„deƒZd1d
d„Zd2dd„Zd3dd„Zd4dd„Zdd„Zdd„Zdd„Zdd„Zdd„ZiZdd „Zd!d"„Zd5d#d$„Zffd%d&„ZGd'd(„d(ƒZ d)d*„Z!d+d,„Z"d-d.„Z#Gd/d0„d0eƒZ$dS)6z±
    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@seZdZdZdS)Ú
ClassNotFoundzCRaised if one of the lookup functions didn't find a matching class.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__©rrú1/tmp/pip-build-gk9425m9/Pygments/pygments/util.pyrsrc@seZdZdS)ÚOptionErrorN)rrrrrrr	r
"sr
FcCs@|j||ƒ}|r|jƒ}||kr<td|djtt|ƒƒfƒ‚|S)Nz%Value for option %s must be one of %sz, )ÚgetÚlowerr
ÚjoinÚmapÚstr)ÚoptionsÚoptnameÚallowedÚdefaultÚnormcaseÚstringrrr	Úget_choice_opt&srcCs||j||ƒ}t|tƒr|St|tƒr,t|ƒSt|tƒsHtd||fƒ‚n0|jƒd
krXdS|jƒdkrhdStd||fƒ‚dS)NzBInvalid 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)rrrr)rrrr)rÚ
isinstanceÚboolÚintrr
r)rrrrrrr	Úget_bool_opt0s


r"cCs`|j||ƒ}yt|ƒStk
r8td||fƒ‚Yn$tk
rZtd||fƒ‚YnXdS)Nz=Invalid type %r for option %s; you must give an integer valuez>Invalid value %r for option %s; you must give an integer value)rr!Ú	TypeErrorr
Ú
ValueError)rrrrrrr	Úget_int_optDsr%cCsH|j||ƒ}t|tƒr|jƒSt|ttfƒr4t|ƒStd||fƒ‚dS)Nz9Invalid type %r for option %s; you must give a list value)rrrÚsplitÚlistÚtupler
)rrrÚvalrrr	Úget_list_optRs
r*cCsR|js
dSg}x4|jjƒjƒD]"}|jƒr>|jd|jƒƒqPqWdj|ƒjƒS)NÚú )rÚstripÚ
splitlinesÚappendr
Úlstrip)ÚobjÚresÚlinerrr	Údocstring_headline^sr4cs‡fdd„}ˆj|_t|ƒS)zAReturn a static text analyser function that returns float values.cs\yˆ|ƒ}Wntk
r dSX|s*dSytdtdt|ƒƒƒSttfk
rVdSXdS)Nggð?)Ú	ExceptionÚminÚmaxÚfloatr$r#)ÚtextÚrv)Úfrr	Útext_analyselsz%make_analysator.<locals>.text_analyse)rÚstaticmethod)r;r<r)r;r	Úmake_analysatorjsr>cCsœ|jdƒ}|dkr$|d|…jƒ}n|jƒ}|jdƒr˜y(dd„tj|dd…jƒƒDƒd}Wntk
rrd	SXtjd
|tj	ƒ}|j
|ƒdk	r˜dSd	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 ``'^$'``)
    Ú
rNz#!cSs g|]}|r|jdƒr|‘qS)ú-)Ú
startswith)Ú.0Úxrrr	ú
<listcomp>žsz#shebang_matches.<locals>.<listcomp>ééFz^%s(\.(exe|cmd|bat|bin))?$Téÿÿÿÿ)ÚfindrrAÚ
split_path_rer&r-Ú
IndexErrorÚreÚcompileÚ
IGNORECASEÚsearch)r9ÚregexÚindexÚ
first_lineÚfoundrrr	Úshebang_matches{s


rScCs<tj|ƒ}|dkrdS|jdƒ}tj|tjƒj|jƒƒdk	S)zÁCheck 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"'
    NFrF)Údoctype_lookup_rerNÚgrouprKrLÚIÚmatchr-)r9rOÚmÚdoctyperrr	Údoctype_matches¨s


rZcCs
t|dƒS)z3Check if the file looks like it has a html doctype.Úhtml)rZ)r9rrr	Úhtml_doctype_matchesµsr\cCsltj|ƒrdSt|ƒ}yt|Stk
rftj|ƒ}|dk	rDdStj|dd…ƒdk	}|t|<|SXdS)z2Check if a doctype exists or if we have some tags.TNiè)Úxml_decl_rerWÚhashÚ_looks_like_xml_cacheÚKeyErrorrTrNÚtag_re)r9ÚkeyrXr:rrr	Úlooks_like_xml½s

rccCsd|d?d|d@fS)zoGiven a unicode character code with length greater than 16 bits,
    return the two 16 bit surrogate pair.
    iÀ×é
iÜiÿr)Úcrrr	Ú
surrogatepairÍsrfc	Cs¬g}d|d}d|dd}|j||dƒ|rXx\|D]}|j||dƒq<Wn<x:|D]2}t|dƒ}|j||dd…|ddƒq^W|j|d	ƒd
j|ƒS)
z)Formats a sequence of strings for output.r,érFz = (ú,ú"NrEú)r?éþÿÿÿrG)r/Úreprr
)	Úvar_nameÚseqÚrawÚindent_levelÚlinesZbase_indentZinner_indentÚiÚrrrr	Úformat_linesÖs

&rtcCsBg}tƒ}x2|D]*}||ks||kr&q|j|ƒ|j|ƒqW|S)za
    Returns a list with duplicates removed from the iterable `it`.

    Order is preserved.
    )Úsetr/Úadd)ÚitZalready_seenÚlstÚseenrrrrr	Úduplicates_removedés

rzc@seZdZdZdd„ZdS)ÚFuturez‡Generic class to defer some work.

    Handled specially in RegexLexerMeta, to support regex string construction at
    first use.
    cCst‚dS)N)ÚNotImplementedError)Úselfrrr	rÿsz
Future.getN)rrrrrrrrr	r{ùsr{cCsty|jdƒ}|dfStk
rny ddl}|jƒ}|jƒ}||fSttfk
rh|jdƒ}|dfSXYnXdS)zÃDecode *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.
    zutf-8rNÚlatin1)ÚdecodeÚUnicodeDecodeErrorÚlocaleÚgetpreferredencodingÚLookupError)r9rZprefencodingrrr	Úguess_decodes

r„cCsDt|ddƒr<y|j|jƒ}Wntk
r0YnX||jfSt|ƒS)zÊDecode *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)Úgetattrrr…r€r„)r9Útermrrr	Úguess_decode_from_terminals
rˆcCs"t|ddƒr|jSddl}|jƒS)z7Return our best guess of encoding for the given *term*.r…Nr)r†r…rr‚)r‡rrrr	Úterminal_encoding)sr‰c@seZdZdd„ZdS)ÚUnclosingTextIOWrappercCs|jƒdS)N)Úflush)r}rrr	Úclose3szUnclosingTextIOWrapper.closeN)rrrrŒrrrr	rŠ1srŠ)NF)N)N)N)Fr)%rrKÚiorrLrIÚDOTALLÚ	MULTILINEÚVERBOSErTrMrarVr]r$rr5r
rr"r%r*r4r>rSrZr\r_rcrfrtrzr{r„rˆr‰rŠrrrr	Ú<module>	s:





-