Files
PowerToys/PythonHome/Lib/lib2to3/pgen2/tokenize.pyc

195 lines
16 KiB
Plaintext
Raw Normal View History

2014-07-09 18:15:23 +08:00
<03>
<EFBFBD>W`Sc@s dZdZdZddlZddlZddlmZmZddlTddl m
Z
ge e
<00>D]Z e d d
krge ^qgd d d gZ [
yeWnek
r<>eZnXd<00>Zd<00>Zd<00>ZdZdZeede<17>ee<00>ZdZdZdZdZdZeeeee<00>ZdZedd<00>ee<00>ZdeZeee<00>Z ede d<17>Z!ee!e e<00>Z"dZ#d Z$d!Z%d"Z&ed#d$<00>Z'ed%d&<00>Z(ed'd(d)d*d+d,d-d.d/<00> Z)d0Z*ed1d2<00>Z+ee)e*e+<00>Z,ee"e,e(e<00>Z-ee-Z.ed3ed4d<00>d5ed6d<00><17>Z/edee'<00>Z0eee0e"e,e/e<00>Z1e2ej3e.e1e%e&f<00>\Z4Z5Z6Z7i&ej3e#<00>d46ej3e$<00>d66e6d76e7d86e6d96e7d:6e6d;6e7d<6e6d=6e7d>6e6d?6e7d@6e6dA6e7dB6e6dC6e7dD6e6dE6e7dF6e6dG6e7dH6e6dI6e7dJ6e6dK6e7dL6e6dM6e7dN6e6dO6e7dP6e6dQ6e7dR6e6dS6e7dT6ddU6ddV6ddW6ddX6ddY6ddZ6Z9iZ:xd<>D]Z;e;e:e;<q<>WiZ<xd<>D]Z;e;e<e;<qWdwZ=dxe>fdy<00><00>YZ?dze>fd{<00><00>YZ@d|<00>ZAeAd}<00>ZBd~<00>ZCdd<>d<><00><00>YZDej3d<><00>ZEd<><00>ZFd<><00>ZGd<><00>ZHd<><00>ZIeJd<>krddlKZKeLeKjM<00>dkr<>eBeNeKjMd<19>jO<00>qeBeKjPjO<00>ndS(<28>s<>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 <ping@lfw.org>s@GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaroi<6F><69><EFBFBD><EFBFBD>N(tBOM_UTF8tlookup(t*i(ttokenit_ttokenizetgenerate_tokenst
untokenizecGsddj|<00>dS(Nt(t|t)(tjoin(tchoices((s.\Lib\lib2to3\pgen2\tokenize.pytgroup0scGst|<00>dS(NR(R (R ((s.\Lib\lib2to3\pgen2\tokenize.pytany1scGst|<00>dS(Nt?(R (R ((s.\Lib\lib2to3\pgen2\tokenize.pytmaybe2ss[ \f\t]*s #[^\r\n]*s\\\r?\ns [a-zA-Z_]\w*s
0[bB][01]*s0[xX][\da-fA-F]*[lL]?s0[oO]?[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[ubUB]?[rR]?'''s[ubUB]?[rR]?"""s&[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'s&[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"s\*\*=?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'''s"""sr'''sr"""su'''su"""sb'''sb"""sur'''sur"""sbr'''sbr"""sR'''sR"""sU'''sU"""sB'''sB"""suR'''suR"""sUr'''sUr"""sUR'''sUR"""sbR'''sbR"""sBr'''sBr"""sBR'''sBR"""trtRtutUtbtBsr'sr"sR'sR"su'su"sU'sU"sb'sb"sB'sB"sur'sur"sUr'sUr"suR'suR"sUR'sUR"sbr'sbr"sBr'sBr"sbR'sbR"sBR'sBR"it
TokenErrorcBseZRS((t__name__t
__module__(((s.\Lib\lib2to3\pgen2\tokenize.pyR<00>stStopTokenizingcBseZRS((RR(((s.\Lib\lib2to3\pgen2\tokenize.pyR<00>sc CsA|\}}|\}}d||||t|t|<00>fGHdS(Ns%d,%d-%d,%d: %s %s(ttok_nametrepr( ttypeRtstarttendtlinetsrowtscolterowtecol((s.\Lib\lib2to3\pgen2\tokenize.pyt
printtoken<65>s  cCs)yt||<00>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.\Lib\lib2to3\pgen2\tokenize.pyR<00>s  cCs%xt|<00>D]}||<00>q WdS(N(R(R*R+t
token_info((s.\Lib\lib2to3\pgen2\tokenize.pyR)<00>st UntokenizercBs,eZd<00>Zd<00>Zd<00>Zd<00>ZRS(cCsg|_d|_d|_dS(Nii(ttokenstprev_rowtprev_col(tself((s.\Lib\lib2to3\pgen2\tokenize.pyt__init__<5F>s  cCsO|\}}||jks!t<00>||j}|rK|jjd|<14>ndS(Nt (R/tAssertionErrorR0R.tappend(R1R!trowtcolt
col_offset((s.\Lib\lib2to3\pgen2\tokenize.pytadd_whitespace<63>s
  cCs<>x<>|D]<5D>}t|<00>dkr3|j||<00>Pn|\}}}}}|j|<00>|jj|<00>|\|_|_|ttfkr|jd7_d|_qqWdj |j<00>S(Niiit(
tlentcompatR9R.R5R/R0tNEWLINEtNLR (R1titerablettttok_typeRR!R"R#((s.\Lib\lib2to3\pgen2\tokenize.pyR<00>s  c Cs%t}g}|jj}|\}}|ttfkrC|d7}n|ttfkr^t}nx<>|D]<5D>}|d \}}|ttfkr<>|d7}n|tkr<>|j|<00>qenZ|t kr<>|j
<00>qen>|ttfkr<>t}n#|r|r||d<19>t}n||<00>qeWdS(NR3ii<><69><EFBFBD><EFBFBD>( tFalseR.R5tNAMEtNUMBERR=R>tTruetINDENTtDEDENTtpop( R1RR?t startlinetindentst toks_appendttoknumttokvalttok((s.\Lib\lib2to3\pgen2\tokenize.pyR<<00>s0         
   (RRR2R9RR<(((s.\Lib\lib2to3\pgen2\tokenize.pyR-<00>s   s%^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)cCs^|d j<00>jdd<00>}|dks7|jd<00>r;dS|d ksV|jd <00>rZdS|S(s(Imitates get_normal_name in tokenizer.c.i Rt-sutf-8sutf-8-slatin-1s
iso-8859-1s iso-latin-1slatin-1-s iso-8859-1-s iso-latin-1-(slatin-1s
iso-8859-1s iso-latin-1(slatin-1-s iso-8859-1-s iso-latin-1-(tlowertreplacet
startswith(torig_enctenc((s.\Lib\lib2to3\pgen2\tokenize.pyt_get_normal_name<6D>s cs<>t<00>d}d}<00>fd<00>}<00>fd<00>}|<00>}|jt<00>rat<00>|d}d}n|sq|gfS||<00>}|r<>||gfS|<00>}|s<>||gfS||<00>}|r<>|||gfS|||gfS(s
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.
sutf-8cs'y <00><00>SWntk
r"t<00>SXdS(N(t StopIterationtbytes((R*(s.\Lib\lib2to3\pgen2\tokenize.pyt read_or_stops  cs<>y|jd<00>}Wntk
r'dSXtj|<00>}|sAdSt|jd<00><00>}yt|<00>}Wn!tk
r<>t d|<17><00>nX<>r<>|j
dkr<>t d<00><00>n|d7}n|S(Ntasciiisunknown encoding: sutf-8sencoding problem: utf-8s-sig( tdecodetUnicodeDecodeErrortNonet cookie_retmatchRUR Rt LookupErrort SyntaxErrortname(R#t line_stringR^tencodingtcodec(t bom_found(s.\Lib\lib2to3\pgen2\tokenize.pyt find_cookies"   is utf-8-sigN(RBR\RRRRE(R*RctdefaultRXRftfirsttsecond((ReR*s.\Lib\lib2to3\pgen2\tokenize.pytdetect_encoding<6E>s, 
 
     cCst<00>}|j|<00>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. 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
(R-R(R?tut((s.\Lib\lib2to3\pgen2\tokenize.pyRCs ccsUd}}}tjdd}}d\}}d}dg} x<>y |<00>}
Wntk
rfd}
nX|d}dt|
<00>} } |r{|
s<>td| f<00>n|j|
<00>}|r|jd<00>} }t||
| | ||f||
fVd\}}d}q<>|ra|
ddkra|
d d
krat ||
| |t|
<00>f|fVd}d}q@q<>||
}||
}q@n`|dkr<>| r<>|
s<>Pnd}xv| | kr|
| d kr<>|d}n?|
| d kr<>|t
dt
}n|
| d krd}nP| d} q<>W| | kr'Pn|
| dkr|
| dkr<>|
| j d<00>}| t|<00>}t ||| f|| t|<00>f|
fVt |
|||f|t|
<00>f|
fVq@t t f|
| dk|
| || f|t|
<00>f|
fVq@n|| dkrI| j|<00>t|
| |df|| f|
fVnx<>|| dkr<>|| kr<>tdd|| |
f<00><00>n| d } td|| f|| f|
fVqLWn$|
s<>td|dff<00>nd}x| | kr<>tj|
| <00>}|r<>|jd<00>\}}||f||f|}}} |
||!|
|}}||kss|dkr<>|dkr<>t||||
fVq<>|dkr<>t}|dkr<>t }n|||||
fVq<>|dkr|jd<00> s<>t<00>t ||||
fVq<>|tkr<>t|}|j|
| <00>}|rh|jd<00>} |
|| !}t|||| f|
fVq<>||f} |
|}|
}Pq<50>|tks<>|d tks<>|d tkr(|ddkr||f} t|p<>t|dp<>t|d}|
|d}}|
}Pq<50>t||||
fVq<>||krKt||||
fVq<>|dkrzt |||| f|
fVd}q<>|dkr<>|d}n|dkr<>|d}nt||||
fVq<>t |
| || f|| df|
fV| d} q<>Wq@x2| 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
0123456789R:isEOF in multi-line stringi<67><69><EFBFBD><EFBFBD>s\
i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>s\
R3s s s#
t#s
i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>s3unindent does not match any outer indentation levels
<tokenize>sEOF in multi-line statementt.s
iis\s([{s)]}N(R:i(R:i(tstringt ascii_lettersR\RVR;RR^R"tSTRINGt
ERRORTOKENttabsizetrstriptCOMMENTR>R5RFtIndentationErrorRGt
pseudoprogtspanRDR=tendswithR4t triple_quotedtendprogst single_quotedRCtOPt ENDMARKER(R*tlnumtparenlevt continuedt namecharstnumcharstcontstrtneedconttcontlineRJR#tpostmaxtstrstarttendprogtendmatchR"tcolumnt comment_tokentnl_post pseudomatchR!tsposteposRtinitialtnewlinetindent((s.\Lib\lib2to3\pgen2\tokenize.pyRXs<>    

  &


   $
#  ' 
'       
  
       
$t__main__(s'''s"""sr'''sr"""sR'''sR"""su'''su"""sU'''sU"""sb'''sb"""sB'''sB"""sur'''sur"""sUr'''sUr"""suR'''suR"""sUR'''sUR"""sbr'''sbr"""sBr'''sBr"""sbR'''sbR"""sBR'''sBR"""(RRsr'sr"sR'sR"su'su"sU'sU"sb'sb"sB'sB"sur'sur"sUr'sUr"suR'suR"sUR'sUR"sbr'sbr"sBr'sBr"sbR'sbR"sBR'sBR"((Qt__doc__t
__author__t __credits__RotretcodecsRRtlib2to3.pgen2.tokenR:Rtdirtxt__all__RWt NameErrortstrR RRt
WhitespacetCommenttIgnoretNamet Binnumbert Hexnumbert Octnumbert Decnumbert IntnumbertExponentt
PointfloattExpfloatt Floatnumbert
ImagnumbertNumbertSingletDoubletSingle3tDouble3tTripletStringtOperatortBrackettSpecialtFunnyt
PlainTokentTokentContStrt PseudoExtrast PseudoTokentmaptcompilet tokenprogRwt single3progt double3progR\R{RzR@R|Rst ExceptionRRR(RR)R-R]RURjRRRtsysR;targvtopenR*tstdin(((s.\Lib\lib2to3\pgen2\tokenize.pyt<module>s<>
/  
   
  
 '#

   8 G  <09>