a
    äze%ÿ  ã                   @   sN  d dl mZ d dlmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZmZ d dlZd dlmZmZ d dlmZmZ d dlZd dlZdd„ ZG d	d
„ d
eƒZG dd„ deƒZdd„ Z G dd„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&G dd„ deƒZ'e(dkrJe )¡  dS )é    )Úsupport)ÚtokenizeÚ	_tokenizeÚ
untokenizeÚNUMBERÚNAMEÚOPÚSTRINGÚ	ENDMARKERÚENCODINGÚtok_nameÚdetect_encodingÚopenÚUntokenizerÚgenerate_tokensÚNEWLINE)ÚBytesIOÚStringION)ÚTestCaseÚmock)ÚVALID_UNDERSCORE_LITERALSÚINVALID_UNDERSCORE_LITERALSc           
      C   sˆ   g }t | ¡ ƒ}|d dv}| D ]b\}}}}}	|tkr: q„|rT|tkrT|d |krTq t| }| d|d›d|d›d|› d|› ¡ q |S )Néÿÿÿÿz
r   ú    Z10ú Z13)ÚlenÚ
splitlinesr
   r   r   Úappend)
Ztoken_generatorZsource_stringÚresultZ	num_linesZmissing_trailing_nlÚtypeÚtokenÚstartÚendÚline© r$   ú(/usr/lib/python3.9/test/test_tokenize.pyÚstringify_tokens_from_source   s    (r&   c                   @   s¬   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)S )*ÚTokenizeTestc                 C   s<   t | d¡ƒ}tt|jƒ|ƒ}|  |dg| ¡  ¡  ¡ d S )Núutf-8z*    ENCODING   'utf-8'       (0, 0) (0, 0))r   Úencoder&   r   ÚreadlineÚassertEqualÚrstripr   ©ÚselfÚsÚexpectedÚfr   r$   r$   r%   Úcheck_tokenize*   s    
ÿÿzTokenizeTest.check_tokenizec                 C   sD   t d d¡ƒ}tt|jƒƒ}|  |d jt¡ |  |d jt¡ d S )NÚxr(   éþÿÿÿr   )	r   r)   Úlistr   r*   r+   r   r   r
   )r.   r1   Útokensr$   r$   r%   Útest_implicit_newline4   s    z"TokenizeTest.test_implicit_newlinec                 C   sd   |   dd¡ |   dd¡ d}t|ƒj}|  td¡ t|ƒD ]}q<W d   ƒ n1 sV0    Y  d S )Nz1 + 1z…    NUMBER     '1'           (1, 0) (1, 1)
    OP         '+'           (1, 2) (1, 3)
    NUMBER     '1'           (1, 4) (1, 5)
    z3if False:
    # NL
    
    True = False # NEWLINE
af      NAME       'if'          (1, 0) (1, 2)
    NAME       'False'       (1, 3) (1, 8)
    OP         ':'           (1, 8) (1, 9)
    NEWLINE    '\n'          (1, 9) (1, 10)
    COMMENT    '# NL'        (2, 4) (2, 8)
    NL         '\n'          (2, 8) (2, 9)
    NL         '\n'          (3, 4) (3, 5)
    INDENT     '    '        (4, 0) (4, 4)
    NAME       'True'        (4, 4) (4, 8)
    OP         '='           (4, 9) (4, 10)
    NAME       'False'       (4, 11) (4, 16)
    COMMENT    '# NEWLINE'   (4, 17) (4, 26)
    NEWLINE    '\n'          (4, 26) (4, 27)
    DEDENT     ''            (5, 0) (5, 0)
    s   def k(x):
    x += 2
  x += 5
z3unindent does not match any outer indentation level)r2   r   r*   ÚassertRaisesRegexÚIndentationErrorr   )r.   Zindent_error_filer*   Útokr$   r$   r%   Ú
test_basic<   s    ý
ÿzTokenizeTest.test_basicc                 C   sp   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ d S )Nz0xff <= 255z†    NUMBER     '0xff'        (1, 0) (1, 4)
    OP         '<='          (1, 5) (1, 7)
    NUMBER     '255'         (1, 8) (1, 11)
    z0b10 <= 255z†    NUMBER     '0b10'        (1, 0) (1, 4)
    OP         '<='          (1, 5) (1, 7)
    NUMBER     '255'         (1, 8) (1, 11)
    z0o123 <= 0O123z†    NUMBER     '0o123'       (1, 0) (1, 5)
    OP         '<='          (1, 6) (1, 8)
    NUMBER     '0O123'       (1, 9) (1, 14)
    z1234567 > ~0x15z´    NUMBER     '1234567'     (1, 0) (1, 7)
    OP         '>'           (1, 8) (1, 9)
    OP         '~'           (1, 10) (1, 11)
    NUMBER     '0x15'        (1, 11) (1, 15)
    z2134568 != 1231515zˆ    NUMBER     '2134568'     (1, 0) (1, 7)
    OP         '!='          (1, 8) (1, 10)
    NUMBER     '1231515'     (1, 11) (1, 18)
    z(-124561-1) & 200000000ac      OP         '('           (1, 0) (1, 1)
    OP         '-'           (1, 1) (1, 2)
    NUMBER     '124561'      (1, 2) (1, 8)
    OP         '-'           (1, 8) (1, 9)
    NUMBER     '1'           (1, 9) (1, 10)
    OP         ')'           (1, 10) (1, 11)
    OP         '&'           (1, 12) (1, 13)
    NUMBER     '200000000'   (1, 14) (1, 23)
    z0xdeadbeef != -1z·    NUMBER     '0xdeadbeef'  (1, 0) (1, 10)
    OP         '!='          (1, 11) (1, 13)
    OP         '-'           (1, 14) (1, 15)
    NUMBER     '1'           (1, 15) (1, 16)
    z0xdeadc0de & 12345zŠ    NUMBER     '0xdeadc0de'  (1, 0) (1, 10)
    OP         '&'           (1, 11) (1, 12)
    NUMBER     '12345'       (1, 13) (1, 18)
    z0xFF & 0x15 | 1234zà    NUMBER     '0xFF'        (1, 0) (1, 4)
    OP         '&'           (1, 5) (1, 6)
    NUMBER     '0x15'        (1, 7) (1, 11)
    OP         '|'           (1, 12) (1, 13)
    NUMBER     '1234'        (1, 14) (1, 18)
    ©r2   ©r.   r$   r$   r%   Útest_inta   s    
zTokenizeTest.test_intc                 C   s4   |   dd¡ |   dd¡ |   dd¡ |   dd¡ d S )	Nzx = 0z…    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '0'           (1, 4) (1, 5)
    zx = 0xfffffffffffzˆ    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '0xfffffffffff' (1, 4) (1, 17)
    zx = 123141242151251616110z    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '123141242151251616110' (1, 4) (1, 25)
    zx = -15921590215012591z·    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    OP         '-'           (1, 4) (1, 5)
    NUMBER     '15921590215012591' (1, 5) (1, 22)
    r<   r=   r$   r$   r%   Ú	test_longš   s    zTokenizeTest.test_longc                 C   sX   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ d S )Nzx = 3.14159z†    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '3.14159'     (1, 4) (1, 11)
    zx = 314159.z†    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '314159.'     (1, 4) (1, 11)
    zx = .314159z†    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '.314159'     (1, 4) (1, 11)
    zx = 3e14159z†    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '3e14159'     (1, 4) (1, 11)
    z	x = 3E123z…    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '3E123'       (1, 4) (1, 9)
    zx+y = 3e-1230zÜ    NAME       'x'           (1, 0) (1, 1)
    OP         '+'           (1, 1) (1, 2)
    NAME       'y'           (1, 2) (1, 3)
    OP         '='           (1, 4) (1, 5)
    NUMBER     '3e-1230'     (1, 6) (1, 13)
    zx = 3.14e159z†    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '3.14e159'    (1, 4) (1, 12)
    r<   r=   r$   r$   r%   Ú
test_float²   s    zTokenizeTest.test_floatc                 C   sJ   dd„ }t D ]}d|v rq|  ||ƒ|¡ qtD ]}|  ||ƒ|¡ q0d S )Nc                 S   s<   t |  d¡ƒ}t|jƒD ]\}}}}}|tkr|  S qdS )Nr(   zinvalid token)r   r)   r   r*   r   )r/   r1   Ztoktyper    r!   r"   r#   r$   r$   r%   Únumber_tokenÛ   s
    
