B
    u9aµú  ã               @   s:  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 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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r6e '¡  dS )é    )Úsupport)ÚtokenizeÚ	_tokenizeÚ
untokenizeÚNUMBERÚNAMEÚOPÚSTRINGÚ	ENDMARKERÚENCODINGÚtok_nameÚdetect_encodingÚopenÚUntokenizerÚgenerate_tokensÚNEWLINE)ÚBytesION)ÚTestCaseÚmock)ÚVALID_UNDERSCORE_LITERALSÚINVALID_UNDERSCORE_LITERALSc       
      C   sŠ   g }t | ¡ ƒ}|d dk}xh| D ]`\}}}}}	|tkr:P |rT|tkrT|d |krTq"t| }| d|d›d|d›d|› d|› ¡ q"W |S )Néÿÿÿÿz
r   z    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.7/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 )Nz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Úxzutf-8éþÿÿÿr   )	r   r&   Úlistr   r'   r(   r   r   r
   )r*   r-   Útokensr"   r"   r#   Útest_implicit_newline4   s    z"TokenizeTest.test_implicit_newlinec          	   C   sT   |   dd¡ |   dd¡ d}t|ƒj}|  td¡ xt|ƒD ]}q>W W d Q R X 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)r.   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)
    )r.   )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   sR   dd„ }x&t D ]}d|krq|  ||ƒ|¡ qW xtD ]}|  ||ƒ|¡ q6W d S )Nc             S   s<   t |  d¡ƒ}x(t|jƒD ]\}}}}}|tkr|S qW dS )Nzutf-8zinvalid token)r   r&   r   r'   r   )r+   r-   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*   r;   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é   sx    

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__r.   r3   r7   r8   r9   r:   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rK   r"   r"   r"   r#   r%   #   s*   
%9( '<&%r%   c             C   s„   g }t t|  d¡ƒjƒ}x\|D ]T\}}}}}|tkrdd|krd| tdftdftt	|ƒftdfg¡ q| 
||f¡ qW t|ƒ d¡S )Nzutf-8Ú.ÚDecimalr<   ú))r   r   r&   r'   r   Úextendr   r   r	   Úreprr   r   Údecode)r+   r   ÚgÚtoknumÚtokvalÚ_r"   r"   r#   Údecistmt´  s    
rY   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   )rP   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)ÚdecimalrP   r(   rY   ZassertRegexrS   Úeval)r*   rP   r+   r"   r"   r#   Útest_decistmtÅ  s    
zTestMisc.test_decistmtN)rL   rM   rN   r]   r"   r"   r"   r#   rZ   Ã  s   rZ   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*   Úfilenamera   r"   r"   r#   Ú	_testFileß  s    z'TestTokenizerAdheresToPep0263._testFilec             C   s   d}|   |¡ d S )Nz9tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt)rh   )r*   r-   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ÚSyntaxErrorrh   )r*   r-   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.txt)rh   )r*   r-   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.txt)rh   )r*   r-   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.py)rj   rk   rh   )r*   r"   r"   r#   Útest_bad_coding_cookieú  s    z4TestTokenizerAdheresToPep0263.test_bad_coding_cookieN)	rL   rM   rN   rh   ri   rl   rm   rn   ro   r"   r"   r"   r#   r^   Ú  s   r^   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 )Nu   "Ð‰ÐŠÐˆÐÐ‚"zutf-8Fc                  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é   r0   )é   u   "Ð‰ÐŠÐˆÐÐ‚")rt   r   )rt   é   u   "Ð‰ÐŠÐˆÐÐ‚"zbytes not decoded with encoding)r&   r1   r   r(   )r*   Úliteralr'   r2   Úexpected_tokensr"   )rr   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 )	Nu   "Ð‰ÐŠÐˆÐÐ‚"Fc                  s   ˆ sd‰ ˆS dS d S )NTrq   r"   r"   )rr   rw   r"   r#   r'     s    zQTest_Tokenize.test__tokenize_does_not_decode_with_encoding_none.<locals>.readline)rs   r0   )ru   u   "Ð‰ÐŠÐˆÐÐ‚")rt   r   )rt   rv   u   "Ð‰ÐŠÐˆÐÐ‚"z*string not tokenized when encoding is None)r1   r   r(   )r*   r'   r2   rx   r"   )rr   rw   r#   Ú1test__tokenize_does_not_decode_with_encoding_none  s    	z?Test_Tokenize.test__tokenize_does_not_decode_with_encoding_noneN)rL   rM   rN   ry   rz   r"   r"   r"   r#   rp   ÿ  s   rp   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 )Nrt   )r   ÚStopIteration)r!   )ÚindexÚlinesr"   r#   r'   )  s
    z1TestDetectEncoding.get_readline.<locals>.readliner"   )r*   r~   r'   r"   )r}   r~   r#   Úget_readline'  s    zTestDetectEncoding.get_readlinec             C   s>   d}t |  |¡ƒ\}}|  |d¡ |  |t|d d… ƒ¡ d S )N)s   # something
s   print(something)
s   do_something(else)
zutf-8é   )r   r   r(   r1   )r*   r~   rs   Úconsumed_linesr"   r"   r#   Útest_no_bom_no_encoding_cookie2  s    z1TestDetectEncoding.test_no_bom_no_encoding_cookiec             C   s6   d}t |  |¡ƒ\}}|  |d¡ |  |ddg¡ d S )N)s   ï»¿# something
s   print(something)
s   do_something(else)
z	utf-8-sigs   # something
s   print(something)
)r   r   r(   )r*   r~   rs   r   r"   r"   r#   Útest_bom_no_cookie<  s
    z%TestDetectEncoding.test_bom_no_cookiec             C   s4   d}t |  |¡ƒ\}}|  |d¡ |  |dg¡ d S )N)s   # -*- coding: latin-1 -*-
s   print(something)
s   do_something(else)
z
iso-8859-1s   # -*- coding: latin-1 -*-
)r   r   r(   )r*   r~   rs   r   r"   r"   r#   Útest_cookie_first_line_no_bomG  s    z0TestDetectEncoding.test_cookie_first_line_no_bomc             C   s4   d}t |  |¡ƒ\}}|  |d¡ |  |dg¡ d S )N)s   ï»¿# coding=utf-8
s   print(something)
s   do_something(else)
z	utf-8-sigs   # coding=utf-8
)r   r   r(   )r*   r~   rs   r   r"   r"   r#   Ú&test_matched_bom_and_cookie_first_lineQ  s    z9TestDetectEncoding.test_matched_bom_and_cookie_first_linec             C   s    d}|   |¡}|  tt|¡ d S )N)s#   ï»¿# vim: set fileencoding=ascii :
s   print(something)
s   do_something(else)
)r   rj   rk   r   )r*   r~   r'   r"   r"   r#   Ú<test_mismatched_bom_and_cookie_first_line_raises_syntaxerror[  s    
zOTestDetectEncoding.test_mismatched_bom_and_cookie_first_line_raises_syntaxerrorc             C   s:   d}t |  |¡ƒ\}}|  |d¡ ddg}|  ||¡ d S )N)s   #! something
s    # vim: set fileencoding=ascii :
s   print(something)
s   do_something(else)
Úasciis   #! something
s    # vim: set fileencoding=ascii :
)r   r   r(   )r*   r~   rs   r   r,   r"   r"   r#   Útest_cookie_second_line_no_bomd  s
    z1TestDetectEncoding.test_cookie_second_line_no_bomc             C   s6   d}t |  |¡ƒ\}}|  |d¡ |  |ddg¡ d S )N)s   ï»¿#! something
s   f# coding=utf-8
s   print(something)
s   do_something(else)
z	utf-8-sigs   #! something
s   f# coding=utf-8
)r   r   r(   )r*   r~   rs   r   r"   r"   r#   Ú'test_matched_bom_and_cookie_second_linep  s
    z:TestDetectEncoding.test_matched_bom_and_cookie_second_linec             C   s    d}|   |¡}|  tt|¡ d S )N)s   ï»¿#! something
s    # vim: set fileencoding=ascii :
s   print(something)
s   do_something(else)
)r   rj   rk   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)s   print('Â£')
s%   # vim: set fileencoding=iso8859-15 :
s   print('â‚¬')
zutf-8s   print('Â£')
)r   r   r(   )r*   r~   rs   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)s   #print('Â£')
s%   # vim: set fileencoding=iso8859-15 :
s   print('â‚¬')
z
iso8859-15s   #print('Â£')
s%   # vim: set fileencoding=iso8859-15 :
)r   r   r(   )r*   r~   rs   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)ó   
s%   # vim: set fileencoding=iso8859-15 :
s   print('â‚¬')
z
iso8859-15r   s%   # vim: set fileencoding=iso8859-15 :
)r   r   r(   )r*   r~   rs   r   r,   r"   r"   r#   Ú(test_cookie_second_line_empty_first_lineœ  s
    z;TestDetectEncoding.test_cookie_second_line_empty_first_linec       	      C   sl   d}xb|D ]Z}xTdD ]L}|  d|¡}dd| d¡ d dd	f}|  |¡}t|ƒ\}}|  |d
¡ qW q
W d S )N)zlatin-1z
iso-8859-1ziso-latin-1zlatin-1-unixziso-8859-1-unixziso-latin-1-mac)ú-rX   r   s   #!/usr/bin/python
s
   # coding: r‡   r   s   print(things)
s   do_something += 4
z
iso-8859-1)Úreplacer&   r   r   r(   )	r*   Ú	encodingsrs   ÚrepÚencr~   Ú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   rj   rk   r   )r*   r~   r'   r"   r"   r#   Útest_syntaxerror_latin1¶  s    
z*TestDetectEncoding.test_syntaxerror_latin1c       	      C   sj   d}x`|D ]X}xRdD ]J}|  d|¡}dd| d¡ d df}|  |¡}t|ƒ\}}|  |d	¡ qW q
W d S )
N)zutf-8z	utf-8-macz
utf-8-unix)r   rX   r   s   #!/usr/bin/python
s
   # coding: r‡   r   s   1 + 3
