K i/'dZddlZddlmZejdZejdej ejzejzZ ejdejej zejzZ ejdejZ Gdd eZGd d eZd d Zd!d Zd!dZd!dZdZdZdZdZdZiZdZdZd"dZd#dZGddZ dZ!dZ"dZ#GddeZ$y)$z pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N) TextIOWrapperz[/\\ ]z ]*> z<(.+?)(\s.*?)?>.*?z\s*<\?xml[^>]*\?>ceZdZdZy) ClassNotFoundzCRaised if one of the lookup functions didn't find a matching class.N__name__ __module__ __qualname____doc__S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pygments/util.pyrrsMr rceZdZdZy) 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 rr"sr rc |j||}|r|j}||vr8tdj|dj t t ||S)z} 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, )getlowerrformatjoinmapstr)optionsoptnamealloweddefaultnormcasestrings r get_choice_optr(s^ [[' *F WAHHRVR[R[\_`cel\mRnopp Mr c4|j||}t|tr|St|tr t|St|tst d|d|d|j dvry|j dvryt d|d|d) 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)1yestrueonT)0nofalseoffFInvalid value )r isinstanceboolintrrrrrrrs r get_bool_optr.5s[[' *F&$ FC F|  $M&<yI<<= = 5 5 6 6N6*L J<<= =r c|j||} t|S#t$rtd|d|dt$rtd|d|dwxYw)z?As :func:`get_bool_opt`, but interpret the value as an integer.rr z ; you must give an integer valuer))rr, TypeErrorr ValueErrorr-s r get_int_optr2Rs [[' *F86{ 8M&<yI778 8 8N6*L J778 88s 6Ac|j||}t|tr|jSt|tt fr t |St d|d|d)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. rr z; you must give a list value)rr*rsplitlisttupler)rrrvals r get_list_optr8^sf ++gw 'C#syy{ C$ 'CyM# WIF334 4r c |jsyg}|jjjD]6}|jr#|jd|jz6ndj |j S)N )r strip splitlinesappendrlstrip)objreslines r docstring_headlinerCnsr ;; C !!#..0 ::< JJsTZZ\) *   773<    r cFfd}j|_t|S)zAReturn a static text analyser function that returns float values.c  |}|sy tdtdt|S#t$rYywxYw#tt f$rYywxYw)Ngg?) Exceptionminmaxfloatr1r0)textrvfs r text_analysez%make_analysator..text_analyse|sb 4B sCU2Y/0 0    I&  s.= ::AA)r staticmethod)rLrMs` r make_analysatorrOzs! 99L  %%r c|jd}|dk\r|d|j}n|j}|jdr tj |ddj Dcgc]}|r|jds|c}d}tjd |d tj}|j|y ycc}w#t $rYywxYw) 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#!-F^z(\.(exe|cmd|bat|bin))?$T) findr startswith split_path_rer4r< IndexErrorrecompile IGNORECASEsearch)rJregexindex first_linexfounds r shebang_matchesrcs8 IIdOE z&5\'') ZZ\ T"  - 3 3JqrN4H4H4J K51!,,s"35579E aw&=> N <<  * 5  s$ (C5CCC C#"C#ctj|}|y|jd}tj|tj j |jduS)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]grouprZr[Imatchr<)rJr^mdoctypes r doctype_matchesrlsT   &AyggajG ::eRTT " ( ( 9 EEr ct|dS)z3Check if the file looks like it has a html doctype.html)rl)rJs r html_doctype_matchesros 4 ))r ctj|ryt|} t|S#t$rAt j |}|Yytj |dddu}|t|<|cYSwxYw)z2Check if a doctype exists or if we have some tags.TNi) xml_decl_rerihash_looks_like_xml_cacheKeyErrorrfr]tag_re)rJkeyrjrKs r looks_like_xmlrws| t*C$S))   $ $T * = ]]4; 't 3%'c" s, A6%A65A6c"d|dz zd|dzzfS)zoGiven a unicode character code with length greater than 16 bits, return the two 16 bit surrogate pair. i iir )cs r surrogatepairr{s! a2g 1u9!5 77r cPg}d|zdz}d|dzzdz}|j||zdz|r|D]}|j||zdzn5|D]0}t|dz}|j||ddz|d zdz2|j|d zd j|S) z)Formats a sequence of strings for output.r;rez = (,"NrT)rQ)r>reprr) var_nameseqraw indent_levellines base_indent inner_indentirs r format_linesrs E $q(K,*+a/L LLx'&01  1A LL)C/ 0 1 >AQW A LL#2.26< = > LLs"# 99U r cg}t}|D]-}||vs||vr |j||j|/|S)za Returns a list with duplicates removed from the iterable `it`. Order is preserved. )setr>add)it already_seenlstseenrs r duplicates_removedrsM C 5D  9\)  1    Jr ceZdZdZdZy)FuturezGeneric class to defer some work. Handled specially in RegexLexerMeta, to support regex string construction at first use. ctN)NotImplementedErrorselfs r rz Future.gets!!r N)rrr r rr r r rr s  "r rc |jd}|dfS#t$rX ddl}|j}|j}||fcYS#ttf$r|jd}|dfcYcYSwxYwwxYw)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)rJr prefencodings r guess_decoders "{{7#W} " " !668L;;=D% %"K0 ";;x(D> ! " "s, A8'A A8 $A4/A83A44A8ct|ddr* |j|j}||jfSt |S#t$r Yt |SwxYw)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)rJterms r guess_decode_from_terminalr(sdtZ& ';;t}}-D& &   "      sA AAc\t|ddr |jSddl}|jS)z7Return our best guess of encoding for the given *term*.rNr)rrrr)rrs r terminal_encodingr9s*tZ&}}  & & ((r ceZdZdZy)UnclosingTextIOWrapperc$|jyr)flushrs r closezUnclosingTextIOWrapper.closeCs  r N)rrr rr r r rrAsr r)NFr)Fr)r )%r rZiorr[rXDOTALL MULTILINEVERBOSErfr\rurhrqr1rrFrrr.r2r8rCrOrcrlrorsrwr{rrrrrrrr r r rs$  9% BJJ YY *, /MMBII- < >bjj-rtt4 NJN) =: 8 4 !&"*Z F*   8&  """*")]r