z;TokenizeTest.test_underscore_literals.<locals>.number_tokenú()r   r+   r   ZassertNotEqual)r.   rA   Zlitr$   r$   r%   Útest_underscore_literalsÚ   s    z%TokenizeTest.test_underscore_literalsc                 C   s<  |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd ¡ |   d!d"¡ |   d#d$¡ |   d%d&¡ |   d'd(¡ |   d)d*¡ |   d+d,¡ |   d-d.¡ |   d/d0¡ |   d1d2¡ |   d3d4¡ d S )5Nzx = ''; y = ""a5      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     "''"          (1, 4) (1, 6)
    OP         ';'           (1, 6) (1, 7)
    NAME       'y'           (1, 8) (1, 9)
    OP         '='           (1, 10) (1, 11)
    STRING     '""'          (1, 12) (1, 14)
    zx = '"'; y = "'"a6      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     '\'"\''       (1, 4) (1, 7)
    OP         ';'           (1, 7) (1, 8)
    NAME       'y'           (1, 9) (1, 10)
    OP         '='           (1, 11) (1, 12)
    STRING     '"\'"'        (1, 13) (1, 16)
    zx = "doesn't "shrink", does it"zà    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     '"doesn\'t "' (1, 4) (1, 14)
    NAME       'shrink'      (1, 14) (1, 20)
    STRING     '", does it"' (1, 20) (1, 31)
    zx = 'abc' + 'ABC'zß    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     "'abc'"       (1, 4) (1, 9)
    OP         '+'           (1, 10) (1, 11)
    STRING     "'ABC'"       (1, 12) (1, 17)
    zy = "ABC" + "ABC"zß    NAME       'y'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     '"ABC"'       (1, 4) (1, 9)
    OP         '+'           (1, 10) (1, 11)
    STRING     '"ABC"'       (1, 12) (1, 17)
    z%x = r'abc' + r'ABC' + R'ABC' + R'ABC'a”      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     "r'abc'"      (1, 4) (1, 10)
    OP         '+'           (1, 11) (1, 12)
    STRING     "r'ABC'"      (1, 13) (1, 19)
    OP         '+'           (1, 20) (1, 21)
    STRING     "R'ABC'"      (1, 22) (1, 28)
    OP         '+'           (1, 29) (1, 30)
    STRING     "R'ABC'"      (1, 31) (1, 37)
    z%y = r"abc" + r"ABC" + R"ABC" + R"ABC"a”      NAME       'y'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    STRING     'r"abc"'      (1, 4) (1, 10)
    OP         '+'           (1, 11) (1, 12)
    STRING     'r"ABC"'      (1, 13) (1, 19)
    OP         '+'           (1, 20) (1, 21)
    STRING     'R"ABC"'      (1, 22) (1, 28)
    OP         '+'           (1, 29) (1, 30)
    STRING     'R"ABC"'      (1, 31) (1, 37)
    zu'abc' + U'abc'z†    STRING     "u'abc'"      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     "U'abc'"      (1, 9) (1, 15)
    zu"abc" + U"abc"z†    STRING     'u"abc"'      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     'U"abc"'      (1, 9) (1, 15)
    zb'abc' + B'abc'z†    STRING     "b'abc'"      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     "B'abc'"      (1, 9) (1, 15)
    zb"abc" + B"abc"z†    STRING     'b"abc"'      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     'B"abc"'      (1, 9) (1, 15)
    z%br'abc' + bR'abc' + Br'abc' + BR'abc'a;      STRING     "br'abc'"     (1, 0) (1, 7)
    OP         '+'           (1, 8) (1, 9)
    STRING     "bR'abc'"     (1, 10) (1, 17)
    OP         '+'           (1, 18) (1, 19)
    STRING     "Br'abc'"     (1, 20) (1, 27)
    OP         '+'           (1, 28) (1, 29)
    STRING     "BR'abc'"     (1, 30) (1, 37)
    z%br"abc" + bR"abc" + Br"abc" + BR"abc"a;      STRING     'br"abc"'     (1, 0) (1, 7)
    OP         '+'           (1, 8) (1, 9)
    STRING     'bR"abc"'     (1, 10) (1, 17)
    OP         '+'           (1, 18) (1, 19)
    STRING     'Br"abc"'     (1, 20) (1, 27)
    OP         '+'           (1, 28) (1, 29)
    STRING     'BR"abc"'     (1, 30) (1, 37)
    z%rb'abc' + rB'abc' + Rb'abc' + RB'abc'a;      STRING     "rb'abc'"     (1, 0) (1, 7)
    OP         '+'           (1, 8) (1, 9)
    STRING     "rB'abc'"     (1, 10) (1, 17)
    OP         '+'           (1, 18) (1, 19)
    STRING     "Rb'abc'"     (1, 20) (1, 27)
    OP         '+'           (1, 28) (1, 29)
    STRING     "RB'abc'"     (1, 30) (1, 37)
    z%rb"abc" + rB"abc" + Rb"abc" + RB"abc"a;      STRING     'rb"abc"'     (1, 0) (1, 7)
    OP         '+'           (1, 8) (1, 9)
    STRING     'rB"abc"'     (1, 10) (1, 17)
    OP         '+'           (1, 18) (1, 19)
    STRING     'Rb"abc"'     (1, 20) (1, 27)
    OP         '+'           (1, 28) (1, 29)
    STRING     'RB"abc"'     (1, 30) (1, 37)
    z"a\
de\
fg"z3    STRING     '"a\\\nde\\\nfg"' (1, 0) (3, 3)
    zu"a\
de"z/    STRING     'u"a\\\nde"'  (1, 0) (2, 3)
    zrb"a\
d"z/    STRING     'rb"a\\\nd"'  (1, 0) (2, 2)
    z
"""a\
b"""z0    STRING     '"""a\\\nb"""' (1, 0) (2, 4)
    zu"""a\
b"""z1    STRING     'u"""a\\\nb"""' (1, 0) (2, 4)
    zrb"""a\
b\
c"""z7    STRING     'rb"""a\\\nb\\\nc"""' (1, 0) (3, 4)
    zf"abc"z/    STRING     'f"abc"'      (1, 0) (1, 6)
    z	fR"a{b}c"z/    STRING     'fR"a{b}c"'   (1, 0) (1, 9)
    z
f"""abc"""z0    STRING     'f"""abc"""'  (1, 0) (1, 10)
    zf"abc\
def"z1    STRING     'f"abc\\\ndef"' (1, 0) (2, 4)
    zRf"abc\
def"z2    STRING     'Rf"abc\\\ndef"' (1, 0) (2, 4)
    r<   r=   r$   r$   r%   Útest_stringé   sT    					
