a *eg/'@s6dZddlZddlmZedZedejejBejBZ edej ejBejBZ edej Z Gdd d eZGd d d eZd2d dZd3ddZd4ddZd5ddZddZddZddZddZddZiZdd Zd!d"Zd6d#d$Zd7d&d'ZGd(d)d)Z d*d+Z!d,d-Z"d.d/Z#Gd0d1d1eZ$dS)8z pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2024 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__r r C/usr/local/lib/python3.9/site-packages/pip/_vendor/pygments/util.pyrsrc@seZdZdZdS) OptionErrorz This exception will be raised by all option processing functions if the type or value of the argument is not correct. Nrr r r r r "sr Fc Cs@|||}|r|}||vrtd|d|dYn(tydtd|d|dYn0dS)z?As :func:`get_bool_opt`, but interpret the value as an integer.rrz ; you must give an integer valuer#N)r r& TypeErrorr ValueErrorr'r r r get_int_optRs    r+cCsN|||}t|tr|St|ttfr4t|Std|d|ddS)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. rrz; you must give a list valueN)r r$rsplitlisttupler )rrrvalr r r get_list_opt^s   r0cCsP|js dSg}|jD]$}|r<|d|qqBqd|S)N )rstrip splitlinesappendrlstrip)objresliner r r docstring_headlinensr:csfdd}j|_t|S)zAReturn a static text analyser function that returns float values.c s^z |}Wnty YdS0|s*dSztdtdt|WSttfyXYdS0dS)Ngg?) Exceptionminmaxfloatr*r))textrvfr r text_analyse|s  z%make_analysator..text_analyse)r staticmethod)rBrCr rAr make_analysatorzs rEcCs|d}|dkr$|d|}n|}|drz(ddt|ddDd}WntyrYd S0td |d tj }| |durd 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).0xr r r sz#shebang_matches..F^z(\.(exe|cmd|bat|bin))?$T) findr rH split_path_rer,r3 IndexErrorrecompile IGNORECASEsearch)r?regexindex first_linefoundr r r shebang_matchess   rZcCs<t|}|durdS|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_rerUgrouprRrSImatchr3)r?rVmdoctyper r r doctype_matchess   rbcCs t|dS)z3Check if the file looks like it has a html doctype.html)rb)r?r r r html_doctype_matchessrdcCsrt|rdSt|}z t|WStylt|}|durFYdSt|dddu}|t|<|YS0dS)z2Check if a doctype exists or if we have some tags.TNi) xml_decl_rer_hash_looks_like_xml_cacheKeyErrorr\rUtag_re)r?keyr`r@r r r looks_like_xmls    rkcCsd|d?d|d@fS)zoGiven a unicode character code with length greater than 16 bits, return the two 16 bit surrogate pair. i iir )cr r r surrogatepairsrnc Csg}d|d}d|dd}|||d|rT|D]}|||dq:n8|D]2}t|d}|||dd|d dqX||d d |S) z)Formats a sequence of strings for output.r2r[z = (,"NrM)rF)r5reprr) var_nameseqraw indent_levellinesZ base_indentZ inner_indentirr r r format_liness  $r|r cCs>g}t}|D]*}||vs||vr$q||||q|S)za Returns a list with duplicates removed from the iterable `it`. Order is preserved. )setr5add)itZ already_seenlstseenrzr r r duplicates_removeds  rc@seZdZdZddZdS)FuturezGeneric class to defer some work. Handled specially in RegexLexerMeta, to support regex string construction at first use. cCstdSN)NotImplementedErrorselfr r r r sz Future.getN)rrrrr r r r r r src Csz|d}|dfWStyzz&ddl}|}|}||fWYSttfyt|d}|dfYYS0Yn0dS)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?rZ prefencodingr r r guess_decodes    rcCsBt|ddr:z||j}Wnty.Yn 0||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?termr r r guess_decode_from_terminal(s   rcCs"t|ddr|jSddl}|S)z7Return our best guess of encoding for the given *term*.rNr)rrrr)rrr r r terminal_encoding9s rc@seZdZddZdS)UnclosingTextIOWrappercCs |dSr)flushrr r r closeCszUnclosingTextIOWrapper.closeN)rrrrr r r r rAsr)NF)N)N)N)Fr)r )%rrRiorrSrPDOTALL MULTILINEVERBOSEr\rTrir^rer*rr;r rr(r+r0r:rErZrbrdrgrkrnr|rrrrrrr r r r s>       -