o a#@s<dZddlZddlmZedZedejejBejBZ edej ej BejBejBZ edej ZGdd d eZGd d d eZd2d dZd3ddZd3ddZd3ddZddZddZddZddZddZiZdd Zd!d"Zd4d#d$Zd5d&d'Z Gd(d)d)Z!d*d+Z"d,d-Z#d.d/Z$Gd0d1d1eZ%dS)6z pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N) TextIOWrapperz[/\\ ]z ]*> 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//usr/lib/python3/dist-packages/pygments/util.pyrsrc@s eZdZdS) OptionErrorN)rrrrrrr r "sr FcCs@|||}|r |}||vrtd|dtt|f|S)Nz%Value for option %s must be one of %sz, )getlowerr joinmapstr)optionsoptnamealloweddefaultnormcasestringrrr get_choice_opt&s rcCsv|||}t|tr |St|trt|St|ts#td||f|dvr+dS|dvr3dStd||f)NzBInvalid type %r for option %s; use 1/0, yes/no, true/false, on/off)1yestrueonT)0nofalseoffFzCInvalid value %r for option %s; use 1/0, yes/no, true/false, on/off)r isinstanceboolintrr r rrrrrrr get_bool_opt0s$      r#cCsR|||}zt|WStytd||fty(td||fw)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)r r! TypeErrorr ValueErrorr"rrr get_int_optDs    r&cCsD|||}t|tr|St|ttfrt|Std||f)Nz9Invalid type %r for option %s; you must give a list value)r rrsplitlisttupler )rrrvalrrr get_list_optRs  r+cCsL|jsdSg}|jD]}|r|d|qd|S)N )rstrip splitlinesappendr lstrip)objreslinerrr docstring_headline^sr5csfdd}j|_t|S)zAReturn a static text analyser function that returns float values.c sZz|}Wn tyYdSw|sdSz tdtdt|WSttfy,YdSw)Ngg?) Exceptionminmaxfloatr%r$)textrvfrr text_analysels  z%make_analysator..text_analyse)r staticmethod)r=r>rr<r make_analysatorjs  r@cCs|d}|dkr|d|}n|}|drLzddt|ddDd}Wn ty9Yd Swtd |tj }| |durLd Sd S) aCheck 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#!cSsg|] }|r|ds|qS)-) startswith).0xrrr s  z#shebang_matches..Fz^%s(\.(exe|cmd|bat|bin))?$T) findr rC split_path_rer'r. IndexErrorrecompile IGNORECASEsearch)r:regexindex first_linefoundrrr shebang_matches{s   rTcCs<t|}|dur dS|d}t|tj|duS)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_rerOgrouprLrMImatchr.)r:rPmdoctyperrr doctype_matchess  r\cCs t|dS)z3Check if the file looks like it has a html doctype.html)r\)r:rrr html_doctype_matchess r^cCsnt|rdSt|}zt|WSty6t|}|dur#YdSt|dddu}|t|<|YSw)z2Check if a doctype exists or if we have some tags.TNi) xml_decl_rerYhash_looks_like_xml_cacheKeyErrorrVrOtag_re)r:keyrZr;rrr looks_like_xmls    recCsd|d?d|d@fS)zoGiven a unicode character code with length greater than 16 bits, return the two 16 bit surrogate pair. i iir)crrr surrogatepairsrhc Csg}d|d}d|dd}|||d|r*|D] }|||dqn|D]}t|d}|||dd|d dq,||d d |S) z)Formats a sequence of strings for output.r-rUz = (,"NrH)rA)r0reprr ) var_nameseqraw indent_levellines base_indent inner_indentirrrr format_liness  $ rxrcCs>g}t}|D]}||vs||vrq||||q|S)za Returns a list with duplicates removed from the iterable `it`. Order is preserved. )setr0add)it already_seenlstseenrvrrr duplicates_removeds  rc@seZdZdZddZdS)FuturezGeneric class to defer some work. Handled specially in RegexLexerMeta, to support regex string construction at first use. cCstN)NotImplementedErrorselfrrr r sz Future.getN)rrrrr rrrr rs rc Csxz |d}|dfWSty;zddl}|}|}||fWYSttfy:|d}|dfYYSww)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. zutf-8rNlatin1)decodeUnicodeDecodeErrorlocalegetpreferredencoding LookupError)r:r prefencodingrrr guess_decodes    rcCsHt|ddr z||j}Wn tyYt|Sw||jfSt|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)getattrrrrr)r:termrrr guess_decode_from_terminals   rcCs"t|ddr |jSddl}|S)z7Return our best guess of encoding for the given *term*.rNr)rrrr)rrrrr terminal_encoding)s rc@seZdZddZdS)UnclosingTextIOWrappercCs |dSr)flushrrrr close3s zUnclosingTextIOWrapper.closeN)rrrrrrrr r1s r)NFr)Fr)r)&rrLiorrMrJDOTALL MULTILINEVERBOSErVUNICODErNrcrXr_r%rr6r rr#r&r+r5r@rTr\r^rarerhrxrrrrrrrrrr s@        -