HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_tokenize.cpython-310.pyc
o

�i�@s�ddlmZddlmZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZddlZddlmZddlmZmZddlmZmZddlmZdd	lm Z m!Z!ddl"Z"ddl#Z#d
d�Z$Gdd
�d
e�Z%Gdd�de%�Z&dd�Z'Gdd�de�Z(Gdd�de�Z)Gdd�de�Z*Gdd�de�Z+Gdd�de�Z,Gdd�de�Z-Gdd�de�Z.Gd d!�d!ej�Z/e0d"kr�e�1�dSdS)#�)�support)�	os_helper)�tokenize�	_tokenize�
untokenize�NUMBER�NAME�OP�STRING�	ENDMARKER�ENCODING�tok_name�detect_encoding�open�Untokenizer�generate_tokens�NEWLINE)�BytesIO�StringION)�dedent)�TestCase�mock)�VALID_UNDERSCORE_LITERALS�INVALID_UNDERSCORE_LITERALS)�run_test_script�make_scriptc
Cs�g}t|���}|ddv}|D]2\}}}}}	|tkr|S|r+|tkr+|d|kr+qt|}|�d|d�d|d�d|�d|���q|S)N���z
r�    Z10� Z13)�len�
splitlinesrrr
�append)
Ztoken_generatorZ
source_string�resultZ	num_linesZmissing_trailing_nl�type�token�start�end�line�r(�//usr/local/lib/python3.10/test/test_tokenize.py�stringify_tokens_from_sources�(r*c@�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�TokenizeTestcCs<t|�d��}tt|j�|�}|�|dg|�����dS)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
��zTokenizeTest.check_tokenizecCsDtd�d��}tt|j��}|�|djt�|�|djt�dS)N�xr-���r)	rr.�listrr/r0r#rr)r3r6�tokensr(r(r)�test_implicit_newline7sz"TokenizeTest.test_implicit_newlinecCsf|�dd�|�dd�d}t|�j}|�td��t|�D]}qWd�dS1s,wYdS)Nz1 + 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)
    sdef k(x):
    x += 2
  x += 5