zutf-8)r   r&   r   r   r(   )	r*   r‘   rs   r’   r“   r~   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)s   print(something)
zutf-8s   print(something)
r"   )s   ï»¿print(something)
z	utf-8-sig)s   ï»¿)s   # coding: bad
)r   r   r(   rj   rk   )r*   r'   rs   r   r"   r"   r#   Útest_short_filesÍ  s"    



z#TestDetectEncoding.test_short_filesc             C   s4   |   d¡}t|ƒ\}}|  |d¡ |  |dg¡ d S )N)s   print("#coding=fake")zutf-8s   print("#coding=fake"))r   r   r(   )r*   r'   rs   r   r"   r"   r#   Útest_false_encodingä  s    
z&TestDetectEncoding.test_false_encodingc          
   C   sæ   t jd }|  t j|¡ xrdD ]j}t|d|d"}td| |d td|d W d Q R X t|ƒ"}|  |j|¡ |  |j	d¡ W d Q R X qW t|dd	d}td|d W d Q R X t|ƒ"}|  |jd	¡ |  |j	d¡ W d Q R X d S )
Nz.py)ziso-8859-15zutf-8Úw)rs   z# coding: %s)Úfileu   print('euro:â‚¬')Úrz	utf-8-sig)
r   ZTESTFNZ
addCleanupÚunlinkr   ÚprintÚtokenize_openr(   rs   Úmode)r*   rg   rs   Úfpr"   r"   r#   Ú	test_openë  s    