þÿÿÿÿþÿÿzTokenizeTest.test_stringc                 C   s(   |   dd¡ |   dd¡ |   dd¡ d S )Nz!def d22(a, b, c=2, d=2, *k): passa      NAME       'def'         (1, 0) (1, 3)
    NAME       'd22'         (1, 4) (1, 7)
    OP         '('           (1, 7) (1, 8)
    NAME       'a'           (1, 8) (1, 9)
    OP         ','           (1, 9) (1, 10)
    NAME       'b'           (1, 11) (1, 12)
    OP         ','           (1, 12) (1, 13)
    NAME       'c'           (1, 14) (1, 15)
    OP         '='           (1, 15) (1, 16)
    NUMBER     '2'           (1, 16) (1, 17)
    OP         ','           (1, 17) (1, 18)
    NAME       'd'           (1, 19) (1, 20)
    OP         '='           (1, 20) (1, 21)
    NUMBER     '2'           (1, 21) (1, 22)
    OP         ','           (1, 22) (1, 23)
    OP         '*'           (1, 24) (1, 25)
    NAME       'k'           (1, 25) (1, 26)
    OP         ')'           (1, 26) (1, 27)
    OP         ':'           (1, 27) (1, 28)
    NAME       'pass'        (1, 29) (1, 33)
    zdef d01v_(a=1, *k, **w): passa¢      NAME       'def'         (1, 0) (1, 3)
    NAME       'd01v_'       (1, 4) (1, 9)
    OP         '('           (1, 9) (1, 10)
    NAME       'a'           (1, 10) (1, 11)
    OP         '='           (1, 11) (1, 12)
    NUMBER     '1'           (1, 12) (1, 13)
    OP         ','           (1, 13) (1, 14)
    OP         '*'           (1, 15) (1, 16)
    NAME       'k'           (1, 16) (1, 17)
    OP         ','           (1, 17) (1, 18)
    OP         '**'          (1, 19) (1, 21)
    NAME       'w'           (1, 21) (1, 22)
    OP         ')'           (1, 22) (1, 23)
    OP         ':'           (1, 23) (1, 24)
    NAME       'pass'        (1, 25) (1, 29)
    z&def d23(a: str, b: int=3) -> int: passaø      NAME       'def'         (1, 0) (1, 3)
    NAME       'd23'         (1, 4) (1, 7)
    OP         '('           (1, 7) (1, 8)
    NAME       'a'           (1, 8) (1, 9)
    OP         ':'           (1, 9) (1, 10)
    NAME       'str'         (1, 11) (1, 14)
    OP         ','           (1, 14) (1, 15)
    NAME       'b'           (1, 16) (1, 17)
    OP         ':'           (1, 17) (1, 18)
    NAME       'int'         (1, 19) (1, 22)
    OP         '='           (1, 22) (1, 23)
    NUMBER     '3'           (1, 23) (1, 24)
    OP         ')'           (1, 24) (1, 25)
    OP         '->'          (1, 26) (1, 28)
    NAME       'int'         (1, 29) (1, 32)
    OP         ':'           (1, 32) (1, 33)
    NAME       'pass'        (1, 34) (1, 38)
    r<   r=   r$   r$   r%   Útest_function  s    zTokenizeTest.test_functionc                 C   s   |   dd¡ d S )NzXif 1 < 1 > 1 == 1 >= 5 <= 0x15 <= 0x12 != 1 and 5 in 1 not in 1 is 1 or 5 is not 1: passa›      NAME       'if'          (1, 0) (1, 2)
    NUMBER     '1'           (1, 3) (1, 4)
    OP         '<'           (1, 5) (1, 6)
    NUMBER     '1'           (1, 7) (1, 8)
    OP         '>'           (1, 9) (1, 10)
    NUMBER     '1'           (1, 11) (1, 12)
    OP         '=='          (1, 13) (1, 15)
    NUMBER     '1'           (1, 16) (1, 17)
    OP         '>='          (1, 18) (1, 20)
    NUMBER     '5'           (1, 21) (1, 22)
    OP         '<='          (1, 23) (1, 25)
    NUMBER     '0x15'        (1, 26) (1, 30)
    OP         '<='          (1, 31) (1, 33)
    NUMBER     '0x12'        (1, 34) (1, 38)
    OP         '!='          (1, 39) (1, 41)
    NUMBER     '1'           (1, 42) (1, 43)
    NAME       'and'         (1, 44) (1, 47)
    NUMBER     '5'           (1, 48) (1, 49)
    NAME       'in'          (1, 50) (1, 52)
    NUMBER     '1'           (1, 53) (1, 54)
    NAME       'not'         (1, 55) (1, 58)
    NAME       'in'          (1, 59) (1, 61)
    NUMBER     '1'           (1, 62) (1, 63)
    NAME       'is'          (1, 64) (1, 66)
    NUMBER     '1'           (1, 67) (1, 68)
    NAME       'or'          (1, 69) (1, 71)
    NUMBER     '5'           (1, 72) (1, 73)
    NAME       'is'          (1, 74) (1, 76)
    NAME       'not'         (1, 77) (1, 80)
    NUMBER     '1'           (1, 81) (1, 82)
    OP         ':'           (1, 82) (1, 83)
    NAME       'pass'        (1, 84) (1, 88)
    r<   r=   r$   r$   r%   Útest_comparisonË  s    ÿzTokenizeTest.test_comparisonc                 C   s   |   dd¡ d S )Nzx = 1 << 1 >> 5a6      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '1'           (1, 4) (1, 5)
    OP         '<<'          (1, 6) (1, 8)
    NUMBER     '1'           (1, 9) (1, 10)
    OP         '>>'          (1, 11) (1, 13)
    NUMBER     '5'           (1, 14) (1, 15)
    r<   r=   r$   r$   r%   Ú
test_shiftñ  s    zTokenizeTest.test_shiftc                 C   s   |   dd¡ d S )Nz%x = 1 - y + 15 - 1 + 0x124 + z + a[5]a$      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '1'           (1, 4) (1, 5)
    OP         '-'           (1, 6) (1, 7)
    NAME       'y'           (1, 8) (1, 9)
    OP         '+'           (1, 10) (1, 11)
    NUMBER     '15'          (1, 12) (1, 14)
    OP         '-'           (1, 15) (1, 16)
    NUMBER     '1'           (1, 17) (1, 18)
    OP         '+'           (1, 19) (1, 20)
    NUMBER     '0x124'       (1, 21) (1, 26)
    OP         '+'           (1, 27) (1, 28)
    NAME       'z'           (1, 29) (1, 30)
    OP         '+'           (1, 31) (1, 32)
    NAME       'a'           (1, 33) (1, 34)
    OP         '['           (1, 34) (1, 35)
    NUMBER     '5'           (1, 35) (1, 36)
    OP         ']'           (1, 36) (1, 37)
    r<   r=   r$   r$   r%   Útest_additiveý  s    zTokenizeTest.test_additivec                 C   s   |   dd¡ d S )Nzx = 1//1*1/5*12%0x12@42aš      NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '1'           (1, 4) (1, 5)
    OP         '//'          (1, 5) (1, 7)
    NUMBER     '1'           (1, 7) (1, 8)
    OP         '*'           (1, 8) (1, 9)
    NUMBER     '1'           (1, 9) (1, 10)
    OP         '/'           (1, 10) (1, 11)
    NUMBER     '5'           (1, 11) (1, 12)
    OP         '*'           (1, 12) (1, 13)
    NUMBER     '12'          (1, 13) (1, 15)
    OP         '%'           (1, 15) (1, 16)
    NUMBER     '0x12'        (1, 16) (1, 20)
    OP         '@'           (1, 20) (1, 21)
    NUMBER     '42'          (1, 21) (1, 23)
    r<   r=   r$   r$   r%   Útest_multiplicative  s    z TokenizeTest.test_multiplicativec                 C   s   |   dd¡ |   dd¡ d S )Nz~1 ^ 1 & 1 |1 ^ -1aè      OP         '~'           (1, 0) (1, 1)
    NUMBER     '1'           (1, 1) (1, 2)
    OP         '^'           (1, 3) (1, 4)
    NUMBER     '1'           (1, 5) (1, 6)
    OP         '&'           (1, 7) (1, 8)
    NUMBER     '1'           (1, 9) (1, 10)
    OP         '|'           (1, 11) (1, 12)
    NUMBER     '1'           (1, 12) (1, 13)
    OP         '^'           (1, 14) (1, 15)
    OP         '-'           (1, 16) (1, 17)
    NUMBER     '1'           (1, 17) (1, 18)
    z-1*1/1+1*1//1 - ---1**1aH      OP         '-'           (1, 0) (1, 1)
    NUMBER     '1'           (1, 1) (1, 2)
    OP         '*'           (1, 2) (1, 3)
    NUMBER     '1'           (1, 3) (1, 4)
    OP         '/'           (1, 4) (1, 5)
    NUMBER     '1'           (1, 5) (1, 6)
    OP         '+'           (1, 6) (1, 7)
    NUMBER     '1'           (1, 7) (1, 8)
    OP         '*'           (1, 8) (1, 9)
    NUMBER     '1'           (1, 9) (1, 10)
    OP         '//'          (1, 10) (1, 12)
    NUMBER     '1'           (1, 12) (1, 13)
    OP         '-'           (1, 14) (1, 15)
    OP         '-'           (1, 16) (1, 17)
    OP         '-'           (1, 17) (1, 18)
    OP         '-'           (1, 18) (1, 19)
    NUMBER     '1'           (1, 19) (1, 20)
    OP         '**'          (1, 20) (1, 22)
    NUMBER     '1'           (1, 22) (1, 23)
    r<   r=   r$   r$   r%   Ú
test_unary(  s    zTokenizeTest.test_unaryc                 C   s   |   dd¡ d S )Nz/import sys, time
x = sys.modules['time'].time()aõ      NAME       'import'      (1, 0) (1, 6)
    NAME       'sys'         (1, 7) (1, 10)
    OP         ','           (1, 10) (1, 11)
    NAME       'time'        (1, 12) (1, 16)
    NEWLINE    '\n'          (1, 16) (1, 17)
    NAME       'x'           (2, 0) (2, 1)
    OP         '='           (2, 2) (2, 3)
    NAME       'sys'         (2, 4) (2, 7)
    OP         '.'           (2, 7) (2, 8)
    NAME       'modules'     (2, 8) (2, 15)
    OP         '['           (2, 15) (2, 16)
    STRING     "'time'"      (2, 16) (2, 22)
    OP         ']'           (2, 22) (2, 23)
    OP         '.'           (2, 23) (2, 24)
    NAME       'time'        (2, 24) (2, 28)
    OP         '('           (2, 28) (2, 29)
    OP         ')'           (2, 29) (2, 30)
    r<   r=   r$   r$   r%   Útest_selectorM  s    zTokenizeTest.test_selectorc                 C   s   |   dd¡ d S )Nz @staticmethod