z3unindent does not match any outer indentation level)r7rr/�assertRaisesRegex�IndentationErrorr)r3Zindent_error_filer/�tokr(r(r)�
test_basic?s�
��"�zTokenizeTest.test_basiccCsp|�dd�|�dd�|�dd�|�dd�|�d	d
�|�dd�|�d
d�|�dd�|�dd�dS)Nz0xff <= 255z�    NUMBER     '0xff'        (1, 0) (1, 4)
    OP         '<='          (1, 5) (1, 7)
    NUMBER     '255'         (1, 8) (1, 11)
    z0b10 <= 255z�    NUMBER     '0b10'        (1, 0) (1, 4)
    OP         '<='          (1, 5) (1, 7)
    NUMBER     '255'         (1, 8) (1, 11)
    z0o123 <= 0O123z�    NUMBER     '0o123'       (1, 0) (1, 5)
    OP         '<='          (1, 6) (1, 8)
    NUMBER     '0O123'       (1, 9) (1, 14)
    z1234567 > ~0x15z�    NUMBER     '1234567'     (1, 0) (1, 7)
    OP         '>'           (1, 8) (1, 9)
    OP         '~'           (1, 10) (1, 11)
    NUMBER     '0x15'        (1, 11) (1, 15)
    z2134568 != 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)
    z0xdeadbeef != -1z�    NUMBER     '0xdeadbeef'  (1, 0) (1, 10)
    OP         '!='          (1, 11) (1, 13)
    OP         '-'           (1, 14) (1, 15)
    NUMBER     '1'           (1, 15) (1, 16)
    z0xdeadc0de & 12345z�    NUMBER     '0xdeadc0de'  (1, 0) (1, 10)
    OP         '&'           (1, 11) (1, 12)
    NUMBER     '12345'       (1, 13) (1, 18)
    z0xFF & 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)
    �r7�r3r(r(r)�test_intds
zTokenizeTest.test_intcCs4|�dd�|�dd�|�dd�|�dd�dS)	Nzx = 0z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '0'           (1, 4) (1, 5)
    zx = 0xfffffffffffz�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '0xfffffffffff' (1, 4) (1, 17)
    zx = 123141242151251616110z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '123141242151251616110' (1, 4) (1, 25)
    zx = -15921590215012591z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    OP         '-'           (1, 4) (1, 5)
    NUMBER     '15921590215012591' (1, 5) (1, 22)
    rArBr(r(r)�	test_long�szTokenizeTest.test_longcCsX|�dd�|�dd�|�dd�|�dd�|�d	d
�|�dd�|�d
d�dS)Nzx = 3.14159z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '3.14159'     (1, 4) (1, 11)
    zx = 314159.z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '314159.'     (1, 4) (1, 11)
    zx = .314159z�    NAME       'x'           (1, 0) (1, 1)
    OP         '='           (1, 2) (1, 3)
    NUMBER     '.314159'     (1, 4) (1, 11)
    zx = 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)
    rArBr(r(r)�
test_float�szTokenizeTest.test_floatcCsJdd�}tD]}d|vr
q|�||�|�qtD]
}|�||�|�qdS)NcSs<t|�d��}t|j�D]\}}}}}|tkr|SqdS)Nr-z
invalid token)rr.rr/r)r4r6Ztoktyper$r%r&r'r(r(r)�number_token�s�z;TokenizeTest.test_underscore_literals.<locals>.number_token�()rr0rZassertNotEqual)r3rFZlitr(r(r)�test_underscore_literals�s�z%TokenizeTest.test_underscore_literalscCs<|�dd�|�dd�|�dd�|�dd�|�d	d
�|�dd�|�d
d�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd �|�d!d"�|�d#d$�|�d%d&�|�d'd(�|�d)d*�|�d+d,�|�d-d.�|�d/d0�|�d1d2�|�d3d4�dS)5Nzx = ''; 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)
    zx = '"'; 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)
    zx = "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)
    zx = '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)
    zy = "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)
    zu'abc' + U'abc'z�    STRING     "u'abc'"      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     "U'abc'"      (1, 9) (1, 15)
    zu"abc" + U"abc"z�    STRING     'u"abc"'      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     'U"abc"'      (1, 9) (1, 15)
    zb'abc' + B'abc'z�    STRING     "b'abc'"      (1, 0) (1, 6)
    OP         '+'           (1, 7) (1, 8)
    STRING     "B'abc'"      (1, 9) (1, 15)
    zb"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)
    zu"a\
de"z/    STRING     'u"a\\\nde"'  (1, 0) (2, 3)
    zrb"a\
d"z/    STRING     'rb"a\\\nd"'  (1, 0) (2, 2)
    z
"""a\
b"""z0    STRING     '"""a\\\nb"""' (1, 0) (2, 4)
    zu"""a\
b"""z1    STRING     'u"""a\\\nb"""' (1, 0) (2, 4)
    zrb"""a\
b\
c"""z7    STRING     'rb"""a\\\nb\\\nc"""' (1, 0) (3, 4)
    zf"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)
    zf"abc\
def"z1    STRING     'f"abc\\\ndef"' (1, 0) (2, 4)
    zRf"abc\
def"z2    STRING     'Rf"abc\\\ndef"' (1, 0) (2, 4)
    rArBr(r(r)�test_string�sT					
��������zTokenizeTest.test_stringcCs(|�dd�|�dd�|�dd�dS)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)
    zdef 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)
    rArBr(r(r)�
test_function�szTokenizeTest.test_functioncC�|�dd�dS)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)
    rArBr(r(r)�test_comparison�s�zTokenizeTest.test_comparisoncCrK)Nzx = 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)
    rArBr(r(r)�
test_shift��zTokenizeTest.test_shiftcCrK)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)
    rArBr(r(r)�
test_additiverNzTokenizeTest.test_additivecCrK)Nzx = 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)
    rArBr(r(r)�test_multiplicativerNz TokenizeTest.test_multiplicativecCs|�dd�|�dd�dS)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)
    rArBr(r(r)�
test_unary+s
zTokenizeTest.test_unarycCrK)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)
    rArBr(r(r)�
test_selectorPrNzTokenizeTest.test_selectorcCrK)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)
    rArBr(r(r)�test_methodfrNzTokenizeTest.test_methodcCrK)Nzdef 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)
    rArBr(r(r)�	test_tabsws�zTokenizeTest.test_tabscCrK)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)
    rArBr(r(r)�test_non_ascii_identifiers�rNz'TokenizeTest.test_non_ascii_identifierscCrK)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)
    rArBr(r(r)�test_unicode�rNzTokenizeTest.test_unicodecCs|�dd�|�dd�|�dd�|�dd�|�d	d
�|�dd�|�d
d�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd �|�d!d"�|�d#d$�|�d%d&�|�d'd(�|�d)d*�dS)+Nz	async = 1z�    NAME       'async'       (1, 0) (1, 5)
    OP         '='           (1, 6) (1, 7)
    NUMBER     '1'           (1, 8) (1, 9)
    za = (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)
    zasync()z�    NAME       'async'       (1, 0) (1, 5)
    OP         '('           (1, 5) (1, 6)
    OP         ')'           (1, 6) (1, 7)
    zclass 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)
    zclass 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)
    zasync 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)
    zasync 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)
    zasync