zTestDetectEncoding.test_openc          	      s~   d}d‰ G ‡ fdd„dƒ}|   t¡ |ˆ |ƒ}|`t|jƒ W d Q R X |  td |¡¡ |ˆ |ƒ}t|jƒ W d Q R X d S )NZsome_file_path)s
   print("ß")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~   ra   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 )Nrt   )r¥   r   r|   )r*   r!   )r~   r"   r#   r'     s
    
zDTestDetectEncoding.test_filename_in_exception.<locals>.Bunk.readlineN)rL   rM   rN   r¦   r'   r"   )r~   r"   r#   ÚBunk  s   r§   z.*{})rj   rk   r¤   r   r'   r4   Úformat)r*   ra   r§   Zinsr"   )r~   r#   Útest_filename_in_exceptionÿ  s    

z-TestDetectEncoding.test_filename_in_exceptionc          	   C   s@   t dƒ}tjd|d |  ttd¡ W d Q R X |  |j¡ d S )Ns   #coding:xxxztokenize._builtin_open)Zreturn_valueZfoobar)r   r   Zpatchrj   rk   r    Z
assertTrueÚclosed)r*   Úmr"   r"   r#   Útest_open_error  s    z"TestDetectEncoding.test_open_errorN)rL   rM   rN   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               @   s4   e Z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|ƒdd	d
dddg¡ W d ||_||_X |  ˆˆ¡ d S )Nr   c                s   ˆ ddgfS )Ns   firsts   secondr"   )r'   )rs   r"   r#   Úmock_detect_encoding)  s    z8TestTokenize.test_tokenize.<locals>.mock_detect_encodingc                s(   |‰ g }x| ƒ }|r |  |¡ q
|S d S )N)r   )r'   rs   ÚoutZ	next_line)Úencoding_usedr"   r#   Úmock__tokenize,  s    
z2TestTokenize.test_tokenize.<locals>.mock__tokenizec                  s    ˆ d7 ‰ ˆ dkrdS t ˆ ƒ ¡ S )Nrt   é   rq   )Ústrr&   r"   )Úcounterr"   r#   Úmock_readline8  s    z1TestTokenize.test_tokenize.<locals>.mock_readlines   firsts   secondó   1ó   2ó   3ó   4)r   Úobjectr   r   r(   r1   )r*   Ztokenize_moduler®   r±   rµ   Zorig_detect_encodingZorig__tokenizeÚresultsr"   )r´   rs   r°   r#   Útest_tokenize%  s$    
zTestTokenize.test_tokenizec             C   sj   g }x"t dƒD ]}| dj|d¡ qW | d¡ d |¡}ttt| d¡ƒjƒƒ}|  	|d j
d¡ d S )Niô  zdef i{i}(): return {i})ÚiZOKÚ
zutf-8éýÿÿÿ)Úranger   r¨   rb   r1   r   r   r&   r'   r(   Ústring)r*   Úbufr½   Ztoksr"   r"   r#   Útest_oneline_defsM  s    

zTestTokenize.test_oneline_defsc             G   sÆ   t tt| d¡ƒjƒƒ}t|ƒ}|  t|ƒd| ¡ |  t|d j tt	 ¡ x2t
|ƒD ]&}|  t||d  j t||  ¡ qXW |  t|d|  j ttj ¡ |  t|d|  j ttj ¡ d S )Nzutf-8ru   r   rt   r€   )r1   r   r   r&   r'   r   r(   r   Ú
exact_typer   rÀ   r   r   r
   )r*   ZopstrZoptypesr2   Znum_optypesr½   r"   r"   r#   ÚassertExactTypeEqualY  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,t0tjt1tj	t0tjt1tjt0tjt1¡ |   d-tjtj1tjtj1tjtj1tj¡ |   d.tjtjtj0tjtj1tj¡ d S )/Nz()z[]ú:ú,ú;ú+r   Ú*ú/ú|ú&ú<ú>ú=rO   ú%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))2rÅ   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ÚELLIPSISÚRARROWÚATÚATEQUALr   r   )r*   r"   r"   r#   Útest_exact_typeg  sz    zTestTokenize.test_exact_typec             C   s   |   dtj¡ d S )Nz@          )rÅ   r   r  )r*   r"   r"   r#   Ú%test_pathological_trailing_whitespace§  s    z2TestTokenize.test_pathological_trailing_whitespaceN)rL   rM   rN   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S )ÚUntokenizeTestc          	   C   sZ   t ƒ }d|_d|_|  t¡}| d¡ W d Q R X |  |jjd d¡ |  t|jd¡ d S )Nr€   )rt   ru   r   z'start (1,3) precedes previous end (2,2))r€   rt   )	r   Úprev_rowÚprev_colrj   Ú
ValueErrorÚadd_whitespacer(   Z	exceptionÚargs)r*   ÚuÚcmr"   r"   r#   Útest_bad_input_order®  s    z#UntokenizeTest.test_bad_input_orderc             C   sf   t ƒ }d|_d|_g |_| d¡ |  |jdg¡ d|_| d¡ |  |jdddg¡ t | d¡ d S )	Nrt   )r€   r   z\
r€   )é   r  z\
\
z    za
  b
    c
  \
  c
)r   r  r  r2   r	  r(   re   rf   )r*   r  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Hellozutf-8zHello s   Hello )	r   r   r   ÚcompatÚiterr(   r2   r   rs   )r*   r  r   r2   r"   r"   r#   Útest_iter_compatÇ  s    zUntokenizeTest.test_iter_compatN)rL   rM   rN   r  r  r  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 )re   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 )Nzutf-8T)Úkeependsc             S   s   g | ]}|d d… ‘qS )Nr€   r"   )Ú.0r6   r"   r"   r#   ú
<listcomp>ë  s    z1TestRoundtrip.check_roundtrip.<locals>.<listcomp>c             S   s   g | ]}|d d… ‘qS )Nr€   r"   )r  r6   r"   r"   r#   r  ï  s    c             S   s   g | ]}|d d… ‘qS )Nr€   r"   )r  r6   r"   r"   r#   r  ô  s    )Ú
isinstancer³   r&   ÚreadÚcloser  r   Ú__next__r1   r   r   r(   )r*   r-   Úcoder'   Ztokens5Ztokens2Zbytes_from2Z	readline2Ztokens2_from2Zbytes_from5Z	readline5Ztokens2_from5r"   r"   r#   rf   ×  s    
zTestRoundtrip.check_roundtripc          	   C   st   |   d¡ |   d¡ |   d¡ t d¡}t|dƒ}|   |¡ W d Q R X |   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)
ztokenize_tests.txtr_   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')
)rf   r   Úfindfiler   )r*   Úfnr-   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']
)rf   )r*   r"   r"   r#   Útest_continuation  s    zTestRoundtrip.test_continuationc             C   s   |   d¡ |   d¡ d S )Nz)x=1+\
1
# This is a comment\
# This also
z# Comment \
x = 0)rf   )r*   r"   r"   r#   r  +  s    
z)TestRoundtrip.test_backslash_continuationc             C   s   |   d¡ d S )Nz'' '')rf   )r*   r"   r"   r#   Útest_string_concatenation4  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¡¡ x$dD ]}| 	tj |d¡| ¡ qZW t 
d¡s| |d¡}xD|D ]<}t|d	ƒ(}| j|d
 |  |¡ W d Q R X W d Q R X q–W d S )Nr   ztokenize_tests.txtztest*.pyztest_unicode_identifiers.py)ÚbufferZbuiltinZfileioÚinspectr`   ÚplatformÚsysz