def foo(x,y): passa      OP         '@'           (1, 0) (1, 1)
    NAME       'staticmethod' (1, 1) (1, 13)
    NEWLINE    '\n'          (1, 13) (1, 14)
    NAME       'def'         (2, 0) (2, 3)
    NAME       'foo'         (2, 4) (2, 7)
    OP         '('           (2, 7) (2, 8)
    NAME       'x'           (2, 8) (2, 9)
    OP         ','           (2, 9) (2, 10)
    NAME       'y'           (2, 10) (2, 11)
    OP         ')'           (2, 11) (2, 12)
    OP         ':'           (2, 12) (2, 13)
    NAME       'pass'        (2, 14) (2, 18)
    r<   r=   r$   r$   r%   Útest_methodc  s    zTokenizeTest.test_methodc                 C   s   |   dd¡ d S )Nzdef f():
	if x
        	passa_      NAME       'def'         (1, 0) (1, 3)
    NAME       'f'           (1, 4) (1, 5)
    OP         '('           (1, 5) (1, 6)
    OP         ')'           (1, 6) (1, 7)
    OP         ':'           (1, 7) (1, 8)
    NEWLINE    '\n'          (1, 8) (1, 9)
    INDENT     '\t'          (2, 0) (2, 1)
    NAME       'if'          (2, 1) (2, 3)
    NAME       'x'           (2, 4) (2, 5)
    NEWLINE    '\n'          (2, 5) (2, 6)
    INDENT     '        \t'  (3, 0) (3, 9)
    NAME       'pass'        (3, 9) (3, 13)
    DEDENT     ''            (4, 0) (4, 0)
    DEDENT     ''            (4, 0) (4, 0)
    r<   r=   r$   r$   r%   Ú	test_tabst  s    þzTokenizeTest.test_tabsc                 C   s   |   dd¡ d S )Nu!   Ã–rter = 'places'
grÃ¼n = 'green'u7      NAME       'Ã–rter'       (1, 0) (1, 5)
    OP         '='           (1, 6) (1, 7)
    STRING     "'places'"    (1, 8) (1, 16)
    NEWLINE    '\n'          (1, 16) (1, 17)
    NAME       'grÃ¼n'        (2, 0) (2, 4)
    OP         '='           (2, 5) (2, 6)
    STRING     "'green'"     (2, 7) (2, 14)
    r<   r=   r$   r$   r%   Útest_non_ascii_identifiers‰  s    z'TokenizeTest.test_non_ascii_identifiersc                 C   s   |   dd¡ d S )Nu#   Ã–rter = u'places'
grÃ¼n = U'green'u7      NAME       'Ã–rter'       (1, 0) (1, 5)
    OP         '='           (1, 6) (1, 7)
    STRING     "u'places'"   (1, 8) (1, 17)
    NEWLINE    '\n'          (1, 17) (1, 18)
    NAME       'grÃ¼n'        (2, 0) (2, 4)
    OP         '='           (2, 5) (2, 6)
    STRING     "U'green'"    (2, 7) (2, 15)
    r<   r=   r$   r$   r%   Útest_unicode•  s    zTokenizeTest.test_unicodec                 C   s   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd ¡ |   d!d"¡ |   d#d$¡ |   d%d&¡ |   d'd(¡ |   d)d*¡ d S )+Nz	async = 1z…    NAME       'async'       (1, 0) (1, 5)
    OP         '='           (1, 6) (1, 7)
    NUMBER     '1'           (1, 8) (1, 9)
    za = (async = 1)a8      NAME       'a'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    OP         '('           (1, 4) (1, 5)
    NAME       'async'       (1, 5) (1, 10)
    OP         '='           (1, 11) (1, 12)
    NUMBER     '1'           (1, 13) (1, 14)
    OP         ')'           (1, 14) (1, 15)
    zasync()z…    NAME       'async'       (1, 0) (1, 5)
    OP         '('           (1, 5) (1, 6)
    OP         ')'           (1, 6) (1, 7)
    zclass async(Bar):passa<      NAME       'class'       (1, 0) (1, 5)
    NAME       'async'       (1, 6) (1, 11)
    OP         '('           (1, 11) (1, 12)
    NAME       'Bar'         (1, 12) (1, 15)
    OP         ')'           (1, 15) (1, 16)
    OP         ':'           (1, 16) (1, 17)
    NAME       'pass'        (1, 17) (1, 21)
    zclass async:passzµ    NAME       'class'       (1, 0) (1, 5)
    NAME       'async'       (1, 6) (1, 11)
    OP         ':'           (1, 11) (1, 12)
    NAME       'pass'        (1, 12) (1, 16)
    z	await = 1z…    NAME       'await'       (1, 0) (1, 5)
    OP         '='           (1, 6) (1, 7)
    NUMBER     '1'           (1, 8) (1, 9)
    z	foo.asyncz…    NAME       'foo'         (1, 0) (1, 3)
    OP         '.'           (1, 3) (1, 4)
    NAME       'async'       (1, 4) (1, 9)
    zasync for a in b: passa;      NAME       'async'       (1, 0) (1, 5)
    NAME       'for'         (1, 6) (1, 9)
    NAME       'a'           (1, 10) (1, 11)
    NAME       'in'          (1, 12) (1, 14)
    NAME       'b'           (1, 15) (1, 16)
    OP         ':'           (1, 16) (1, 17)
    NAME       'pass'        (1, 18) (1, 22)
    zasync with a as b: passa<      NAME       'async'       (1, 0) (1, 5)
    NAME       'with'        (1, 6) (1, 10)
    NAME       'a'           (1, 11) (1, 12)
    NAME       'as'          (1, 13) (1, 15)
    NAME       'b'           (1, 16) (1, 17)
    OP         ':'           (1, 17) (1, 18)
    NAME       'pass'        (1, 19) (1, 23)
    z	async.fooz…    NAME       'async'       (1, 0) (1, 5)
    OP         '.'           (1, 5) (1, 6)
    NAME       'foo'         (1, 6) (1, 9)
    Úasyncz/    NAME       'async'       (1, 0) (1, 5)
    zasync
#comment
awaitzÛ    NAME       'async'       (1, 0) (1, 5)
    NEWLINE    '\n'          (1, 5) (1, 6)
    COMMENT    '#comment'    (2, 0) (2, 8)
    NL         '\n'          (2, 8) (2, 9)
    NAME       'await'       (3, 0) (3, 5)
    zasync
...
awaitzÛ    NAME       'async'       (1, 0) (1, 5)
    NEWLINE    '\n'          (1, 5) (1, 6)
    OP         '...'         (2, 0) (2, 3)
    NEWLINE    '\n'          (2, 3) (2, 4)
    NAME       'await'       (3, 0) (3, 5)
    zasync
awaitz…    NAME       'async'       (1, 0) (1, 5)
    NEWLINE    '\n'          (1, 5) (1, 6)
    NAME       'await'       (2, 0) (2, 5)
    zfoo.async + 1zß    NAME       'foo'         (1, 0) (1, 3)
    OP         '.'           (1, 3) (1, 4)
    NAME       'async'       (1, 4) (1, 9)
    OP         '+'           (1, 10) (1, 11)
    NUMBER     '1'           (1, 12) (1, 13)
    zasync def foo(): passa;      NAME       'async'       (1, 0) (1, 5)
    NAME       'def'         (1, 6) (1, 9)
    NAME       'foo'         (1, 10) (1, 13)
    OP         '('           (1, 13) (1, 14)
    OP         ')'           (1, 14) (1, 15)
    OP         ':'           (1, 15) (1, 16)
    NAME       'pass'        (1, 17) (1, 21)
    zNasync def foo():
  def foo(await):
    await = 1
  if 1:
    await