#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)
    zasync
...
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)
    zasync
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)
    zasync 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)
    zasync 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)
    rArBr(r(r)�
test_async�s:




�,��%�zTokenizeTest.test_asyncN)�__name__�
__module__�__qualname__r7r<r@rCrDrErHrIrJrLrMrOrPrQrRrSrTrUrVrXr(r(r(r)r,'s,	%9('<&%r,c@�eZdZdd�ZdS)�GenerateTokensTestcCs0t|�}tt|j�|�}|�||�����dS�N)rr*rr/r0r1r r2r(r(r)r7�sz!GenerateTokensTest.check_tokenizeN)rYrZr[r7r(r(r(r)r]��r]cCs�g}tt|�d��j�}|D]*\}}}}}|tkr1d|vr1|�tdftdftt	|�ftdfg�q|�
||f�qt|��d�S)Nr-�.�DecimalrG�))
rrr.r/r�extendrr	r
�reprr!r�decode)r4r"�g�toknum�tokval�_r(r(r)�decistmt�s
�rjc@r\)�TestMisccCsPddlm}d}|�t|�d�|�tt|��d�|�tt|��|d��dS)Nr)raz+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)�decimalrar0rjZassertRegexrd�eval)r3rar4r(r(r)�
test_decistmt�s
��zTestMisc.test_decistmtN)rYrZr[rnr(r(r(r)rk�srkc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TestTokenizerAdheresToPep0263zU
    Test that tokenizer adheres to the coding behaviour stipulated in PEP 0263.
    cCs,tj�tj�t�|�}t�|t|d��dS)N�rb)�os�path�join�dirname�__file__�
TestRoundtrip�check_roundtripr)r3�filenamerrr(r(r)�	_testFile�sz'TestTokenizerAdheresToPep0263._testFilecC�d}|�|�dS)Nz9tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt�ry�r3r6r(r(r)�'test_utf8_coding_cookie_and_no_utf8_bom��zETestTokenizerAdheresToPep0263.test_utf8_coding_cookie_and_no_utf8_bomcCsd}|�t|j|�dS)a�
        As per PEP 0263, if a file starts with a utf-8 BOM signature, the only
        allowed encoding for the comment is 'utf-8'.  The text file used in
        this test starts with a BOM signature, but specifies latin1 as the
        coding, so verify that a SyntaxError is raised, which matches the
        behaviour of the interpreter when it encounters a similar condition.
        z8tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txtN��assertRaises�SyntaxErrorryr|r(r(r)�&test_latin1_coding_cookie_and_utf8_bom�szDTestTokenizerAdheresToPep0263.test_latin1_coding_cookie_and_utf8_bomcCrz)Nz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr{r|r(r(r)�"test_no_coding_cookie_and_utf8_bom�r~z@TestTokenizerAdheresToPep0263.test_no_coding_cookie_and_utf8_bomcCrz)Nz6tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txtr{r|r(r(r)�$test_utf8_coding_cookie_and_utf8_bomr~zBTestTokenizerAdheresToPep0263.test_utf8_coding_cookie_and_utf8_bomcCs$|�t|jd�|�t|jd�dS)Nz
bad_coding.pyzbad_coding2.pyrrBr(r(r)�test_bad_coding_cookiesz4TestTokenizerAdheresToPep0263.test_bad_coding_cookieN)
rYrZr[�__doc__ryr}r�r�r�r�r(r(r(r)ro�sroc@seZdZdd�Zdd�ZdS)�
Test_TokenizecsPd}|�d��d���fdd�}tt|dd��dd�}d	g}|�||d
�dS)N�"ЉЊЈЁЂ"r-Fc��sd��SdS�NT�r(r(��firstr'r(r)r/�zNTest_Tokenize.test__tokenize_decodes_with_specified_encoding.<locals>.readline��encoding�r9��r�)r�r)r��r�zbytes not decoded with encoding)r.r:rr0)r3�literalr/r;�expected_tokensr(r�r)�.test__tokenize_decodes_with_specified_encodings
	�z<Test_Tokenize.test__tokenize_decodes_with_specified_encodingcsFd�d���fdd�}tt|dd��dd�}dg}|�||d�dS)	Nr�Fcr�r�r(r(�r�r�r(r)r/!r�zQTest_Tokenize.test__tokenize_does_not_decode_with_encoding_none.<locals>.readliner�r9r�z*string not tokenized when encoding is None)r:rr0)r3r/r;r�r(r�r)�1test__tokenize_does_not_decode_with_encoding_nones	�z?Test_Tokenize.test__tokenize_does_not_decode_with_encoding_noneN)rYrZr[r�r�r(r(r(r)r�
sr�c@r+)*�TestDetectEncodingcsd���fdd�}|S)Nrcs$�t��krt���}�d7�|S�Nr�)r�
StopIteration)r'��index�linesr(r)r/4s
z1TestDetectEncoding.get_readline.<locals>.readliner(�r3r�r/r(r�r)�get_readline2szTestDetectEncoding.get_readlinecCs>d}t|�|��\}}|�|d�|�|t|dd���dS)N)�# something
�print(something)
�do_something(else)
r-�)rr�r0r:�r3r�r��consumed_linesr(r(r)�test_no_bom_no_encoding_cookie=sz1TestDetectEncoding.test_no_bom_no_encoding_cookiecC�6d}t|�|��\}}|�|d�|�|ddg�dS)N)s# something
r�r��	utf-8-sigr�r��rr�r0r�r(r(r)�test_bom_no_cookieGs�z%TestDetectEncoding.test_bom_no_cookiecC�4d}t|�|��\}}|�|d�|�|dg�dS)N)�# -*- coding: latin-1 -*-
r�r��
iso-8859-1r�r�r�r(r(r)�test_cookie_first_line_no_bomR�z0TestDetectEncoding.test_cookie_first_line_no_bomcCr�)N)s# coding=utf-8
r�r�r�s# coding=utf-8
r�r�r(r(r)�&test_matched_bom_and_cookie_first_line\r�z9TestDetectEncoding.test_matched_bom_and_cookie_first_linecC� d}|�|�}|�tt|�dS)N)s## vim: set fileencoding=ascii :
r�r��r�r�r�rr�r(r(r)�<test_mismatched_bom_and_cookie_first_line_raises_syntaxerrorfs
zOTestDetectEncoding.test_mismatched_bom_and_cookie_first_line_raises_syntaxerrorcC�:d}t|�|��\}}|�|d�ddg}|�||�dS)N)�
#! something
� # vim: set fileencoding=ascii :
r�r��asciir�r�r��r3r�r�r�r5r(r(r)�test_cookie_second_line_no_bomos
z1TestDetectEncoding.test_cookie_second_line_no_bomcCr�)N)�#! something
�f# coding=utf-8
r�r�r�r�r�r�r�r(r(r)�'test_matched_bom_and_cookie_second_line{s�z:TestDetectEncoding.test_matched_bom_and_cookie_second_linecCr�)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_syntaxerrorcCs8d}t|�|��\}}|�|d�dg}|�||�dS)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_linecCr�)N)�
#print('£')
r�r��
iso8859-15r�r�r�r�r(r(r)�,test_cookie_second_line_commented_first_line��
z?TestDetectEncoding.test_cookie_second_line_commented_first_linecCr�)N)�
r�r�r�r�r�r�r�r(r(r)�(test_cookie_second_line_empty_first_line�r�z;TestDetectEncoding.test_cookie_second_line_empty_first_linec	Csdd}|D]+}dD]&}|�d|�}dd|�d�ddd	f}|�|�}t|�\}}|�|d
�qqdS)N)zlatin-1r�ziso-latin-1zlatin-1-unixziso-8859-1-unixziso-latin-1-mac��-rir��#!/usr/bin/python
�
# coding: r�r�sprint(things)
sdo_something += 4
r���replacer.r�rr0�	r3�	encodingsr�Zrep�encr�Zrl�foundr�r(r(r)�test_latin1_normalization�s�
��z,TestDetectEncoding.test_latin1_normalizationcCr�)N�s
print("�")r�r�r(r(r)�test_syntaxerror_latin1�s
z*TestDetectEncoding.test_syntaxerror_latin1c	Csbd}|D]*}dD]%}|�d|�}dd|�d�ddf}|�|�}t|�\}}|�|d	�qqdS)
N)r-z	utf-8-macz
utf-8-unixr�r�r�r�r�r�s1 + 3
r-r�r�r(r(r)�test_utf8_normalization�s�
��z*TestDetectEncoding.test_utf8_normalizationcCs�|�d�}t|�\}}|�|d�|�|dg�t|�d��\}}|�|d�|�|g�|�d�}t|�\}}|�|d�|�|dg�|�d�}t|�\}}|�|d�|�|g�|�d�}|�tt|�dS)	N)r�r-r�r()sprint(something)
r�)s)s# coding: bad
)r�rr0r�r��r3r/r�r�r(r(r)�test_short_files�s"



z#TestDetectEncoding.test_short_filescCs4|�d�}t|�\}}|�|d�|�|dg�dS)N)�print("#coding=fake")r-r�)r�rr0r�r(r(r)�test_false_encoding�s
z&TestDetectEncoding.test_false_encodingc	Cs4tjd}|�tj|�dD]I}t|d|d��}td||d�td|d�Wd�n1s0wYt|��}|�|j|�|�|j	d�Wd�n1sRwYqt|dd	d��}td|d�Wd�n1spwYt|��}|�|jd	�|�|j	d�Wd�dS1s�wYdS)
Nz.py)ziso-8859-15r-�wr�z# coding: %s��fileuprint('euro:€')�rr�)
rZTESTFNZ
addCleanup�unlinkr�print�
tokenize_openr0r��mode)r3rxr��fpr(r(r)�	test_open�s&
�
���
"�zTestDetectEncoding.test_opencs�d}d�G�fdd�d�}|�t��|�|�}|`t|j�Wd�n1s)wY|�td�|���|�|�}t|j�Wd�dS1sMwYdS)NZsome_file_pathr�cs eZdZdd�Z�fdd�ZdS)z;TestDetectEncoding.test_filename_in_exception.<locals>.BunkcSs||_||_d|_dS)Nr)�nameZ_lines�_index)r3r�rrr(r(r)�__init__s
zDTestDetectEncoding.test_filename_in_exception.<locals>.Bunk.__init__cs.|jt��kr	t��|j}|jd7_|Sr�)r�rr�)r3r'�r�r(r)r/s