test_%s.pyZcpué
   r_   )rœ   )ÚglobÚrandomr   r  r`   ra   rc   Úcurdirrb   ÚremoveZis_resource_enabledZsampler   ZsubTestrf   )r*   r%  r&  r  ZtempdirZ	testfilesr-   Ztestfiler"   r"   r#   Útest_random_files8  s    



zTestRoundtrip.test_random_filesc             C   s,   t |tƒr| d¡}ttt|ƒjƒƒ d¡S )Nzutf-8)r  r³   r&   r   r   r   r'   rT   )r*   r  r"   r"   r#   Ú	roundtripS  s    

zTestRoundtrip.roundtripc             C   s6   d}|   |¡ d¡}|  |d |d ¡ |  |¡ d S )Nzif False:
	x=3
	x=3
r¾   rt   r€   )r*  Úsplitr(   rf   )r*   r  Z	codelinesr"   r"   r#   Ú#test_indentation_semantics_retainedX  s    z1TestRoundtrip.test_indentation_semantics_retainedN)rL   rM   rN   rf   r  r  r  r  r)  r*  r,  r"   r"   r"   r#   re   Õ  s    '	re   Ú__main__)(Ztestr   r   r   r   r   r   r   r	   r
   r   r   r   r   r    r   r   r   Úior   Zunittestr   r   Ztest.test_grammarr   r   r`   r   r$   r%   rY   rZ   r^   rp   r{   r­   r  re   rL   Úmainr"   r"   r"   r#   Ú<module>   s<   D       %&    
) 
