P8 dZdZdZddlZddlZddlmZmZddlddl m Z e e Dcgc] }|dd k7s |c}gd zZ [ e d Zd Zd ZdZdZdZeedezzeezZdZdZdZdZeddZeeeeeZdZeddeezZdezZeeeZ ede dzZ!ee!e eZ"dZ#dZ$d Z%d!Z&d"Z'ee'd#ze'd$zZ(ee'd%ze'd&zZ)ed'd(d)d*d+d,d-d.d/ Z*d0Z+ed1d2d3Z,ee*e+e,Z-ee"e-e)eZ.ee.zZ/ee'd4zed5dze'd6zed7dzZ0edee(Z1eee1e"e-e0ezZ2e3ejhe/e2e%e&f\Z5Z6Z7Z8ed8d9d:d;ed8d9dzZ9ejhe#ejhe$e7e8d?e9Dcic]}|d#e7 c}e9Dcic]}|d$e8 c}e9Dcic]}|dc}Z:d#d$he9Dchc]}|d# c}ze9Dchc]}|d$ c}zZ;d5d7he9Dchc]}|d5 c}ze9Dchc]}|d7 c}zZZ?GdCdDe>Z@dEZAeAfdFZBdGZCGdHdIZDejhdJejZFejhdKejZGdLZHdMZIdNZJdOZKeLdPk(r\ddlMZMeNeMjdkDr&eBePeMjdjyeBeMjjyycc}w#e$reZ YwxYwcc}wcc}wcc}wcc}wcc}wcc}wcc}w)QaTokenization help for Python programs. generate_tokens(readline) is a generator that breaks a stream of text into Python tokens. It accepts a readline-like method which is called repeatedly to get the next line of input (or "" for EOF). It generates 5-tuples with these members: the token type (see token.py) the token (a string) the starting (row, column) indices of the token (a 2-tuple of ints) the ending (row, column) indices of the token (a 2-tuple of ints) the original line (string) It is designed to match the working of the Python tokenizer exactly, except that it produces COMMENT tokens for comments and gives type OP for all operators Older entry points tokenize_loop(readline, tokeneater) tokenize(readline, tokeneater=printtoken) are the same, except instead of generating tokens, tokeneater is a callback function to which the 5 fields described above are passed as 5 arguments, each time a new token is found.zKa-Ping Yee z@GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip MontanaroN)BOM_UTF8lookup)*)token_)tokenizegenerate_tokens untokenizec0ddj|zdzS)N(|))joinchoicess =/opt/alt/python312/lib64/python3.12/lib2to3/pgen2/tokenize.pygroupr0sC#((7"33c99ct|dzS)Nrrrs ranyr1s%/C//rct|dzS)N?rrs rmayber2sE7Oc11rc,tfdDS)Nc3K|]5}dzD]+}|j|jk7s%||z-7yw))N)casefold).0xyls r z _combinations..4s8!!e)Qqzz|qzz|/KA)qs.> >)set)r#s`r _combinationsr&3s  rz[ \f\t]*z #[^\r\n]*z\\\r?\nz\w+z0[bB]_?[01]+(?:_[01]+)*z(0[xX]_?[\da-fA-F]+(?:_[\da-fA-F]+)*[lL]?z0[oO]?_?[0-7]+(?:_[0-7]+)*[lL]?z[1-9]\d*(?:_\d+)*[lL]?z0[lL]?z[eE][-+]?\d+(?:_\d+)*z\d+(?:_\d+)*\.(?:\d+(?:_\d+)*)?z\.\d+(?:_\d+)*z \d+(?:_\d+)*z\d+(?:_\d+)*[jJ]z[jJ]z[^'\\]*(?:\\.[^'\\]*)*'z[^"\\]*(?:\\.[^"\\]*)*"z%[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''z%[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""z'(?:[uUrRbBfF]|[rR][fFbB]|[fFbBuU][rR])?'''"""z'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*"z\*\*=?z>>=?z<<=?z<>z!=z//=?z->z[+\-*/%&@|^=<>]=?~z[][(){}]z\r?\nz:=z[:;.,`@]z'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*"rRfFbB>UuURUruRur)r*r+r'r(c eZdZy) TokenErrorN__name__ __module__ __qualname__rrr:r:rr:c eZdZy)StopTokenizingNr;r?rrrBrBr@rrBc `|\}}|\}}td||||t|t|fzy)Nz%d,%d-%d,%d: %s %s)printtok_namerepr) typerxxx_todo_changemexxx_todo_changeme1linesrowscolerowecols r printtokenrOs<$LT4%LT4 tT4$e= >?rc< t||y#t$rYywxYw)a: The tokenize() function accepts two parameters: one representing the input stream, and one providing an output mechanism for tokenize(). The first parameter, readline, must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as a string. The second parameter, tokeneater, must also be a callable object. It is called once for each token, with five arguments, corresponding to the tuples generated by generate_tokens(). N) tokenize_looprB)readline tokeneaters rr r s# h +    s  c.t|D]}|| yN)r )rRrS token_infos rrQrQs%h/ J0rc$eZdZdZdZdZdZy) Untokenizerc.g|_d|_d|_y)Nrr)tokensprev_rowprev_col)selfs r__init__zUntokenizer.__init__s   rc|\}}||jksJ||jz }|r|jjd|zyy)N )r[r\rZappend)r]startrowcol col_offsets radd_whitespacezUntokenizer.add_whitespacesJSdmm###4==(  KK  sZ/ 0 rcf|D]}t|dk(r|j||np|\}}}}}|j||jj ||\|_|_|ttfvsw|xj dz c_d|_dj|jS)Nrrr) lencompatrfrZrar[r\NEWLINENLr)r]iterablettok_typerrbendrJs rr zUntokenizer.untokenizesA1v{ Ax(01 -HeUC    & KK  u %+. (DM4=GR=( " ! wwt{{##rcd}g}|jj}|\}}|ttfvr|dz }|tt fvrd}|D]}|dd\}}|ttt tfvr|dz }|tk(r|j|C|tk(r|j]|tt fvrd}n|r|r ||dd}||y)NFr`Trh) rZraNAMENUMBERrkrlASYNCAWAITINDENTDEDENTpop) r]rrm startlineindents toks_appendtoknumtokvaltoks rrjzUntokenizer.compats kk((  dF^ # cMF gr] "IC !WNFF$u55# v&6! GR=( wGBK(!  #rN)r<r=r>r^rfr rjr?rrrXrXs 1 $ rrXz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s^[ \t\f]*(?:[#\r\n]|$)c|ddjjdd}|dk(s|jdry|dvs|jdry |S) z(Imitates get_normal_name in tokenizer.c.N r-utf-8zutf-8-)zlatin-1 iso-8859-1z iso-latin-1)zlatin-1-z iso-8859-1-z iso-latin-1-r)lowerreplace startswith)orig_encencs r_get_normal_namersX 3B-    ' 'S 1C g~1 66 ~~AB Orcdd}d}fd}fd}|}|jtr d|dd}d}|s|gfS||}|r||gfStj|s||gfS|}|s||gfS||}|r|||gfS|||gfS) a The detect_encoding() function is used to detect the encoding that should be used to decode a Python source file. It requires one argument, readline, in the same way as the tokenize() generator. It will call readline a maximum of twice, and return the encoding used (as a string) and a list of any lines (left as bytes) it has read in. It detects the encoding from the presence of a utf-8 bom or an encoding cookie as specified in pep-0263. If both a bom and a cookie are present, but disagree, a SyntaxError will be raised. If the encoding cookie is an invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found, 'utf-8-sig' is returned. If no encoding is specified, then the default of 'utf-8' will be returned. FNrcF S#t$r tcYSwxYwrU) StopIterationbytes)rRsr read_or_stopz%detect_encoding..read_or_stops& :  7N s    c> |jd}tj|}|syt |j d} t |}r|jdk7r td|dz }|S#t$rYywxYw#t$rtd|zwxYw)Nasciirzunknown encoding: rzencoding problem: utf-8z-sig) decodeUnicodeDecodeError cookie_rematchrrr LookupError SyntaxErrorname)rJ line_stringrencodingcodec bom_founds r find_cookiez$detect_encoding..find_cookie s ++g.K ,#EKKN3 ?8$E zzW$!";<<  H#"   ?2X=> > ?sA5 B5 BBBTz utf-8-sig)rrblank_rer)rRrdefaultrrfirstsecondrs` @rdetect_encodingrs$IHG , NE ! ab  {5!H%  >>%  ^F 6"H%(( UFO ##rc8t}|j|S)aTransform tokens back into Python source code. Each element returned by the iterable must be a token sequence with at least two elements, a token number and token value. If only two tokens are passed, the resulting output is poor. Round-trip invariant for full input: Untokenized source will match input source exactly Round-trip invariant for limited input: # Output text will tokenize the back to the input t1 = [tok[:2] for tok in generate_tokens(f.readline)] newcode = untokenize(t1) readline = iter(newcode.splitlines(1)).next t2 = [tok[:2] for tokin generate_tokens(readline)] assert t1 == t2 )rXr )rmuts rr r :s$ B == ""rc# Kdx}x}}d\}}d}dg}d}d} d} d} |} |dz}dt| }} |r| s tdj| }|r4|j dx} }t || d|z||f|| zfd\}}d}n|r0| ddd k7r(| d dd k7r t || z|t| f|fd}d}|| z}|| z}|dk(r|s| sn/d}| |krA| | d k(r|dz}n(| | d k(r|tzdztz}n | | dk(rd}nn | dz} | |krA| |k(rn|r|d}| | dvr| | dk(r]| | djd}| t|z}t||| f|| t|zf| ft| |d||f|t| f| fn,ttf| | dk(| | d|| f|t| f| f||dkDr%|j|t| d| |df|| f| f||dkrC||vrtdd|| | f|dd}| r| |dk\rd} d} d} td|| f|| f| f||dkrC| r#| r!| |dk\rd} d} d} n| std|dfd}| |krtj| | }|r]|j!d\}}||f||f|} }}| ||| |}}|t"j$vs |dk(r|dk7rt&|||| fn&|dvr)t(}|dkDrt}n| rd} |r|d}||||| fn|dk(r+|j*drJ|r|d}t|||| fn|t,vrYt.|}|j| | }|r/|j d} | || }|r|d}t |||| f| fnu||f}| |d}| }no|t0vs|ddt0vs |ddt0vrR|ddk(r4||f}t.|xst.|dxs t.|d}| |dd}}| }n|r|d}t |||| fn|j3r|dvr| r|dk(rt4nt6|||| ft8|||| f}|dk(r|s|}|dvr=|r;|dt8k(r/|ddk(r'|dk(rd} |d} t4|d|d|d|dfd}|r|d}|nd|d k(r|r|d}t|||| f| fd}nE|d!vr|dz}n |d"vr|dz }|r|d}t:|||| fnt | | || f|| dzf| f| dz} | |kr|r|d}|ddD]}td|df|dfdft<d|df|dfdfy#t$rd} Y%wxYww)#a4 The generate_tokens() generator requires one argument, readline, which must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as a string. Alternately, readline can be a callable function terminating with StopIteration: readline = open(myfile).next # Example of alternate readline The generator produces 5-tuples with these members: the token type; the token string; a 2-tuple (srow, scol) of ints specifying the row and column where the token begins in the source; a 2-tuple (erow, ecol) of ints specifying the row and column where the token ends in the source; and the line on which the token was found. The line passed is the physical line. r)rrNFrrzEOF in multi-line stringz\ z\ r`  z# #z rrz3unindent does not match any outer indentation levelz zEOF in multi-line statement.T rhr)asyncawaitr)defforr\z([{z)]})rrir:rrpSTRING ERRORTOKENtabsizerstripCOMMENTrlrarwIndentationErrorrx pseudoprogspanstringdigitsrtrkendswith triple_quotedendprogs single_quoted isidentifierrurvrsOP ENDMARKER)rRlnumparenlev continuedcontstrneedcontcontliner{stashed async_defasync_def_indent async_def_nlrJposmaxstrstartendprogendmatchrpcolumn comment_tokennl_pos pseudomatchrbsposeposrinitialnewlinerindents rr r Os #$#D#8iGXHcGGIL  :Daxc$iS  !;XFF}}T*H$LLO+cwds3$ho??$)!d23i61d23i86K!7T>#dCI%6BB!D.#d? ]9F)9#fqjV#Y$&&'/A2Ew1N#Y$&Ag ) cz5 CyG#9#$(J$5$5f$=M 3}#55F"M #;sS5G/G(H$PPtFG} &>D#d)+'"+.M! $ #$  !>q JJICi$**45K(--a0 s#'-$cCd!%eC$u+wfmm+sNu|!5$d;;&%G!|"$"'+ % "&"E4t<<^-u~~d333% "&"E4t<<m+&uoG&}}T37H&ll1o $U3"")M&*G%udT3KFF$(%="&uv,#' -"1I."1I.RyD($(%=#+G#4$6q8J$6#+E!H#5 ,0L!#'"")M&*G%udD$??))+ 22$,1W,<5%#($d#<<$dD9C'"% .#$+AJ$$6$+AJ'$9$~,0 3:2; 0#('!*#*1:wqz#*1:#//'+G% "&I_% "&udT3K>> !I%'HqL E)hl8% "&udD$77!49 #;s1u t==AgSCii ~ !"+rD!9tQi44 b4)dAY 33E D s<U T;C:U D U KU 7U ; U U  U  U __main__)S__doc__ __author__ __credits__rrecodecsrrlib2to3.pgen2.tokenrrdir__all__r NameErrorstrrrrr& WhitespaceCommentIgnoreName Binnumber Hexnumber Octnumber Decnumber IntnumberExponent PointfloatExpfloat Floatnumber ImagnumberNumberSingleDoubleSingle3Double3 _litprefixTripleStringOperatorBracketSpecialFunny PlainTokenTokenContStr PseudoExtras PseudoTokenmapcompile tokenprogr single3prog double3prog _strprefixesrrrr Exceptionr:rBrOr rQrXASCIIrrrrr r r<sysriargvopenrRstdin)r!prefixs00rrs#0* F #!%j 0jAaDCK1j 04, ,  :/1   c*z12 2U7^ C  & 7 . +X 6 )Y 9 = # 57H IERZO [ X %J) & g(= > z; 2 $ # 2 2 7 zE!:#5 6 z;;;; = GWeU%%   % - h) 65&$ /   ;;c:&';;c:&' (Z&1 5vugtLL 25JJ Wg638/ :{K#sC%#sC%&&' F#*"**V*<{ 99EFv&~{*F 9:FFv&~{*F 9+77,vt|,7  9 EN"./,xs^,/0"./,xs^,/0  #J ,- fxq\ -. ,- fxq\ -. !!%Y%? #- & 6 6 p BJJ@"(( K 2::0"(( ; G$R#*`4D z 388}q(4 #4#=#=> 399%% &Y 1  E\GF70/.-sF L$L$L) L7 L<) M> M M * M> M)L43L4