zfc@sdZdZdZddlmZddlZddlZddlTddlZgeeD]Z e j ds]e ^q]Z e dd d d d g7Z [ [e Z dee 6e6d?6e5d@6e6dA6e5dB6e6dC6e5dD6e6dE6e5dF6e6dG6e5dH6e6dI6e5dJ6e6dK6e5dL6e6dM6e5dN6e6dO6e5dP6e6dQ6e5dR6e6dS6e5dT6e6dU6ddV6ddW6ddX6ddY6ddZ6dd[6Z8iZ9xdD]Z:e:e9e:d{e=fd|YZ?d}Z@e@d~ZAdZBdddYZCdZDdZEeFdkrddlGZGeHeGjId kreAeJeGjId jKqeAeGjLjKndS(sTokenization 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.sKa-Ping Yee sSGvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettingeri(tchainN(t*t_tCOMMENTttokenizetgenerate_tokenstNLt untokenizeiicGsddj|dS(Nt(t|t)(tjoin(tchoices((s /usr/lib64/python2.7/tokenize.pytgroup-tcGst|dS(NR(R (R ((s /usr/lib64/python2.7/tokenize.pytany.RcGst|dS(Nt?(R (R ((s /usr/lib64/python2.7/tokenize.pytmaybe/Rs[ \f\t]*s #[^\r\n]*s\\\r?\ns [a-zA-Z_]\w*s0[xX][\da-fA-F]+[lL]?s(0[oO][0-7]+)|(0[0-7]*)[lL]?s0[bB][01]+[lL]?s [1-9]\d*[lL]?s [eE][-+]?\d+s\d+\.\d*s\.\d+s\d+s\d+[jJ]s[jJ]s[^'\\]*(?:\\.[^'\\]*)*'s[^"\\]*(?:\\.[^"\\]*)*"s%[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''s%[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""s[uUbB]?[rR]?'''s[uUbB]?[rR]?"""s([uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'s([uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"s\*\*=?s>>=?s<<=?s<>s!=s//=?s[+\-*/%&|^=<>]=?t~s[][(){}]s\r?\ns[:;.,`@]s'[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*t's'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*t"s \\\r?\n|\Zs'''s"""sr'''sr"""su'''su"""sur'''sur"""sR'''sR"""sU'''sU"""suR'''suR"""sUr'''sUr"""sUR'''sUR"""sb'''sb"""sbr'''sbr"""sB'''sB"""sbR'''sbR"""sBr'''sBr"""sBR'''sBR"""trtRtutUtbtBsr'sr"sR'sR"su'su"sU'sU"sur'sur"sUr'sUr"suR'suR"sUR'sUR"sb'sb"sB'sB"sbr'sbr"sBr'sBr"sbR'sbR"sBR'sBR"it TokenErrorcBseZRS((t__name__t __module__(((s /usr/lib64/python2.7/tokenize.pyRstStopTokenizingcBseZRS((RR(((s /usr/lib64/python2.7/tokenize.pyRsc CsA|\}}|\}}d||||t|t|fGHdS(Ns%d,%d-%d,%d: %s %s(ttok_nametrepr( ttypettokent srow_scolt erow_ecoltlinetsrowtscolterowtecol((s /usr/lib64/python2.7/tokenize.pyt printtokens  cCs)yt||Wntk r$nXdS(s: 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(t tokenize_loopR(treadlinet tokeneater((s /usr/lib64/python2.7/tokenize.pyRs  cCs%xt|D]}||q WdS(N(R(R,R-t token_info((s /usr/lib64/python2.7/tokenize.pyR+st UntokenizercBs,eZdZdZdZdZRS(cCsg|_d|_d|_dS(Nii(ttokenstprev_rowtprev_col(tself((s /usr/lib64/python2.7/tokenize.pyt__init__s  cCs|\}}||jks9||jkr`||jkr`tdj|||j|jn||j}|r|jjd|d|_n||j}|r|jjd|ndS(Ns+start ({},{}) precedes previous end ({},{})s\ it (R1R2t ValueErrortformatR0tappend(R3tstarttrowtcolt row_offsett col_offset((s /usr/lib64/python2.7/tokenize.pytadd_whitespaces -    c Cst|}g}t}xt|D]l}t|dkrK|j||Pn|\}}}} } |tkrpPn|tkr|j|qn|tkr|j| \|_ |_ qnr|t t fkrt }nW|r/|r/|d} |dt| kr&|jj| t| |_ nt}n|j||jj|| \|_ |_ |t t fkr|j d7_ d|_ qqWdj|jS(NiiiiR(titertFalsetlentcompatt ENDMARKERtINDENTR8tDEDENTtpopR1R2tNEWLINERtTrueR0R>R ( R3titerabletittindentst startlinettttok_typeR"R9tendR%tindent((s /usr/lib64/python2.7/tokenize.pyRs@            c Cs/g}|jj}|dttfk}t}xt|g|D]}|d \}} |ttfkrv| d7} n|tkr|rd| } nt }nt}|t kr|j| qAnZ|t kr|j qAn>|ttfkrt }n#|r|r||dt}n|| qAWdS(NiiR5i( R0R8RGRR@RtNAMEtNUMBERtSTRINGRHRDRERF( R3R"RIRKt toks_appendRLt prevstringttokttoknumttokval((s /usr/lib64/python2.7/tokenize.pyRBs2            (RRR4R>RRB(((s /usr/lib64/python2.7/tokenize.pyR/s  "cCst}|j|S(sTransform 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 tok in generate_tokens(readline)] assert t1 == t2 (R/R(RItut((s /usr/lib64/python2.7/tokenize.pyR s ccsEd}}}tjdd}}d\}}d}dg} xy |} Wntk rfd} nX|d7}dt| } } |r{| std| fn|j| }|r|jd} }t|| | | ||f|| fVd\}}d}q|ra| ddkra| d d krat || | |t| f|fVd}d}q@q|| }|| }q@n`|dkr| r| sPnd}xv| | kr| | d kr|d7}n?| | d kr|t dt }n| | d krd}nP| d7} qW| | kr'Pn| | dkr| | dkr| | j d}| t|}t ||| f|| t|f| fVt | |||f|t| f| fVq@t t f| | dk| | || f|t| f| fVq@n|| dkrI| j|t| | |df|| f| fVnx|| dkr|| krtdd|| | fn| d } td|| f|| f| fVqLWn$| std|dffnd}x | | krtj| | }|r|jd\}}||f||f|}}} ||krIqn| ||!| |}}||ks|dkr|dkrt|||| fVq|dkr|dkrt nt|||| fVq|dkr |jd stt |||| fVq|tkrt|}|j| | }|rq|jd} | || !}t|||| f| fVq||f} | |}| }Pq|tks|d tks|d tkr1|ddkr||f} t|pt|dpt|d}| |d}}| }Pqt|||| fVq||krTt|||| fVq|dkrid}q|dkr|d7}n|dkr|d8}nt|||| fVqt | | || f|| df| fV| d7} qWq@Wx2| dD]&}td|df|dfdfVqWtd|df|dfdfVdS(sT 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. iRt 0123456789RisEOF in multi-line stringis\ is\ R5s s s# t#s is3unindent does not match any outer indentation levels sEOF in multi-line statementt.s iis\s([{s)]}N(Ri(Ri(tstringt ascii_letterstNonet StopIterationRARtmatchRORSt ERRORTOKENttabsizetrstripRRR8RDtIndentationErrorREt pseudoprogtspanRRRGtendswithtAssertionErrort triple_quotedtendprogst single_quotedRQtOPRC(R,tlnumtparenlevt continuedt namecharstnumcharstcontstrtneedconttcontlineRKR%tpostmaxtstrstarttendprogtendmatchROtcolumnt comment_tokentnl_post pseudomatchR9tsposteposR"tinitialRP((s /usr/lib64/python2.7/tokenize.pyRs        &      $ #  '  '                    $t__main__(s'''s"""sr'''sr"""sR'''sR"""su'''su"""sU'''sU"""sur'''sur"""sUr'''sUr"""suR'''suR"""sUR'''sUR"""sb'''sb"""sB'''sB"""sbr'''sbr"""sBr'''sBr"""sbR'''sbR"""sBR'''sBR"""(RRsr'sr"sR'sR"su'su"sU'sU"sur'sur"sUr'sUr"suR'suR"sUR'sUR"sb'sb"sB'sB"sbr'sbr"sBr'sBr"sbR'sbR"sBR'sBR"((Mt__doc__t __author__t __credits__t itertoolsRR]treR"tdirtxt startswitht__all__tN_TOKENSRRRR RRt WhitespacetCommenttIgnoretNamet Hexnumbert Octnumbert Binnumbert Decnumbert IntnumbertExponentt PointfloattExpfloatt Floatnumbert ImagnumbertNumbertSingletDoubletSingle3tDouble3tTripletStringtOperatortBrackettSpecialtFunnyt PlainTokentTokentContStrt PseudoExtrast PseudoTokentmaptcompilet tokenprogRft single3progt double3progR_RkRjRMRlRct ExceptionRRR*RR+R/RRRtsysRAtargvtopenR,tstdin(((s /usr/lib64/python2.7/tokenize.pyts  .            '#     W