^Rc@sdZdZdZddlZddlZddlTddlZgeeD]ZejdsMe^qMZ e ddd d d g7Z [[e Z de e 6e3d?6e4d@6e3dA6e4dB6e3dC6e4dD6e3dE6e4dF6e3dG6e4dH6e3dI6e4dJ6e3dK6e4dL6e3dM6e4dN6e3dO6e4dP6e3dQ6e4dR6e3dS6e4dT6ddU6ddV6ddW6ddX6ddY6ddZ6Z6iZ7xdD]Z8e8e7e8e>d}Z?d~Z@dddYZAdZBdZCeDdkrddlEZEeFeEjGd kre?eHeEjGd jIqe?eEjJjIndS(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 HettingeriN(t*t_tCOMMENTttokenizetgenerate_tokenstNLt untokenizeiicGsddj|dS(Nt(t|t)(tjoin(tchoices((s/usr/lib/python2.7/tokenize.pytgroup,scGst|dS(NR(R (R ((s/usr/lib/python2.7/tokenize.pytany-scGst|dS(Nt?(R (R ((s/usr/lib/python2.7/tokenize.pytmaybe.ss[ \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/lib/python2.7/tokenize.pyRstStopTokenizingcBseZRS((RR(((s/usr/lib/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/lib/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/lib/python2.7/tokenize.pyRs  cCs%xt|D]}||q WdS(N(R(R*R+t token_info((s/usr/lib/python2.7/tokenize.pyR)st UntokenizercBs,eZdZdZdZdZRS(cCsg|_d|_d|_dS(Nii(ttokenstprev_rowtprev_col(tself((s/usr/lib/python2.7/tokenize.pyt__init__s  cCs:|\}}||j}|r6|jjd|ndS(Nt (R0R.tappend(R1tstarttrowtcolt col_offset((s/usr/lib/python2.7/tokenize.pytadd_whitespaces  cCsx|D]}t|dkr3|j||Pn|\}}}}}|j||jj||\|_|_|ttfkr|jd7_d|_qqWdj |jS(Niiit( tlentcompatR9R.R4R/R0tNEWLINERR (R1titerablettttok_typeR R5tendR#((s/usr/lib/python2.7/tokenize.pyRs  c CsYt}g}|jj}|\}}|ttfkrC|d7}n|ttfkr^t}nt}x|D]} | d \}}|ttfkr|d7}n|tkr|rd|}nt}nt}|t kr|j|qknZ|t kr |j qkn>|ttfkr$t}n#|rG|rG||dt}n||qkWdS(NR3ii( tFalseR.R4tNAMEtNUMBERR=RtTruetSTRINGtINDENTtDEDENTtpop( R1R R>t startlinetindentst toks_appendttoknumttokvalt prevstringttok((s/usr/lib/python2.7/tokenize.pyR<s<                (RRR2R9RR<(((s/usr/lib/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(R>tut((s/usr/lib/python2.7/tokenize.pyRs c cs.d}}}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|dkrt |||| fVq|tkr{t|}|j| | }|r[|jd} | || !}t|||| f| fVq||f} | |}| }Pq|tks|d tks|d tkr|ddkr||f} t|pt|dpt|d}| |d}}| }Pqt|||| fVq||kr>t|||| fVq|dkrSd}q|dkrl|d7}n|dkr|d8}nt|||| fVqt | | || f|| df| fV| d7} qWq@x2| dD]&}td|df|dfdfVqWtd|df|dfdfVdS(sS The generate_tokens() generator requires one argment, 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 0123456789R:isEOF in multi-line stringis\ is\ R3s s s# t#s is3unindent does not match any outer indentation levels sEOF in multi-line statementt.iis s\s([{s)]}N(R:i(R:i(tstringt ascii_letterstNonet StopIterationR;RtmatchRARFt ERRORTOKENttabsizetrstripRRR4RGtIndentationErrorRHt pseudoprogtspanRDR=t triple_quotedtendprogst single_quotedRCtOPt ENDMARKER(R*tlnumtparenlevt continuedt namecharstnumcharstcontstrtneedconttcontlineRKR#tpostmaxtstrstarttendprogtendmatchRAtcolumnt comment_tokentnl_post pseudomatchR5tsposteposR tinitialtindent((s/usr/lib/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"((Kt__doc__t __author__t __credits__RUtreR tdirtxt startswitht__all__tN_TOKENSRRRR R Rt WhitespacetCommenttIgnoretNamet Hexnumbert Octnumbert Binnumbert Decnumbert IntnumbertExponentt PointfloattExpfloatt Floatnumbert ImagnumbertNumbertSingletDoubletSingle3tDouble3tTripletStringtOperatortBrackettSpecialtFunnyt PlainTokentTokentContStrt PseudoExtrast PseudoTokentmaptcompilet tokenprogR^t single3progt double3progRWRaR`R?RbR[t ExceptionRRR(RR)R-RRRtsysR;targvtopenR*tstdin(((s/usr/lib/python2.7/tokenize.pyts  .            '#     A