zDTestDetectEncoding.test_filename_in_exception.<locals>.Bunk.readlineN)rYrZr[r�r/r(r�r(r)�Bunksr�z.*{})r�r�r�rr/r=�format)r3rrr�Zinsr(r�r)�test_filename_in_exception
s
�
"�z-TestDetectEncoding.test_filename_in_exceptioncCsTtd�}tjd|d��|�ttd�Wd�n1swY|�|j�dS)Ns#coding:xxxztokenize._builtin_open)Zreturn_valueZfoobar)rrZpatchr�r�r�Z
assertTrue�closed)r3�mr(r(r)�test_open_error&s
�z"TestDetectEncoding.test_open_errorN)rYrZr[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�0s*


	


r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestTokenizecs�ddl}t��d��fdd�}�fdd�}d��fdd�}|j}|j}||_||_zt|�}|�t|�gd��W||_||_n||_||_w|����dS)	Nrcs�ddgfS)N�first�secondr()r/r�r(r)�mock_detect_encoding4sz8TestTokenize.test_tokenize.<locals>.mock_detect_encodingcs$|�g}	|�}|r|�|�q|Sr^)r!)r/r��outZ	next_line)�
encoding_usedr(r)�mock__tokenize7s
z2TestTokenize.test_tokenize.<locals>.mock__tokenizecs �d7��dkr
dSt����S)Nr��r�)�strr.r()�counterr(r)�
mock_readlineCsz1TestTokenize.test_tokenize.<locals>.mock_readline)r�r��1�2�3�4)r�objectrrr0r:)r3Ztokenize_moduler�r�r�Zorig_detect_encodingZorig__tokenize�resultsr()r�r�r�r)�
test_tokenize0s*
��zTestTokenize.test_tokenizecCsfg}td�D]}|�dj|d��q|�d�d�|�}ttt|�d��j��}|�	|dj
d�dS)Ni�zdef i{i}(): return {i})�iZOK�
r-���)�ranger!r�rsr:rrr.r/r0�string)r3�bufrZtoksr(r(r)�test_oneline_defsXs

zTestTokenize.test_oneline_defscGs�ttt|�d��j��}t|�}|�t|�d|�|�t|djtt	�t
|�D]}|�t||djt||�q+|�t|d|jttj�|�t|d|jttj
�dS)Nr-r�rr�r�)r:rrr.r/rr0r
�
exact_typerrr$rr)r3ZopstrZoptypesr;Znum_optypesrr(r(r)�assertExactTypeEqualds �
���z!TestTokenize.assertExactTypeEqualcCs�|�dtjtj�|�dtjtj�|�dtj�|�dtj�|�dtj�|�dtj	�|�dtj
�|�dtj�|�d	tj�|�d
tj
�|�dtj�|�dtj�|�d
tj�|�dtj�|�dtj�|�dtj�|�dtjtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj�|�dtj �|�dtj!�|�dtj"�|�dtj#�|�d tj$�|�d!tj%�|�d"tj&�|�d"tj&�|�d#tj'�|�d$tj(�|�d%tj)�|�d&tj*�|�d'tj+�|�d(tj,�|�d)tj-�|�d*tj.�|�d+tj/�|�d,tj0�|�d-t1tjt2tj	t1tjt2tjt1tjt2�|�d.tjtj2tjtj2tjtj2tj�|�d/tjtjtj1tjtj2tj�dS)0Nz()z[]�:�,�;�+r��*�/�|�&�<�>�=r`�%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@=za**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�ATEQUALrrrBr(r(r)�test_exact_typers����zTestTokenize.test_exact_typecCs|�dtj�dS)Nz@          )r
r$rGrBr(r(r)�%test_pathological_trailing_whitespace�sz2TestTokenize.test_pathological_trailing_whitespacecCs�d}tjtjtjtjtjtjg}ttt	|�
d��j��}|�t
|djt
t�td�D]}|�t
||djt
||�q-|�t
|djt
tj�dS)Nzb = 1

