{yMaxKc&@s6dZdZdZddlZddlZddlmZmZddlTddl m Z d d e e Dd d d gZ [ ye Wnek reZ YnXddZddZddZdZdZeedeeeZdZdZdZdZdZeeeeeZdZeddeeZdeZeeeZed ed!Z ee eeZ!d"Z"d#Z#d$Z$d%Z%ed&d'Z&ed(d)Z'ed*d+d,d-d.d/d0d1d2 Z(d3Z)ed4d5Z*ee(e)e*Z+ee!e+e'eZ,ee,Z-ed6ed7dd8ed9dZ.edee&Z/eee/e!e+e.eZ0e1e2ej3e-e0e$e%f\Z4Z5Z6Z7i&ej3e"d76ej3e#d96e6d:6e7d;6e6d<6e7d=6e6d>6e7d?6e6d@6e7dA6e6dB6e7dC6e6dD6e7dE6e6dF6e7dG6e6dH6e7dI6e6dJ6e7dK6e6dL6e7dM6e6dN6e7dO6e6dP6e7dQ6e6dR6e7dS6e6dT6e7dU6e6dV6e7dW6ddX6ddY6ddZ6dd[6dd\6dd]6Z9iZ:xdD]Z;e;e:e;Z?Gd}d~d~e>Z@ddZAeAdd ZBddZCGdddZDej3dejEZFej3dejEZGddZHddZIdd ZJdd ZKeLdkr2ddlMZMeNeMjOdkreBePeMjOdjQq2eBeMjRjQndS(uTokenization 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.uKa-Ping Yee u@GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip MontanaroiN(uBOM_UTF8ulookup(u*i(utokencCs&g|]}|ddkr|qS(iu_((u.0ux((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu %s u utokenizeugenerate_tokensu untokenizecGsddj|dS(Nu(u|u)(ujoin(uchoices((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyugroup0sugroupcGst|dS(Nu*(ugroup(uchoices((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyuany1suanycGst|dS(Nu?(ugroup(uchoices((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyumaybe2sumaybeu[ \f\t]*u #[^\r\n]*u\\\r?\nu [a-zA-Z_]\w*u 0[bB][01]*u0[xX][\da-fA-F]*[lL]?u0[oO]?[0-7]*[lL]?u [1-9]\d*[lL]?u [eE][-+]?\d+u\d+\.\d*u\.\d+u\d+u\d+[jJ]u[jJ]u[^'\\]*(?:\\.[^'\\]*)*'u[^"\\]*(?:\\.[^"\\]*)*"u%[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''u%[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""u[ubUB]?[rR]?'''u[ubUB]?[rR]?"""u&[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'u&[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"u\*\*=?u>>=?u<<=?u<>u!=u//=?u->u[+\-*/%&|^=<>]=?u~u[][(){}]u\r?\nu[:;.,`@]u'[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*u'u'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*u"u'''u"""ur'''ur"""uu'''uu"""ub'''ub"""uur'''uur"""ubr'''ubr"""uR'''uR"""uU'''uU"""uB'''uB"""uuR'''uuR"""uUr'''uUr"""uUR'''uUR"""ubR'''ubR"""uBr'''uBr"""uBR'''uBR"""uruRuuuUubuBur'ur"uR'uR"uu'uu"uU'uU"ub'ub"uB'uB"uur'uur"uUr'uUr"uuR'uuR"uUR'uUR"ubr'ubr"uBr'uBr"ubR'ubR"uBR'uBR"icBs|EeZdZdS(u TokenErrorN(u__name__u __module__u __qualname__(u __locals__((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu TokenErrorsu TokenErrorcBs|EeZdZdS(uStopTokenizingN(u__name__u __module__u __qualname__(u __locals__((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyuStopTokenizingsuStopTokenizingc CsF|\}}|\}}td||||t|t|fdS(Nu%d,%d-%d,%d: %s %s(uprintutok_nameurepr( utypeutokenuxxx_todo_changemeuxxx_todo_changeme1ulineusrowuscoluerowuecol((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu printtokens  u printtokenc Cs*yt||Wntk r%YnXdS(u: 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(u tokenize_loopuStopTokenizing(ureadlineu tokeneater((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyutokenizes  cCs%xt|D]}||q WdS(N(ugenerate_tokens(ureadlineu tokeneateru token_info((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu tokenize_loopsu tokenize_loopcBsD|EeZdZddZddZddZddZd S( u UntokenizercCsg|_d|_d|_dS(Nii(utokensuprev_rowuprev_col(uself((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu__init__s  uUntokenizer.__init__cCs:|\}}||j}|r6|jjd|ndS(Nu (uprev_colutokensuappend(uselfustarturowucolu col_offset((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyuadd_whitespaces  uUntokenizer.add_whitespacecCsx|D]}t|dkr3|j||Pn|\}}}}}|j||jj||\|_|_|ttfkr|jd7_d|_qqWdj |jS(Niiiu( ulenucompatuadd_whitespaceutokensuappenduprev_rowuprev_coluNEWLINEuNLujoin(uselfuiterableututok_typeutokenustartuenduline((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu untokenizes  uUntokenizer.untokenizec Cs+d}g}|jj}|\}}|ttfkrC|d7}n|ttfkr^d}nx|D]}|dd\}}|ttfkr|d7}n|tkr|j|qenZ|t kr|j qen>|ttfkrd}n#|r|r||dd}n||qeWdS(Nu iiFTi( uFalseutokensuappenduNAMEuNUMBERuNEWLINEuNLuTrueuINDENTuDEDENTupop( uselfutokenuiterableu startlineuindentsu toks_appendutoknumutokvalutok((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyucompats0             uUntokenizer.compatN(u__name__u __module__u __qualname__u__init__uadd_whitespaceu untokenizeucompat(u __locals__((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu Untokenizers   u Untokenizeru%^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)s^[ \t\f]*(?:[#\r\n]|$)cCsd|ddjjdd}|dks=|jdrAdS|d ks\|jdr`dS|S(u(Imitates get_normal_name in tokenizer.c.Ni u_u-uutf-8uutf-8-ulatin-1u iso-8859-1u iso-latin-1ulatin-1-u iso-8859-1-u iso-latin-1-(ulatin-1u iso-8859-1u iso-latin-1(ulatin-1-u iso-8859-1-u iso-latin-1-(ulowerureplaceu startswith(uorig_encuenc((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu_get_normal_names" u_get_normal_namecsd d}d}fdd}fdd}|}|jtrmd |dd}d}n|s}|gfS||}|r||gfStj|s||gfS|}|s||gfS||}|r|||gfS|||gfS( u 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. uutf-8c s+y SWntk r&tSYnXdS(N(u StopIterationubytes((ureadline(u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu read_or_stops  u%detect_encoding..read_or_stopcsy|jd}Wntk r+dSYnXtj|}|sEdSt|jd}yt|}Wn"tk rt d|YnXr|j dkrt dn|d7}n|S(Nuasciiiuunknown encoding: uutf-8uencoding problem: utf-8u-sig( udecodeuUnicodeDecodeErroruNoneu cookie_reumatchu_get_normal_nameugroupulookupu LookupErroru SyntaxErroruname(ulineu line_stringumatchuencodingucodec(u bom_found(u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu find_cookies"    u$detect_encoding..find_cookieiNu utf-8-sigFT(uFalseuNoneu startswithuBOM_UTF8uTrueublank_reumatch(ureadlineuencodingudefaultu read_or_stopu find_cookieufirstusecond((u bom_foundureadlineu;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyudetect_encodings0         udetect_encodingcCst}|j|S(uTransform 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 (u Untokenizeru untokenize(uiterableuut((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyu untokenizeFs ccsd}}}tjdd}}d\}}d}dg} xy |} Wntk rgd} YnX|d}dt| } } |r| std| n|j| }|r |jd} }t|| d|| ||f|| fVd\}}d}q |rt| ddd krt| ddd krtt || | |t| f|fVd}d}q@q || }|| }q@n~|dkr| r| sPnd}xv| | kr)| | d kr|d}n?| | d kr|t dt }n| | dkrd}nP| d} qW| | kr:Pn| | dkr*| | dkr| | dj d}| t|}t ||| f|| t|f| fVt | |d||f|t| f| fVq@t t f| | dk| | d|| f|t| f| fVq@n|| dkrt| j|t| d| |df|| f| fVnx|| dkr|| krtdd|| | fn| dd } td|| f|| f| fVqwWn$| std|dfnd}x#| | kr1tj| | }|r|jd\}}||f||f|}}} | ||| |}}||ks|dkr|dkrt|||| fVq.|dkrt}|dkrt }n||||| fVq.|dkrt |||| fVq.|tkrt|}|j| | }|r|jd} | || }t|||| f| fVq||f} | |d}| }Pq.|tks|ddtks|dd tkra|d!dkrJ||f} t|p&t|dp&t|d}| |dd}}| }Pqt|||| fVq.||krt|||| fVq.|dkrt |||| f| fVd}q.|dkr|d}n|dkr|d}nt|||| fVqt | | || f|| df| fV| d} qWq@x8| ddD]&}td|df|dfdfVqFWtd|df|dfdfVdS("uT 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. iu_u 0123456789uiuEOF in multi-line stringNiu\ iu\ u u u u# u#u u3unindent does not match any outer indentation levelu uEOF in multi-line statementu.u u\u([{u)]}(ui(uiiiiiii(ustringu ascii_lettersuNoneu StopIterationulenu TokenErrorumatchuenduSTRINGu ERRORTOKENutabsizeurstripuCOMMENTuNLuappenduINDENTuIndentationErroruDEDENTu pseudoproguspanuNUMBERuNEWLINEu triple_quoteduendprogsu single_quoteduNAMEuOPu ENDMARKER(ureadlineulnumuparenlevu continuedu namecharsunumcharsucontstruneedcontucontlineuindentsulineuposumaxustrstartuendproguendmatchuenducolumnu comment_tokenunl_posu pseudomatchustartusposueposutokenuinitialunewlineuindent((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyugenerate_tokens[s        2      $#$  - '                 $u__main__(u'''u"""ur'''ur"""uR'''uR"""uu'''uu"""uU'''uU"""ub'''ub"""uB'''uB"""uur'''uur"""uUr'''uUr"""uuR'''uuR"""uUR'''uUR"""ubr'''ubr"""uBr'''uBr"""ubR'''ubR"""uBR'''uBR"""(u'u"ur'ur"uR'uR"uu'uu"uU'uU"ub'ub"uB'uB"uur'uur"uUr'uUr"uuR'uuR"uUR'uUR"ubr'ubr"uBr'uBr"ubR'ubR"uBR'uBR"(Su__doc__u __author__u __credits__ustringureucodecsuBOM_UTF8ulookupulib2to3.pgen2.tokenuutokenudiru__all__ubytesu NameErrorustrugroupuanyumaybeu WhitespaceuCommentuIgnoreuNameu Binnumberu Hexnumberu Octnumberu Decnumberu IntnumberuExponentu PointfloatuExpfloatu Floatnumberu ImagnumberuNumberuSingleuDoubleuSingle3uDouble3uTripleuStringuOperatoruBracketuSpecialuFunnyu PlainTokenuTokenuContStru PseudoExtrasu PseudoTokenulistumapucompileu tokenprogu pseudoprogu single3progu double3proguNoneuendprogsu triple_quotedutu single_quotedutabsizeu Exceptionu TokenErroruStopTokenizingu printtokenutokenizeu tokenize_loopu UntokenizeruASCIIu cookie_reublank_reu_get_normal_nameudetect_encodingu untokenizeugenerate_tokensu__name__usysulenuargvuopenureadlineustdin(((u;/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/tokenize.pyus            *#    8 I