async += 1
a×      NAME       'async'       (1, 0) (1, 5)
    NAME       'def'         (1, 6) (1, 9)
    NAME       'foo'         (1, 10) (1, 13)
    OP         '('           (1, 13) (1, 14)
    OP         ')'           (1, 14) (1, 15)
    OP         ':'           (1, 15) (1, 16)
    NEWLINE    '\n'          (1, 16) (1, 17)
    INDENT     '  '          (2, 0) (2, 2)
    NAME       'def'         (2, 2) (2, 5)
    NAME       'foo'         (2, 6) (2, 9)
    OP         '('           (2, 9) (2, 10)
    NAME       'await'       (2, 10) (2, 15)
    OP         ')'           (2, 15) (2, 16)
    OP         ':'           (2, 16) (2, 17)
    NEWLINE    '\n'          (2, 17) (2, 18)
    INDENT     '    '        (3, 0) (3, 4)
    NAME       'await'       (3, 4) (3, 9)
    OP         '='           (3, 10) (3, 11)
    NUMBER     '1'           (3, 12) (3, 13)
    NEWLINE    '\n'          (3, 13) (3, 14)
    DEDENT     ''            (4, 2) (4, 2)
    NAME       'if'          (4, 2) (4, 4)
    NUMBER     '1'           (4, 5) (4, 6)
    OP         ':'           (4, 6) (4, 7)
    NEWLINE    '\n'          (4, 7) (4, 8)
    INDENT     '    '        (5, 0) (5, 4)
    NAME       'await'       (5, 4) (5, 9)
    NEWLINE    '\n'          (5, 9) (5, 10)
    DEDENT     ''            (6, 0) (6, 0)
    DEDENT     ''            (6, 0) (6, 0)
    NAME       'async'       (6, 0) (6, 5)
    OP         '+='          (6, 6) (6, 8)
    NUMBER     '1'           (6, 9) (6, 10)
    NEWLINE    '\n'          (6, 10) (6, 11)
    z)async def foo():
  async for i in 1: passaÉ      NAME       'async'       (1, 0) (1, 5)
    NAME       'def'         (1, 6) (1, 9)
    NAME       'foo'         (1, 10) (1, 13)
    OP         '('           (1, 13) (1, 14)
    OP         ')'           (1, 14) (1, 15)
    OP         ':'           (1, 15) (1, 16)
    NEWLINE    '\n'          (1, 16) (1, 17)
    INDENT     '  '          (2, 0) (2, 2)
    NAME       'async'       (2, 2) (2, 7)
    NAME       'for'         (2, 8) (2, 11)
    NAME       'i'           (2, 12) (2, 13)
    NAME       'in'          (2, 14) (2, 16)
    NUMBER     '1'           (2, 17) (2, 18)
    OP         ':'           (2, 18) (2, 19)
    NAME       'pass'        (2, 20) (2, 24)
    DEDENT     ''            (3, 0) (3, 0)
    zasync def foo(async): awaitah      NAME       'async'       (1, 0) (1, 5)
    NAME       'def'         (1, 6) (1, 9)
    NAME       'foo'         (1, 10) (1, 13)
    OP         '('           (1, 13) (1, 14)
    NAME       'async'       (1, 14) (1, 19)
    OP         ')'           (1, 19) (1, 20)
    OP         ':'           (1, 20) (1, 21)
    NAME       'await'       (1, 22) (1, 27)
    z@def f():

  def baz(): pass
  async def bar(): pass

  await = 2aÐ      NAME       'def'         (1, 0) (1, 3)
    NAME       'f'           (1, 4) (1, 5)
    OP         '('           (1, 5) (1, 6)
    OP         ')'           (1, 6) (1, 7)
    OP         ':'           (1, 7) (1, 8)
    NEWLINE    '\n'          (1, 8) (1, 9)
    NL         '\n'          (2, 0) (2, 1)
    INDENT     '  '          (3, 0) (3, 2)
    NAME       'def'         (3, 2) (3, 5)
    NAME       'baz'         (3, 6) (3, 9)
    OP         '('           (3, 9) (3, 10)
    OP         ')'           (3, 10) (3, 11)
    OP         ':'           (3, 11) (3, 12)
    NAME       'pass'        (3, 13) (3, 17)
    NEWLINE    '\n'          (3, 17) (3, 18)
    NAME       'async'       (4, 2) (4, 7)
    NAME       'def'         (4, 8) (4, 11)
    NAME       'bar'         (4, 12) (4, 15)
    OP         '('           (4, 15) (4, 16)
    OP         ')'           (4, 16) (4, 17)
    OP         ':'           (4, 17) (4, 18)
    NAME       'pass'        (4, 19) (4, 23)
    NEWLINE    '\n'          (4, 23) (4, 24)
    NL         '\n'          (5, 0) (5, 1)
    NAME       'await'       (6, 2) (6, 7)
    OP         '='           (6, 8) (6, 9)
    NUMBER     '2'           (6, 10) (6, 11)
    DEDENT     ''            (7, 0) (7, 0)
    zFasync def f():

  def baz(): pass
  async def bar(): pass

  await = 2a      NAME       'async'       (1, 0) (1, 5)
    NAME       'def'         (1, 6) (1, 9)
    NAME       'f'           (1, 10) (1, 11)
    OP         '('           (1, 11) (1, 12)
    OP         ')'           (1, 12) (1, 13)
    OP         ':'           (1, 13) (1, 14)
    NEWLINE    '\n'          (1, 14) (1, 15)
    NL         '\n'          (2, 0) (2, 1)
    INDENT     '  '          (3, 0) (3, 2)
    NAME       'def'         (3, 2) (3, 5)
    NAME       'baz'         (3, 6) (3, 9)
    OP         '('           (3, 9) (3, 10)
    OP         ')'           (3, 10) (3, 11)
    OP         ':'           (3, 11) (3, 12)
    NAME       'pass'        (3, 13) (3, 17)
    NEWLINE    '\n'          (3, 17) (3, 18)
    NAME       'async'       (4, 2) (4, 7)
    NAME       'def'         (4, 8) (4, 11)
    NAME       'bar'         (4, 12) (4, 15)
    OP         '('           (4, 15) (4, 16)
    OP         ')'           (4, 16) (4, 17)
    OP         ':'           (4, 17) (4, 18)
    NAME       'pass'        (4, 19) (4, 23)
    NEWLINE    '\n'          (4, 23) (4, 24)
    NL         '\n'          (5, 0) (5, 1)
    NAME       'await'       (6, 2) (6, 7)
    OP         '='           (6, 8) (6, 9)
    NUMBER     '2'           (6, 10) (6, 11)
    DEDENT     ''            (7, 0) (7, 0)
    r<   r=   r$   r$   r%   Ú
test_async¡  s:    