#testr-r�r�r)r$rr)rr�NL�COMMENTr:rrr.r/r0r
r	rrr)r3�sourcer�r;rr(r(r)�5test_comment_at_the_end_of_the_source_without_newline�s$ zBTestTokenize.test_comment_at_the_end_of_the_source_without_newlineN)	rYrZr[rrr
rIrJrOr(r(r(r)r�.s(Ar�c@s$eZdZdd�Zdd�Zdd�ZdS)�UntokenizeTestcCsnt�}d|_d|_|�t��
}|�d�Wd�n1swY|�|jjdd�|�t|jd�dS)Nr�)r�r�rz'start (1,3) precedes previous end (2,2))r�r�)	r�prev_row�prev_colr��
ValueError�add_whitespacer0�	exception�args)r3�u�cmr(r(r)�test_bad_input_order�s��z#UntokenizeTest.test_bad_input_ordercCsdt�}d|_d|_g|_|�d�|�|jdg�d|_|�d�|�|jgd��t�|d�dS)Nr�)r�r�\
r�)�r[)rZz\
\
rza
  b
    c
  \
  c
)rrQrRr;rTr0rvrw)r3rWr(r(r)�test_backslash_continuation�s

z*UntokenizeTest.test_backslash_continuationcCs�t�}tdf}tdf|g}|�|tg��|�|jdg�t�}|�|�t|g��d�t�}|�|�t|��d�|�|jd�|�tt|��d�dS)NZHellor-zHello sHello )	rrr�compat�iterr0r;rr�)r3rWr$r;r(r(r)�test_iter_compat�szUntokenizeTest.test_iter_compatN)rYrZr[rYr\r_r(r(r(r)rP�s
rPc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)rvcCs�t|t�r|�d�}n|��}|��t|jdd��j}tt	|��}dd�|D�}t
|�}t|jdd��j}dd�t	|�D�}|�||�t
|�}	t|	jdd��j}
dd�t	|
�D�}|�||�dS)	a)
        Test roundtrip for `untokenize`. `f` is an open file or a string.
        The source code in f is tokenized to both 5- and 2-tuples.
        Both sequences are converted back to source code via
        tokenize.untokenize(), and the latter tokenized again to 2-tuples.
        The test fails if the 3 pair tokenizations do not match.

        When untokenize bugs are fixed, untokenize with 5-tuples should
        reproduce code that does not contain a backslash continuation
        following spaces.  A proper test should test this.
        r-T)�keependscS�g|]}|dd��qS�Nr�r(��.0r?r(r(r)�
<listcomp>�z1TestRoundtrip.check_roundtrip.<locals>.<listcomp>cSrarbr(rcr(r(r)rerfcSrarbr(rcr(r(r)re
rfN)�
isinstancer�r.�read�closer^r �__next__r:rrr0)r3r6�coder/Ztokens5Ztokens2Zbytes_from2Z	readline2Z
tokens2_from2Zbytes_from5Z	readline5Z
tokens2_from5r(r(r)rw�s

zTestRoundtrip.check_roundtripcCs�|�d�|�d�|�d�t�d�}t|d��
}|�|�Wd�n1s)wY|�d�|�d�|�d�|�d	�dS)
Nzif x == 1:
    print(x)
z # This is a comment
# This also
zif x == 1 : 
  print(x)
�tokenize_tests.txtrpzoif 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')
)rwr�findfiler)r3�fnr6r(r(r)�test_roundtrip
s



�


zTestRoundtrip.test_roundtripcC�|�d�dS)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']
�rwrBr(r(r)�test_continuation4�zTestRoundtrip.test_continuationcCs|�d�|�d�dS)Nz)x=1+\
1
# This is a comment\
# This also
z# Comment \
x = 0rqrBr(r(r)r\As
z)TestRoundtrip.test_backslash_continuationcCrp)Nz'' ''rqrBr(r(r)�test_string_concatenationJrsz'TestRoundtrip.test_string_concatenationc
Csddl}ddl}t�d�}tj�|�ptj}|�tj�|�	|�d��}|�
tj�|d��dD]}|�
tj�|d�|�q/t�d�sI|�|d�}|D]<}tj
d	krWtd
|�t|d��#}|j|d��
|�|�Wd�n1sswYWd�n1s�wYqKdS)
Nrrlztest*.pyztest_unicode_identifiers.py)�bufferZbuiltinZfileio�inspectrq�platform�sysz
test_%s.pyZcpu�
r�rrpr�)�glob�randomrrmrqrrrt�curdirrs�escape�removeZis_resource_enabled�sample�verboser�rZsubTestrw)r3rzr{rn�tempdirZ	testfilesr6Ztestfiler(r(r)�test_random_filesNs(



�����zTestRoundtrip.test_random_filescCs,t|t�r
|�d�}ttt|�j���d�S)Nr-)rgr�r.rrrr/re)r3rkr(r(r)�	roundtripks

zTestRoundtrip.roundtripcCs6d}|�|��d�}|�|d|d�|�|�dS)z�
        Ensure that although whitespace might be mutated in a roundtrip,
        the semantic meaning of the indentation remains consistent.
        zif False:
	x=3
	x=3
rr�r�N)r��splitr0rw)r3rkZ	codelinesr(r(r)�#test_indentation_semantics_retainedpsz1TestRoundtrip.test_indentation_semantics_retainedN)rYrZr[rwrorrr\rtr�r�r�r(r(r(r)rv�s '
	rvc@r\)�CTokenizerBufferTestscCsZddd�ddd��}t���}t|d|�}t|�Wd�dS1s&wYdS)Nz"        #coding: latin-1
        #�ai'z

        #i'Zfoo)r�temp_dirrr)r3Ztest_scriptr��	file_namer(r(r)�!test_newline_at_the_end_of_buffer|s��

"�z7CTokenizerBufferTests.test_newline_at_the_end_of_bufferN)rYrZr[r�r(r(r(r)r�{r_r��__main__)2�testrZtest.supportrrrrrrr	r
rrr
rrr�rrr�iorrZunittest�textwraprrrZtest.test_grammarrrZtest.support.script_helperrrrqr$r*r,r]rjrkror�r�r�rPrvr�rY�mainr(r(r(r)�<module>sJD	%&)