QfR TdZdZdZddlmZddlmZmZddl Z ddl Z ddl m Z ddl ZddlZddlZddldd lmZddlZej(d ej*Zej(d ej*ZddlZej0gd zZ[Gd de j2ddZdZdZdZdZdZeedezzeezZ dZ!dZ"dZ#dZ$dZ%ee"e#e$e%Z&dZ'eddee'zZ(de'zZ)ee(e)Z*ede*d zZ+ee+e*e&Z,d!Z-e j\d"Z/ee-Z0d#Z1d$Z2d%Z3d&Z4ee0d'ze0d(zZ5ee0d)ze0d*zZ6ee7ejpe9ed+,Z:ed-e:Z;ee,e;e6e!Zed2ee5Z?eee?e,e;e>e!zZ@iZAe-D]"ZBe1eAeBd/z<e2eAeBd1z<e3eAeBd'z<e4eAeBd(z<$[BeCZDeCZEe-D]BZFeFd1zeFd/zfD]ZGeDjeGeFd(zeFd'zfD]ZGeEjeGD[F[Gd3ZIGd4d5eJZKGd6d7eJZLGd8d9ZMd:ZNd;ZOd<ZPd=Zd>ZQd?ZRd@ZSdAZTdDdBZUeVdCk(reSyy)EaoTokenization help for Python programs. tokenize(readline) is a generator that breaks a stream of bytes into Python tokens. It decodes the bytes according to PEP-0263 for determining source file encoding. It accepts a readline-like method which is called repeatedly to get the next line of input (or b"" 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. Additionally, all token lists start with an ENCODING token which tells you which encoding was used to decode the bytes stream. zKa-Ping Yee zpGvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger, Trent Nelson, Michael Foord)open)lookupBOM_UTF8N) TextIOWrapper)*)EXACT_TOKEN_TYPESz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s^[ \t\f]*(?:[#\r\n]|$))tokenizegenerate_tokensdetect_encoding untokenize TokenInfoc"eZdZdZedZy)r cpd|jt|jfz}d|j|zS)Nz%d (%s)z8TokenInfo(type=%s, string=%r, start=%r, end=%r, line=%r))type)rtok_name_replace)selfannotated_types //opt/alt/python312/lib64/python3.12/tokenize.py__repr__zTokenInfo.__repr__0s9"dii$))1D%EEJ > 23 4c|jtk(r%|jtvrt|jS|jSN)rOPstringrrs r exact_typezTokenInfo.exact_type5s2 99?t{{.??$T[[1 199 rN)__name__ __module__ __qualname__rpropertyrrrr r /s4 rr ztype string start end linec0ddj|zdzS)N(|))joinchoicess rgroupr*<sC#((7"33c99rct|dzS)Nrr*r(s ranyr-=s%/C//rct|dzS)N?r,r(s rmayber0>sE7Oc11rz[ \f\t]*z #[^\r\n]*z\\\r?\nz\w+z0[xX](?:_?[0-9a-fA-F])+z0[bB](?:_?[01])+z0[oO](?:_?[0-7])+z(?:0(?:_?0)*|[1-9](?:_?[0-9])*)z[eE][-+]?[0-9](?:_?[0-9])*z)[0-9](?:_?[0-9])*\.(?:[0-9](?:_?[0-9])*)?z\.[0-9](?:_?[0-9])*z[0-9](?:_?[0-9])*z[0-9](?:_?[0-9])*[jJ]z[jJ]c  gd}dh}|D]q}tj|D]W}tj|Dcgc]}||jfc}D]"}|j dj |$Ys|Scc}w)N)brufbrfr) _itertools permutationsproductupperaddr')_valid_string_prefixesresultprefixtcr4s r_all_string_prefixesrCUs>TF(((0A ''!)D!Q1aggi.!)DE 2771:&F1) M*EsB cJtj|tjSr)recompileUNICODE)exprs r_compilerIds ::dBJJ ''rz[^'\\]*(?:\\.[^'\\]*)*'z[^"\\]*(?:\\.[^"\\]*)*"z%[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''z%[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""z'''z"""z'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*"T)reversez\r?\nz'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*"z \\\r?\n|\Zc eZdZy) TokenErrorNrrr r"rrrOrOrrOc eZdZy)StopTokenizingNrPr"rrrSrSrQrrSc*eZdZdZdZdZdZdZy) UntokenizercJg|_d|_d|_d|_d|_y)Nr)tokensprev_rowprev_col prev_typeencodingrs r__init__zUntokenizer.__init__s%    rc|\}}||jks||jk(r@||jkr1tdj|||j|j||jz }|r%|jj d|zd|_||jz }|r|jj d|zyy)Nz+start ({},{}) precedes previous end ({},{})z\ r )rYrZ ValueErrorformatrXappend)rstartrowcol row_offset col_offsets radd_whitespacezUntokenizer.add_whitespacesS  #"63;NJ$fS#t}}dmmLN N4==(  KK  v 2 3DM4==(  KK  sZ/ 0 rc @g}d}|D]}|dk(r|rd}n|j||dk(rRtdtjdj|dddD}|dzd k(r|j|nd }|j|d j |S) NF}{c3 K|]}dyw)rWNr").0chars r z.Untokenizer.escape_brackets..s$#$A#s \rTr8)rbsumr9 takewhile__eq__r')rtoken charactersconsume_until_next_bracket character n_backslashess rescape_bracketszUntokenizer.escape_bracketss %*"IC-16.%%i0C #$","6"6 "26r6*#$! !1$)%%i015.   i (#$wwz""rcXt|}g}d}|D]}t|dk(r|j||n|\}}}} } |tk(r||_@|t k(rn|t k(r|j|g|tk(r |j| \|_ |_ |ttfvrd}n|rF|rD|d} |dt| k\r+|jj| t| |_ d}n|tk(r]d|vsd|vr|j!|}|j"d} | \} }| j%d| j%d z}| ||zf} nA|t&t(fvr3|j*t&t,fvr|jjd |j/||jj|| \|_ |_ |ttfvr|xjdz c_ d |_ ||_d j1|jS) NFrsTrrrWrkrjz{{z}}r_rr8)iterlencompatENCODINGr\ ENDMARKERINDENTrbDEDENTpoprYrZNEWLINENLrXFSTRING_MIDDLEr| splitlinescountSTRING FSTRING_STARTr[ FSTRING_ENDrhr')riterableitindents startlinerAtok_typerwrcendlineindent last_lineend_lineend_col extra_charss rr zUntokenizer.untokenizes (^ A1v{ Ar"01 -HeUC8# % 9$6!u%V# /2, t}gr]* w 8s6{*KK&&v.$'KDM! ^+%<3%< 007E 0 0 0 22 6I(+%Hg"+//$"7)//$:O"OK#W{%:;Cfm44FT_K`9` ""3'    & KK  u %+. (DM4=GR=( " ! %DNSTwwt{{##rc,g}|jj}|dttfv}d}d}t j |g|D]L}|dd\} } | t k(r| |_| ttfvr| dz } | tk(r |rd| z} d}nd}| tk(r|dz }n| tk(r|dz}| tk(r|j| }| tk(r|j| ttfvrd}n,|r|r||dd}n| t k(r|j#| } | dvr%|jr|jd| k(r|rd| z} | ttfvr3|j$ttfvr|jjd|| | |_Oy) NrFrsr_TrWrr>rkrj)rXrbrrr9chainrr\NAMENUMBERrrrrrrrr|r[) rrwrr toks_appendr prevstring in_fstringtoktoknumtokvals rrzUntokenizer.compatskk(( !H" -   ##UGX6C !WNFF! & $'#  6\F! " &a ;&a v&6! GR=( wGBK(! >)--f5#  B68QV`v&-00T^^P[G\5\ ""3'  #DNY7rN)rrr r]rhr|r rr"rrrUrUs 1#..$`3$rrUct}|j|}|j|j|j}|S)aTransform tokens back into Python source code. It returns a bytes object, encoded using the ENCODING token, which is the first token sequence output by tokenize. 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 bytes will tokenize back to the input t1 = [tok[:2] for tok in tokenize(f.readline)] newcode = untokenize(t1) readline = BytesIO(newcode).readline t2 = [tok[:2] for tok in tokenize(readline)] assert t1 == t2 )rUr r\encode)rutouts rr r :s:( B -- !C {{jj% Jrc|ddjjdd}|dk(s|jdry|dvs|jdry |S) z(Imitates get_normal_name in tokenizer.c.N _-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_namerUsX 3B-    ' 'S 1C g~1 66 ~~AB Orcj jjdd}d}fd}fd}|}|jtr d|dd}d}|s|gfS||}|r||gfSt j |s||gfS|}|s||gfS||}|r|||gfS|||gfS#t$rdYwxYw) 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. NFrc2 S#t$rYywxYw)Nr) StopIterationreadlinesr read_or_stopz%detect_encoding..read_or_stopxs" :   s  c |jd}tj |}|syt |jd} t|}r5|dk7r+ d}t|dj}t||d z }|S#t$r"d}dj|}t|wxYw#t$r0d|z}t|dj|}t|wxYw) Nrz'invalid or missing encoding declarationz {} for {!r}rWzunknown encoding: zunknown encoding for {!r}: {}zencoding problem: utf-8z encoding problem for {!r}: utf-8z-sig) decodeUnicodeDecodeErrorra SyntaxError cookie_rematchrr*r LookupError)r line_stringmsgrr\codec bom_foundfilenames r find_cookiez$detect_encoding..find_cookie~s( #++g.K ,#EKKN3 #8$E 7"#3C"#&&=CCHMC!#&&  H=" #;C##**39c" "  # #*X5c" "6<>%  ^F 6"H%(( UFO ##O sB$$ B21B2ct|d} t|j\}}|jdt ||d}d|_|S#|j xYw)zXOpen a file in read only mode using the encoding detected by detect_encoding(). rbrT)line_bufferingr3) _builtin_openr rseekrmodeclose)rbufferr\linestexts rrrs_8T *F)&//:% AVXdC    s ?AA!c#Kt|\}}tj|t|d}||dk(rd}t t |dddt |j|dEd{y7w) a The tokenize() 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 bytes. Alternatively, readline can be a callable function terminating with StopIteration: readline = open(myfile, 'rb').__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. The first token sequence will always be an ENCODING token which tells you which encoding was used to decode the bytes stream. rNrr)rrr8T extra_tokens)r r9rr~r r!_generate_tokens_from_c_tokenizer__next__)rr\consumedrl_gens rr r sm&)2Hh   hXs(; .perrors& ! rc|r|f|z|fz}d|zn|r|d|n d|ztjdy)Nz%s:%d:%d: error: %sz : error: z error: %srW)rexit)rrlocationargsrs rerrorzmain..errorsO ;)WJ6D (4/ 0  h8 9 ;( )  rzpython -m tokenize)progrr/z filename.pyz'the file to tokenize; defaults to stdin)destnargsmetavarhelpz-ez--exactexact store_truez(display token names using the exact type)ractionrrzTrz %d,%d-%d,%d:2015rWrz interrupted zunexpected error: %s)NN)argparseArgumentParser add_argument parse_argsrrlistr rrrstdinrrrrcrprintrrIndentationErrorrrOrOSErrorKeyboardInterrupt Exception)rrparserrrr5rXrw token_type token_rangeerrrcolumnrs @rmainr s $ $*> $ ?F Zs -FH iglGI    D" ==}}Hx.!hqzz23/.!H6 ""7F EJzz"-- (EKK%)),CDK  4ellD E /. 5xx{1Q' f chhqk8dF^44 5xx{ f chhqk8dF^44  c8  c  o %+, sg$E D= BE =EE H&.F H&+G H& G H&'G44H& H& H!!H&cd|vry|S)zTransform error messages from the C tokenizer into the Python tokenize The C tokenizer is more picky than the Python one, so we need to massage the error messages a bit for backwards compatibility. z)unterminated triple-quoted string literalzEOF in multi-line stringr")rs r_transform_msgr /s 3c9) Jrc#jK|tj||}ntj|||} |D]}tj|y#t$rR}t |tk7r|dt |j}t||j|jfdd}~wwxYww)zWTokenize a source reading Python code as unicode strings using the internal C tokenizerNr)r\r) _tokenize TokenizerIterr _makerrr rrOlinenooffset)sourcer\rrinfoers rrr9s  $ $V, G  $ $Vh\ Z>D//$' ' > 7k ! QUU#qxx23= >s)3B3AB3 B0A B++B00B3__main__)NF)W__doc__ __author__ __credits__builtinsrrcodecsrr collections functoolsior itertoolsr9rErrwrr rFASCIIrr__all__ namedtupler r*r-r0 WhitespaceCommentIgnoreName Hexnumber Binnumber Octnumber Decnumber IntnumberExponent PointfloatExpfloat Floatnumber ImagnumberNumberrC lru_cacherI StringPrefixSingleDoubleSingle3Double3TripleStringmapescapesortedSpecialFunny PlainTokenTokenContStr PseudoExtras PseudoTokenendpats_prefixset single_quoted triple_quotedrAr4r=tabsizerrOrSrUr rr r r r r rrr"rrrIs,*  +# # BJJ@"(( K 2::0"(( ; --6 6  & &&{4PQ :/1  c*z12 2U7^ C  &  . )Y 9 = ( ?)+-28_= ( *J) +[7-B C z; 2  (( *,-  $ # 2 2 |e#\E%9 : |==== ? RYY'8$ GH I h  65&$ /   ==c:&'==c:&' (]GV4 5vugtLL #%G#GGcM#GGcM&GGeO&GGeO &     A#gq3w ! %iU #!$ q !!&Y%P$P$f6 Z$z _8J=~ >  zFr