ù,þú%úzTokenizeTest.test_asyncN)Ú__name__Ú
__module__Ú__qualname__r2   r7   r;   r>   r?   r@   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rQ   r$   r$   r$   r%   r'   #   s*   
%9( '<&%r'   c                   @   s   e Zd Zdd„ ZdS )ÚGenerateTokensTestc                 C   s0   t |ƒ}tt|jƒ|ƒ}|  || ¡  ¡ ¡ d S ©N)r   r&   r   r*   r+   r,   r   r-   r$   r$   r%   r2   ´  s    z!GenerateTokensTest.check_tokenizeN)rR   rS   rT   r2   r$   r$   r$   r%   rU   ³  s   rU   c                 C   s€   g }t t|  d¡ƒjƒ}|D ]T\}}}}}|tkrbd|v rb| tdftdftt	|ƒftdfg¡ q| 
||f¡ qt|ƒ d¡S )Nr(   Ú.ÚDecimalrB   ú))r   r   r)   r*   r   Úextendr   r   r	   Úreprr   r   Údecode)r/   r   ÚgÚtoknumÚtokvalÚ_r$   r$   r%   Údecistmt¼  s    
üra   c                   @   s   e Zd Zdd„ ZdS )ÚTestMiscc                 C   sP   ddl m} d}|  t|ƒd¡ |  tt|ƒƒd¡ |  tt|ƒƒ|dƒ¡ d S )Nr   )rX   z+21.3e-5*-.1234/81.7z8+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7')z-3.2171603427[0-9]*e-0+7z!-3.217160342717258261933904529E-7)ÚdecimalrX   r+   ra   ZassertRegexr[   Úeval)r.   rX   r/   r$   r$   r%   Útest_decistmtÍ  s    
ÿÿzTestMisc.test_decistmtN)rR   rS   rT   re   r$   r$   r$   r%   rb   Ë  s   rb   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestTokenizerAdheresToPep0263c                 C   s,   t j t j t¡|¡}t | t|dƒ¡ d S )NÚrb)ÚosÚpathÚjoinÚdirnameÚ__file__ÚTestRoundtripÚcheck_roundtripr   )r.   Úfilenameri   r$   r$   r%   Ú	_testFileç  s    z'TestTokenizerAdheresToPep0263._testFilec                 C   s   d}|   |¡ d S )Nz9tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt©rp   ©r.   r1   r$   r$   r%   Ú'test_utf8_coding_cookie_and_no_utf8_bomë  s    zETestTokenizerAdheresToPep0263.test_utf8_coding_cookie_and_no_utf8_bomc                 C   s   d}|   t| j|¡ d S )Nz8tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt©ÚassertRaisesÚSyntaxErrorrp   rr   r$   r$   r%   Ú&test_latin1_coding_cookie_and_utf8_bomï  s    zDTestTokenizerAdheresToPep0263.test_latin1_coding_cookie_and_utf8_bomc                 C   s   d}|   |¡ d S )Nz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtrq   rr   r$   r$   r%   Ú"test_no_coding_cookie_and_utf8_bomú  s    z@TestTokenizerAdheresToPep0263.test_no_coding_cookie_and_utf8_bomc                 C   s   d}|   |¡ d S )Nz6tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txtrq   rr   r$   r$   r%   Ú$test_utf8_coding_cookie_and_utf8_bomþ  s    zBTestTokenizerAdheresToPep0263.test_utf8_coding_cookie_and_utf8_bomc                 C   s$   |   t| jd¡ |   t| jd¡ d S )Nzbad_coding.pyzbad_coding2.pyrt   r=   r$   r$   r%   Útest_bad_coding_cookie  s    z4TestTokenizerAdheresToPep0263.test_bad_coding_cookieN)	rR   rS   rT   rp   rs   rw   rx   ry   rz   r$   r$   r$   r%   rf   â  s   rf   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTest_Tokenizec                    sP   d}|  d¡‰d‰ ‡ ‡fdd„}tt|ddƒdd… }d	g}|  ||d
¡ d S )Nõ   "Ð‰ÐŠÐˆÐÐ‚"r(   Fc                      s   ˆ sd‰ ˆS dS d S ©NTó    r$   r$   ©Úfirstr#   r$   r%   r*     s    zNTest_Tokenize.test__tokenize_decodes_with_specified_encoding.<locals>.readline©Úencodingé   r4   ©é   r|   )rƒ   r   )rƒ   é   r|   zbytes not decoded with encoding)r)   r5   r   r+   )r.   Úliteralr*   r6   Úexpected_tokensr$   r   r%   Ú.test__tokenize_decodes_with_specified_encoding	  s    
	ÿz<Test_Tokenize.test__tokenize_decodes_with_specified_encodingc                    sF   d‰d‰ ‡ ‡fdd„}t t|d dƒd d… }dg}|  ||d¡ d S )	Nr|   Fc                      s   ˆ sd‰ ˆS dS d S r}   r$   r$   ©r€   r‡   r$   r%   r*     s    zQTest_Tokenize.test__tokenize_does_not_decode_with_encoding_none.<locals>.readliner   r4   r„   z*string not tokenized when encoding is None)r5   r   r+   )r.   r*   r6   rˆ   r$   rŠ   r%   Ú1test__tokenize_does_not_decode_with_encoding_none  s    	ÿz?Test_Tokenize.test__tokenize_does_not_decode_with_encoding_noneN)rR   rS   rT   r‰   r‹   r$   r$   r$   r%   r{     s   r{   c                   @   s¬   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)S )*ÚTestDetectEncodingc                    s   d‰ ‡ ‡fdd„}|S )Nr   c                     s$   ˆ t ˆƒkrt‚ˆˆ  } ˆ d7 ‰ | S ©Nrƒ   )r   ÚStopIteration)r#   ©ÚindexÚlinesr$   r%   r*   1  s
    z1TestDetectEncoding.get_readline.<locals>.readliner$   ©r.   r‘   r*   r$   r   r%   Úget_readline/  s    zTestDetectEncoding.get_readlinec                 C   s>   d}t |  |¡ƒ\}}|  |d¡ |  |t|d d… ƒ¡ d S )N)ó   # something
ó   print(something)
ó   do_something(else)
r(   é   )r   r“   r+   r5   ©r.   r‘   r‚   Úconsumed_linesr$   r$   r%   Útest_no_bom_no_encoding_cookie:  s    z1TestDetectEncoding.test_no_bom_no_encoding_cookiec                 C   s6   d}t |  |¡ƒ\}}|  |d¡ |  |ddg¡ d S )N)s   ï»¿# something
r•   r–   ú	utf-8-sigr”   r•   ©r   r“   r+   r˜   r$   r$   r%   Útest_bom_no_cookieD  s    ÿz%TestDetectEncoding.test_bom_no_cookiec                 C   s4   d}t |  |¡ƒ\}}|  |d¡ |  |dg¡ d S )N)ó   # -*- coding: latin-1 -*-
r•   r–   ú
iso-8859-1rž   rœ   r˜   r$   r$   r%   Útest_cookie_first_line_no_bomO  s    z0TestDetectEncoding.test_cookie_first_line_no_bomc                 C   s4   d}t |  |¡ƒ\}}|  |d¡ |  |dg¡ d S )N)s   ï»¿# coding=utf-8
r•   r–   r›   s   # coding=utf-8
rœ   r˜   r$   r$   r%   Ú&test_matched_bom_and_cookie_first_lineY  s    z9TestDetectEncoding.test_matched_bom_and_cookie_first_linec                 C   s    d}|   |¡}|  tt|¡ d S )N)s#   ï»¿# vim: set fileencoding=ascii :
r•   r–   ©r“   ru   rv   r   r’   r$   r$   r%   Ú<test_mismatched_bom_and_cookie_first_line_raises_syntaxerrorc  s    
zOTestDetectEncoding.test_mismatched_bom_and_cookie_first_line_raises_syntaxerrorc                 C   s:   d}t |  |¡ƒ\}}|  |d¡ ddg}|  ||¡ d S )N)ó   #! something
ó    # vim: set fileencoding=ascii :
r•   r–   Úasciir¤   r¥   rœ   ©r.   r‘   r‚   r™   r0   r$   r$   r%   Útest_cookie_second_line_no_boml  s
    z1TestDetectEncoding.test_cookie_second_line_no_bomc                 C   s6   d}t |  |¡ƒ\}}|  |d¡ |  |ddg¡ d S )N)ó   ï»¿#! something
ó   f# coding=utf-8
r•   r–   r›   r¤   rª   rœ   r˜   r$   r$   r%   Ú'test_matched_bom_and_cookie_second_linex  s    ÿz:TestDetectEncoding.test_matched_bom_and_cookie_second_linec                 C   s    d}|   |¡}|  tt|¡ d S )N)r©   r¥   r•   r–   r¢   r’   r$   r$   r%   Ú=test_mismatched_bom_and_cookie_second_line_raises_syntaxerror„  s    
zPTestDetectEncoding.test_mismatched_bom_and_cookie_second_line_raises_syntaxerrorc                 C   s8   d}t |  |¡ƒ\}}|  |d¡ dg}|  ||¡ d S )N)ó   print('Â£')
ó%   # vim: set fileencoding=iso8859-15 :
ó   print('â‚¬')
r(   r­   rœ   r§   r$   r$   r%   Ú/test_cookie_second_line_noncommented_first_lineŽ  s
    zBTestDetectEncoding.test_cookie_second_line_noncommented_first_linec                 C   s:   d}t |  |¡ƒ\}}|  |d¡ ddg}|  ||¡ d S )N)ó   #print('Â£')
r®   r¯   ú
iso8859-15r±   r®   rœ   r§   r$   r$   r%   Ú,test_cookie_second_line_commented_first_line™  s
    z?TestDetectEncoding.test_cookie_second_line_commented_first_linec                 C   s:   d}t |  |¡ƒ\}}|  |d¡ ddg}|  ||¡ d S )N)ó   
r®   r¯   r²   r´   r®   rœ   r§   r$   r$   r%   Ú(test_cookie_second_line_empty_first_line¤  s
    z;TestDetectEncoding.test_cookie_second_line_empty_first_linec           	      C   sd   d}|D ]V}dD ]L}|  d|¡}dd| d¡ d dd	f}|  |¡}t|ƒ\}}|  |d
