³ò ¡l‡Jc@s¦dZdZdZddkZddkZddkTddkZgZeeƒD]"Zeddjo eeqQqQ[dd d d d gZ [[e Z de e <e3d?<e2d@<e3dA<e2dB<e3dC<e2dD<e3dE<e2dF<e3dG<ddH<ddI<ddJ<ddKdc„Z?dd„Z@de„ZAeBdfjoTddkCZCeDeCiEƒd joe>eFeCiEd ƒiGƒq¢e>eCiHiGƒndS(isÀTokenization 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 s@GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip MontanaroiÿÿÿÿN(t*it_tCOMMENTttokenizetgenerate_tokenstNLt untokenizeiicGsddi|ƒdS(Nt(t|t)(tjoin(tchoices((s/sys/lib/python/tokenize.pytgroup,scGst|ŒdS(NR(R (R ((s/sys/lib/python/tokenize.pytany-scGst|ŒdS(Nt?(R (R ((s/sys/lib/python/tokenize.pytmaybe.ss[ \f\t]*s #[^\r\n]*s\\\r?\ns [a-zA-Z_]\w*s0[xX][\da-fA-F]*[lL]?s 0[0-7]*[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 [uU]?[rR]?'''s [uU]?[rR]?"""s&[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'s&[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"s\*\*=?s>>=?s<<=?s<>s!=s//=?s[+\-*/%&|^=<>]=?t~s[][(){}]s\r?\ns[:;.,`@]s%[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*t's%[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*t"s'''s"""sr'''sr"""su'''su"""sur'''sur"""sR'''sR"""sU'''sU"""suR'''suR"""sUr'''sUr"""sUR'''sUR"""trtRtutUsr'sr"sR'sR"su'su"sU'sU"sur'sur"sUr'sUr"suR'suR"sUR'sUR"it TokenErrorcBseZRS((t__name__t __module__(((s/sys/lib/python/tokenize.pyRƒstStopTokenizingcBseZRS((RR(((s/sys/lib/python/tokenize.pyR…sc CsA|\}}|\}}d||||t|t|ƒfGHdS(Ns%d,%d-%d,%d: %s %s(ttok_nametrepr( ttypettokent.2t.3tlinetsrowtscolterowtecol((s/sys/lib/python/tokenize.pyt printtoken‡scCs+yt||ƒWntj onXdS(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/sys/lib/python/tokenize.pyR‹s cCs%xt|ƒD]}||Œq WdS(N(R(R(R)t token_info((s/sys/lib/python/tokenize.pyR'žs cCsùt}g}g}|i}xÎ|D]Æ}|d \}}|ttfjo|d7}n|tjo|i|ƒq"ne|tjo|iƒq"nG|ttt fjo t }n'|o|o||dƒt}n||ƒq"Wdi |ƒS(sòTransform 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. Round-trip invariant: # 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 it iÿÿÿÿt( tFalsetappendtNAMEtNUMBERtINDENTtDEDENTtpoptNEWLINERRtTrueR (titerablet startlinetindentsttokst toks_appendttokttoknumttokval((s/sys/lib/python/tokenize.pyR£s,       c csÙd}}}tidd}}d\}}d}dg} x@y |ƒ} Wntj o d} nX|d}dt| ƒ} } |oú| ptd| f‚n|i| ƒ}|oO|idƒ} }t|| | | ||f|| fVd\}}d}qv|oY| ddjoH| d d jo7t || | |t| ƒf|fVd}d}q@qv|| }|| }q@nð|djo¼| o´| pPnd}x~| | jop| | d jo|d}nD| | d jo|t dt }n| | d jo d}nP| d} q±W| | joPn| | djoEt t f| | dj| | || f|t| ƒf| fVq@n|| djo5| i |ƒt| | |df|| f| fVnx–|| djoZ|| jotdd|| | fƒ‚n| d } td|| f|| f| fVqàWn'| ptd|dff‚nd}x| | joöti| | ƒ}|o§|idƒ\}}||f||f|}}} | ||!| |}}||jp|djo%|djot|||| fVqx|djo,|djot pt|||| fVqx|djot |||| fVqx|tjo~t|}|i| | ƒ}|o:|idƒ} | || !}t|||| f| fVqB||f} | |}| }Pqx|tjp"|d tjp|d tjoy|ddjoP||f} t|pt|dp t|d}| |d}}| }PqBt|||| fVqx||jot|||| fVqx|djo d}qx|djo|d}n|djo|d}nt|||| fVqyt | | || f|| df| fV| d} qyWq@x2| dD]&}td|df|dfdfVq‹Wtd|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 stringiþÿÿÿs\ iýÿÿÿs\ R+s s s# t#iÿÿÿÿs3unindent does not match any outer indentation levels sEOF in multi-line statementt.s iis s\s([{s)]}N(R,i(R,i(tstringt ascii_letterstNonet StopIterationtlenRtmatchtendtSTRINGt ERRORTOKENttabsizeRRR.R1tIndentationErrorR2t pseudoprogtspanR0R4t triple_quotedtendprogst single_quotedR/tOPt ENDMARKER(R(tlnumtparenlevt continuedt namecharstnumcharstcontstrtneedconttcontlineR8R!tpostmaxtstrstarttendprogtendmatchRGtcolumnt pseudomatchtstarttsposteposRtinitialtindent((s/sys/lib/python/tokenize.pyRËsØ       )    '  (  )                $t__main__(s'''s"""sr'''sr"""sR'''sR"""su'''su"""sU'''sU"""sur'''sur"""sUr'''sUr"""suR'''suR"""sUR'''sUR"""(RRsr'sr"sR'sR"su'su"sU'sU"sur'sur"sUr'sUr"suR'suR"sUR'sUR"(It__doc__t __author__t __credits__RAtreRt_[1]tdirtxt__all__tN_TOKENSRRRR R Rt WhitespacetCommenttIgnoretNamet Hexnumbert Octnumbert Decnumbert IntnumbertExponentt PointfloattExpfloatt Floatnumbert ImagnumbertNumbertSingletDoubletSingle3tDouble3tTripletStringtOperatortBrackettSpecialtFunnyt PlainTokentTokentContStrt PseudoExtrast PseudoTokentmaptcompilet tokenprogRLt single3progt double3progRCRORNttRPRJt ExceptionRRR&RR'RRRtsysREtargvtopenR(tstdin(((s/sys/lib/python/tokenize.pyss¼  ?            '(&    ( ‹  4