3 \NX=@sdZdZdZddlZddlZddlmZmZddlTddl m Z d d e e Dd d d gZ [ ye Wnek r~eZ YnXddZddZddZdZdZeedeeeZdZdZdZdZeddZeeeeeZdZeddeeZd eZeeeZed!ed"Z ee eeZ!d#Z"d$Z#d%Z$d&Z%d'Z&ee&d(e&d)Z'ee&d*e&d+Z(ed,d-d.d/d0d1d2d3d4 Z)d5Z*ed6d7Z+ee)e*e+Z,ee!e,e(eZ-ee-Z.ee&d8ed9de&d:ed;dZ/edee'Z0eee0e!e,e/eZ1e2e3ej4e.e1e$e%f\Z5Z6Z7Z8ej4e"ej4e#e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8e7e8ddddddddd<4Z9iZ:xdD]Z;e;e:e;<qWiZZ?Gddde>Z@ddZAeAfdd ZBddZCGdddZDej4dejEZFej4dejEZGddZHddZIdd ZJdd ZKeLdkrddlMZMeNeMjOdkr|eBePeMjOdjQn eBeMjRjQdS)aTokenization 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)*)tokencCsg|]}|ddkr|qS)r_).0xrr /usr/lib64/python3.6/tokenize.py %sr tokenizegenerate_tokens untokenizecGsddj|dS)N(|))join)choicesrrr group0srcGs t|dS)Nr)r)rrrr any1srcGs t|dS)N?)r)rrrr maybe2srz[ \f\t]*z #[^\r\n]*z\\\r?\nz [a-zA-Z_]\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][bB]|[bBuU][rR])?'''"""z'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*"z\*\*=?z>>=?z<<=?z<>z!=z//=?z->z[+\-*/%&@|^=<>]=?~z[][(){}]z\r?\nz[:;.,`@]z'[^\n'\\]*(?:\\.[^\n'\\]*)*'z"[^\n"\\]*(?:\\.[^\n"\\]*)*")4rrz'''z"""zr'''zr"""zu'''zu"""zb'''zb"""zf'''zf"""zur'''zur"""zbr'''zbr"""zrb'''zrb"""zR'''zR"""zU'''zU"""zB'''zB"""zF'''zF"""zuR'''zuR"""zUr'''zUr"""zUR'''zUR"""zbR'''zbR"""zBr'''zBr"""zBR'''zBR"""zrB'''zrB"""zRb'''zRb"""zRB'''zRB"""rRuUfFbBr'''r"""R'''R"""u'''u"""U'''U"""b'''b"""B'''B"""f'''f"""F'''F"""ur'''ur"""Ur'''Ur"""uR'''uR"""UR'''UR"""br'''br"""Br'''Br"""bR'''bR"""BR'''BR"""rb'''rb"""Rb'''Rb"""rB'''rB"""RB'''RB"""r'r"R'R"u'u"U'U"b'b"B'B"f'f"F'F"ur'ur"Ur'Ur"uR'uR"UR'UR"br'br"Br'Br"bR'bR"BR'BR"rb'rb"Rb'Rb"rB'rB"RB'RB"c@s eZdZdS) TokenErrorN)__name__ __module__ __qualname__rrrr rwsrwc@s eZdZdS)StopTokenizingN)rxryrzrrrr r{sr{c Cs4|\}}|\}}td||||t|t|fdS)Nz%d,%d-%d,%d: %s %s)printtok_namerepr) typerZxxx_todo_changemeZxxx_todo_changeme1lineZsrowZscolZerowZecolrrr printtokensrc Cs(yt||Wntk r"YnXdS)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_loopr{)readline tokeneaterrrr r s cCsxt|D] }||q WdS)N)r)rrZ token_inforrr rsrc@s,eZdZddZddZddZddZd S) UntokenizercCsg|_d|_d|_dS)Nrr)tokensprev_rowprev_col)selfrrr __init__szUntokenizer.__init__cCs*|\}}||j}|r&|jjd|dS)N )rrappend)rstartrowcol col_offsetrrr add_whitespaces zUntokenizer.add_whitespacecCsxv|D]n}t|dkr$|j||P|\}}}}}|j||jj||\|_|_|ttfkr|jd7_d|_qWdj |jS)Nrr) lencompatrrrrrNEWLINENLr)riterablettok_typerrendrrrr rs        zUntokenizer.untokenizec Csd}g}|jj}|\}}|ttfkr,|d7}|ttfkr|t kr|j qBn*|ttfkrd}n|r|r||dd}||qBWdS)NFrTrr) rrNAMENUMBERrrASYNCAWAITINDENTDEDENTpop) rrr startlineindents toks_appendtoknumtokvaltokrrr rs0      zUntokenizer.compatN)rxryrzrrrrrrrr rsrz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s^[ \t\f]*(?:[#\r\n]|$)cCsH|ddjjdd}|dks*|jdr.dS|d ks@|jdrDdS|S)z(Imitates get_normal_name in tokenizer.c.N r-zutf-8zutf-8-latin-1 iso-8859-1 iso-latin-1latin-1- iso-8859-1- iso-latin-1-)rrr)rrr)lowerreplace startswith)orig_encencrrr _get_normal_names rcsdd}d}fdd}fdd}|}|jtrHd|d d}d }|sT|gfS||}|rj||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. FNzutf-8c s"yStk rtSXdS)N) StopIterationbytesr)rrr read_or_stop sz%detect_encoding..read_or_stopcsy|jd}Wntk r"dSXtj|}|s6dSt|jd}y t|}Wn tk rptd|YnXr|j dkrtd|d7}|S)Nasciirzunknown encoding: zutf-8zencoding problem: utf-8z-sig) decodeUnicodeDecodeError cookie_rematchrrr LookupError SyntaxErrorname)r line_stringrencodingcodec) bom_foundrr find_cookie&s"   z$detect_encoding..find_cookieTz utf-8-sig)rrblank_rer)rrdefaultrrfirstsecondr)rrr detect_encoding s0         rcCst}|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 intput: # 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 )rr)rutrrr rTsc!csd}}}tjdd}}d \}}d}dg} d} d} d} d} xy |}Wntk rdd}YnX|d}dt|}}|rF|std||j|}|r|jd}}t||d||||f||fVd!\}}d}nd|r0|d"dd kr0|d#dd kr0t||||t|f|fVd}d}qBn||}||}qBnF|dkrt| rt|s`Pd}xf||kr||d kr|d}n6||dkr|t dt }n||dkrd}nP|d}qfW||krP| r| Vd} ||dkr||dkrh||dj d}|t|}t |||f||t|f|fVt ||d||f|t|f|fVqBt t f||dk||d||f|t|f|fVqB|| d$kr| j |t|d||df||f|fVxt|| d%krJ|| krtdd|||f| dd&} | r.| | d'kr.d} d} d} td||f||f|fVqW| r| r| | d(krd} d} d} n|std|dfd}x||kr8tj||}|r |jd\}}||f||f|}}}|||||}}||ks|dkr|dkrt||||fVq4|dkrft}|dkr8t }n | rBd} | rR| Vd} |||||fVq4|dkr| r| Vd} t ||||fVq4|tkrt|}|j||}|r|jd}|||}| r| Vd} t||||f|fVn||f}||d}|}Pq4|tks@|dd tks@|dd tkr|d)dkr||f}t|pxt|dpxt|d }||dd}}|}Pn | r| Vd} t||||fVq4||kr|d*kr| r|dkrtnt||||fVqt||||f}|dkr| r|} q|dkrx| rx| dtkrx| ddkrxd} | d+} t| d| d | d | dfVd} | r| Vd} |Vnz|dkr| r| Vd} t ||||f|fVd}nF|dkr|d}n|dkr|d}| r| Vd} t||||fVn(t||||f||df|fV|d}qWqBW| rN| Vd} x.| ddD]} td|df|dfdfVq\Wtd|df|dfdfVdS),aT 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 logical line; continuation lines are included. rr 0123456789rNFrzEOF in multi-line stringrz\ rz\ r  z# #z z3unindent does not match any outer indentation levelz zEOF in multi-line statement.T asyncawaitdef\z([{z)]})rr)rrrrrrrr)rrr)stringZ ascii_lettersrrrwrrSTRING ERRORTOKENtabsizerstripCOMMENTrrrIndentationErrorr pseudoprogspanrr triple_quotedendprogs single_quotedrrrOP ENDMARKER)!rlnumparenlev continuedZ namecharsnumcharscontstrneedcontcontlinerstashed async_defasync_def_indent async_def_nlrposmaxstrstartendprogendmatchrcolumn comment_tokennl_pos pseudomatchrsposeposrinitialnewlinerindentrrr risp     *                             __main__)*rrr&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrM)*rrrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtru)S__doc__ __author__ __credits__rrecodecsrrZlib2to3.pgen2.tokenrrdir__all__r NameErrorstrrrr WhitespaceCommentIgnoreName Binnumber Hexnumber Octnumber Decnumber IntnumberExponent PointfloatExpfloat Floatnumber ImagnumberNumberSingleDoubleSingle3Double3Z _litprefixTripleStringOperatorBracketSpecialFunny PlainTokenTokenContStr PseudoExtras PseudoTokenlistmapcompileZ tokenprogrZ single3progZ double3progrrrrr Exceptionrwr{rr rrASCIIrrrrrrrxsysrargvopenrstdinrrrr s              8 Ic