¡ qqd S )N)zlatin-1rŸ   ziso-latin-1zlatin-1-unixziso-8859-1-unixziso-latin-1-mac©ú-r`   r·   ó   #!/usr/bin/python
ó
   # coding: r¦   r´   s   print(things)
s   do_something += 4
rŸ   ©Úreplacer)   r“   r   r+   ©	r.   Ú	encodingsr‚   ZrepÚencr‘   ZrlÚfoundr™   r$   r$   r%   Útest_latin1_normalization¯  s    ý
z,TestDetectEncoding.test_latin1_normalizationc                 C   s    d}|   |¡}|  tt|¡ d S )N©s
   print("ß")r¢   r’   r$   r$   r%   Útest_syntaxerror_latin1¾  s    
z*TestDetectEncoding.test_syntaxerror_latin1c           	      C   sb   d}|D ]T}dD ]J}|  d|¡}dd| d¡ d df}|  |¡}t|ƒ\}}|  |d	¡ qqd S )
N)r(   z	utf-8-macz
utf-8-unixr¶   r·   r¸   r¹   r¦   r´   s   1 + 3
r(   rº   r¼   r$   r$   r%   Útest_utf8_normalizationÈ  s    þ
z*TestDetectEncoding.test_utf8_normalizationc                 C   sÔ   |   d¡}t|ƒ\}}|  |d¡ |  |dg¡ t|   d¡ƒ\}}|  |d¡ |  |g ¡ |   d¡}t|ƒ\}}|  |d¡ |  |dg¡ |   d¡}t|ƒ\}}|  |d¡ |  |g ¡ |   d¡}|  tt|¡ d S )	N)r•   r(   r•   r$   )s   ï»¿print(something)
r›   )s   ï»¿)s   # coding: bad
)r“   r   r+   ru   rv   ©r.   r*   r‚   r™   r$   r$   r%   Útest_short_filesÕ  s"    



z#TestDetectEncoding.test_short_filesc                 C   s4   |   d¡}t|ƒ\}}|  |d¡ |  |dg¡ d S )N)ó   print("#coding=fake")r(   rÆ   )r“   r   r+   rÄ   r$   r$   r%   Útest_false_encodingì  s    
z&TestDetectEncoding.test_false_encodingc              	   C   s4  t jd }|  t j|¡ dD ]’}t|d|d,}td| |d td|d W d   ƒ n1 s`0    Y  t|ƒ,}|  |j|¡ |  |j	d¡ W d   ƒ q1 s¤0    Y  qt|dd	d}td|d W d   ƒ n1 sà0    Y  t|ƒ,}|  |jd	¡ |  |j	d¡ W d   ƒ n1 s&0    Y  d S )
Nz.py)ziso-8859-15r(   Úwr   z# coding: %s©Úfileu   print('euro:â‚¬')Úrr›   )
r   ZTESTFNZ
addCleanupÚunlinkr   ÚprintÚtokenize_openr+   r‚   Úmode)r.   ro   r‚   Úfpr$   r$   r%   Ú	test_openó  s    
*
.*
zTestDetectEncoding.test_openc                    s¦   d}d‰ G ‡ fdd„dƒ}|   t¡( |ˆ |ƒ}|`t|jƒ W d   ƒ n1 sR0    Y  |  td |¡¡$ |ˆ |ƒ}t|jƒ W d   ƒ n1 s˜0    Y  d S )NZsome_file_pathrÁ   c                       s    e Zd Zdd„ Z‡ fdd„ZdS )z;TestDetectEncoding.test_filename_in_exception.<locals>.Bunkc                 S   s   || _ || _d| _d S )Nr   )ÚnameZ_linesÚ_index)r.   r‘   ri   r$   r$   r%   Ú__init__  s    zDTestDetectEncoding.test_filename_in_exception.<locals>.Bunk.__init__c                    s.   | j tˆ ƒkrt‚ˆ | j  }|  j d7  _ |S r   )rÓ   r   rŽ   )r.   r#   ©r‘   r$   r%   r*     s
    
zDTestDetectEncoding.test_filename_in_exception.<locals>.Bunk.readlineN)rR   rS   rT   rÔ   r*   r$   rÕ   r$   r%   ÚBunk  s   rÖ   z.*{})ru   rv   rÒ   r   r*   r8   Úformat)r.   ri   rÖ   Zinsr$   rÕ   r%   Útest_filename_in_exception  s    
(
z-TestDetectEncoding.test_filename_in_exceptionc                 C   sT   t dƒ}tjd|d |  ttd¡ W d   ƒ n1 s:0    Y  |  |j¡ d S )Ns   #coding:xxxztokenize._builtin_open)Zreturn_valueZfoobar)r   r   Zpatchru   rv   rÎ   Z
assertTrueÚclosed)r.   Úmr$   r$   r%   Útest_open_error#  s    ,z"TestDetectEncoding.test_open_errorN)rR   rS   rT   r“   rš   r   r    r¡   r£   r¨   r«   r¬   r°   r³   rµ   rÀ   rÂ   rÃ   rÅ   rÇ   rÑ   rØ   rÛ   r$   r$   r$   r%   rŒ   -  s(   


	

rŒ   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestTokenizec                    sž   dd l }tƒ ‰d ‰‡fdd„}‡fdd„}d‰ ‡ fdd„}|j}|j}||_||_z,t |ƒ}|  t|ƒg d¢¡ W ||_||_n||_||_0 |  ˆˆ¡ d S )	Nr   c                    s   ˆ ddgfS )Nó   firstó   secondr$   )r*   r   r$   r%   Úmock_detect_encoding1  s    z8TestTokenize.test_tokenize.<locals>.mock_detect_encodingc                    s"   |‰ g }| ƒ }|r|  |¡ q|S rV   )r   )r*   r‚   ÚoutZ	next_line)Úencoding_usedr$   r%   Úmock__tokenize4  s    
z2TestTokenize.test_tokenize.<locals>.mock__tokenizec                      s    ˆ d7 ‰ ˆ dkrdS t ˆ ƒ ¡ S )Nrƒ   é   r~   )Ústrr)   r$   )Úcounterr$   r%   Úmock_readline@  s    z1TestTokenize.test_tokenize.<locals>.mock_readline)rÝ   rÞ   ó   1ó   2ó   3ó   4)r   Úobjectr   r   r+   r5   )r.   Ztokenize_modulerß   râ   ræ   Zorig_detect_encodingZorig__tokenizeÚresultsr$   )rå   r‚   rá   r%   Útest_tokenize-  s*    
ÿÿzTestTokenize.test_tokenizec                 C   sf   g }t dƒD ]}| dj|d¡ q| d¡ d |¡}ttt| d¡ƒjƒƒ}|  	|d j
d¡ d S )Niô  zdef i{i}(): return {i})ÚiZOKÚ
r(   éýÿÿÿ)Úranger   r×   rj   r5   r   r   r)   r*   r+   Ústring)r.   Úbufrî   Ztoksr$   r$   r%   Útest_oneline_defsU  s    

zTestTokenize.test_oneline_defsc                 G   sÂ   t tt| d¡ƒjƒƒ}t|ƒ}|  t|ƒd| ¡ |  t|d j tt	 ¡ t
|ƒD ]&}|  t||d  j t||  ¡ qV|  t|d|  j ttj ¡ |  t|d|  j ttj ¡ d S )Nr(   r…   r   rƒ   r—   )r5   r   r   r)   r*   r   r+   r   Ú
exact_typer   rñ   r    r   r
   )r.   ZopstrZoptypesr6   Znum_optypesrî   r$   r$   r%   ÚassertExactTypeEquala  s     ÿ
ÿÿÿz!TestTokenize.assertExactTypeEqualc                 C   sø  |   dtjtj¡ |   dtjtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj	¡ |   dtj
¡ |   dtj¡ |   d	tj¡ |   d
tj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtjtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj¡ |   dtj ¡ |   dtj!¡ |   dtj"¡ |   dtj#¡ |   d tj$¡ |   d!tj%¡ |   d"tj&¡ |   d"tj&¡ |   d#tj'¡ |   d$tj(¡ |   d%tj)¡ |   d&tj*¡ |   d'tj+¡ |   d(tj,¡ |   d)tj-¡ |   d*tj.¡ |   d+tj/¡ |   d,tj0¡ |   d-t1tjt2tj	t1tjt2tjt1tjt2¡ |   d.tjtj2tjtj2tjtj2tj¡ |   d/tjtjtj1tjtj2tj¡ d S )0Nz()z[]ú:ú,ú;ú+r·   Ú*ú/ú|ú&ú<ú>ú=rW   ú%z{}z==z!=z<=z>=ú~ú^z<<z>>z**z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//z//=z:=z...z->ú@z@=za**2+b**2==c**2z	{1, 2, 3}z
^(x & 0x1))3rö   r    ÚLPARÚRPARÚLSQBÚRSQBÚCOLONÚCOMMAÚSEMIÚPLUSÚMINUSÚSTARÚSLASHÚVBARÚAMPERÚLESSÚGREATERÚEQUALÚDOTÚPERCENTÚLBRACEÚRBRACEÚEQEQUALÚNOTEQUALÚ	LESSEQUALÚGREATEREQUALÚTILDEÚ
CIRCUMFLEXÚ	LEFTSHIFTÚ
RIGHTSHIFTÚ
DOUBLESTARÚ	PLUSEQUALÚMINEQUALÚ	STAREQUALÚ
SLASHEQUALÚPERCENTEQUALÚ
AMPEREQUALÚ	VBAREQUALÚCIRCUMFLEXEQUALÚLEFTSHIFTEQUALÚRIGHTSHIFTEQUALÚDOUBLESTAREQUALÚDOUBLESLASHÚDOUBLESLASHEQUALÚ
COLONEQUALÚELLIPSISÚRARROWÚATÚATEQUALr   r   r=   r$   r$   r%   Útest_exact_typeo  s‚    ûûüzTestTokenize.test_exact_typec                 C   s   |   dtj¡ d S )Nz@          )rö   r    r3  r=   r$   r$   r%   Ú%test_pathological_trailing_whitespace°  s    z2TestTokenize.test_pathological_trailing_whitespacec                 C   s¢   d}t jt jt jt jt jt jg}ttt	| 
d¡ƒjƒƒ}|  t|d j tt ¡ tdƒD ]&}|  t||d  j t||  ¡ qZ|  t|d j tt j ¡ d S )Nzb = 1

#testr(   r   é   rƒ   r   )r    r   r  r   r   ÚNLÚCOMMENTr5   r   r   r)   r*   r+   r   rõ   r   rñ   r
   )r.   Úsourcerˆ   r6   rî   r$   r$   r%   Ú5test_comment_at_the_end_of_the_source_without_newline´  s    $zBTestTokenize.test_comment_at_the_end_of_the_source_without_newlineN)	rR   rS   rT   rí   rô   rö   r5  r6  r;  r$   r$   r$   r%   rÜ   +  s   (ArÜ   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚUntokenizeTestc                 C   sn   t ƒ }d|_d|_|  t¡}| d¡ W d   ƒ n1 s<0    Y  |  |jjd d¡ |  t|jd¡ d S )Nr—   )rƒ   r…   r   z'start (1,3) precedes previous end (2,2))r—   rƒ   )	r   Úprev_rowÚprev_colru   Ú
ValueErrorÚadd_whitespacer+   Ú	exceptionÚargs)r.   ÚuÚcmr$   r$   r%   Útest_bad_input_orderÁ  s    (ÿz#UntokenizeTest.test_bad_input_orderc                 C   sd   t ƒ }d|_d|_g |_| d¡ |  |jdg¡ d|_| d¡ |  |jg d¢¡ t | d¡ d S )Nrƒ   )r—   r   ú\
r—   )é   rG  )rF  z\
\
r   za
  b
    c
  \
  c
)r   r=  r>  r6   r@  r+   rm   rn   )r.   rC  r$   r$   r%   Útest_backslash_continuationÍ  s    

z*UntokenizeTest.test_backslash_continuationc                 C   sš   t ƒ }tdf}tdf|g}| |tg ƒ¡ |  |jdg¡ t ƒ }|  | t|gƒ¡d¡ t ƒ }|  | t|ƒ¡d¡ |  |jd¡ |  tt|ƒƒd¡ d S )NZHellor(   zHello s   Hello )	r   r   r   ÚcompatÚiterr+   r6   r   r‚   )r.   rC  r    r6   r$   r$   r%   Útest_iter_compatÚ  s    zUntokenizeTest.test_iter_compatN)rR   rS   rT   rE  rH  rK  r$   r$   r$   r%   r<  ¿  s   r<  c                   @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )rm   c                 C   sÆ   t |tƒr| d¡}n| ¡ }| ¡  t|jddƒj}tt	|ƒƒ}dd„ |D ƒ}t
|ƒ}t|jddƒj}dd„ t	|ƒD ƒ}|  ||¡ t
|ƒ}	t|	jddƒj}
dd„ t	|
ƒD ƒ}|  ||¡ d S )Nr(   T)Úkeependsc                 S   s   g | ]}|d d… ‘qS ©Nr—   r$   ©Ú.0r:   r$   r$   r%   Ú
<listcomp>þ  r~   z1TestRoundtrip.check_roundtrip.<locals>.<listcomp>c                 S   s   g | ]}|d d… ‘qS rM  r$   rN  r$   r$   r%   rP    r~   c                 S   s   g | ]}|d d… ‘qS rM  r$   rN  r$   r$   r%   rP    r~   )Ú
isinstancerä   r)   ÚreadÚcloserJ  r   Ú__next__r5   r   r   r+   )r.   r1   Úcoder*   Ztokens5Ztokens2Zbytes_from2Z	readline2Ztokens2_from2Zbytes_from5Z	readline5Ztokens2_from5r$   r$   r%   rn   ê  s    
zTestRoundtrip.check_roundtripc                 C   sˆ   |   d¡ |   d¡ |   d¡ t d¡}t|dƒ}|   |¡ W d   ƒ n1 sR0    Y  |   d¡ |   d¡ |   d¡ |   d	¡ d S )
Nzif x == 1:
    print(x)
z # This is a comment
# This also
zif x == 1 : 
  print(x)
útokenize_tests.txtrg   zoif x == 1:
    # A comment by itself.
    print(x) # Comment here, too.
    # Another comment.
after_if = True
zPif (x # The comments need to go in the right place
    == 1):
    print('x==1')
z¾class Test: # A comment here
  # A comment with weird indent
  after_com = 5
  def x(m): return m*5 # a one liner
  def y(m): # A whitespace after the colon
     return y*4 # 3-space indent
zttry: import somemodule
except ImportError: # comment
    print('Can not import' # comment2
)else:   print('Loaded')
)rn   r   Úfindfiler   )r.   Úfnr1   r$   r$   r%   Útest_roundtrip
  s    



(


zTestRoundtrip.test_roundtripc                 C   s   |   d¡ d S )Nzna = (3,4, 
5,6)
y = [3, 4,
5]
z = {'a': 5,
'b':15, 'c':True}
x = len(y) + 5 - a[
3] - a[2]
+ len(z) - z[
'b']
©rn   r=   r$   r$   r%   Útest_continuation1  s    zTestRoundtrip.test_continuationc                 C   s   |   d¡ |   d¡ d S )Nz)x=1+\
1
# This is a comment\
# This also
z# Comment \
x = 0rZ  r=   r$   r$   r%   rH  >  s    
z)TestRoundtrip.test_backslash_continuationc                 C   s   |   d¡ d S )Nz'' ''rZ  r=   r$   r$   r%   Útest_string_concatenationG  s    z'TestRoundtrip.test_string_concatenationc              
   C   s  dd l }dd l}t d¡}tj |¡p*tj}|  tj | 	|¡d¡¡}| 
tj |d¡¡ dD ]}| 
tj |d¡| ¡ q^t d¡s’| |d¡}|D ]z}tjd	kr®td
|ƒ t|dƒF}| j|d |  |¡ W d   ƒ n1 sæ0    Y  W d   ƒ q–1 s0    Y  q–d S )Nr   rV  ztest*.pyztest_unicode_identifiers.py)ÚbufferZbuiltinZfileioÚinspectrh   ÚplatformÚsysz
test_%s.pyZcpué
   r—   r   rg   rÉ   )ÚglobÚrandomr   rW  rh   ri   rk   Úcurdirrj   ÚescapeÚremoveZis_resource_enabledÚsampleÚverboserÍ   r   ZsubTestrn   )r.   rb  rc  rX  ÚtempdirZ	testfilesr1   Ztestfiler$   r$   r%   Útest_random_filesK  s    



zTestRoundtrip.test_random_filesc                 C   s,   t |tƒr| d¡}ttt|ƒjƒƒ d¡S )Nr(   )rQ  rä   r)   r   r   r   r*   r\   )r.   rU  r$   r$   r%   Ú	roundtriph  s    

zTestRoundtrip.roundtripc                 C   s6   d}|   |¡ d¡}|  |d |d ¡ |  |¡ d S )Nzif False:
	x=3
	x=3
rï   rƒ   r—   )rk  Úsplitr+   rn   )r.   rU  Z	codelinesr$   r$   r%   Ú#test_indentation_semantics_retainedm  s    z1TestRoundtrip.test_indentation_semantics_retainedN)rR   rS   rT   rn   rY  r[  rH  r\  rj  rk  rm  r$   r$   r$   r%   rm   è  s    '	rm   Ú__main__)*Útestr   r   r   r   r   r   r   r	   r
   r   r   r   r   rÎ   r   r   r   Úior   r   Zunittestr   r   Ztest.test_grammarr   r   rh   r    r&   r'   rU   ra   rb   rf   r{   rŒ   rÜ   r<  rm   rR   Úmainr$   r$   r$   r%   Ú<module>   s>   D       	%&    ) 
