Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_string_literals.cpython-39.opt-1.pyc

a

XC?h�'�@srdZddlZddlZddlZddlZddlZddlZddlmZdZ	dd�Z
Gdd�dej�Ze
d	krne��dS)
a�Test correct treatment of various string literals by the parser.

There are four types of string literals:

    'abc'             -- normal str
    r'abc'            -- raw str
    b'xyz'            -- normal bytes
    br'xyz' | rb'xyz' -- raw bytes

The difference between normal and raw strings is of course that in a
raw string, \ escapes (while still used to determine the end of the
literal) are not interpreted, so that r'\x00' contains four
characters: a backslash, an x, and two zeros; while '\x00' contains a
single character (code point zero).

The tricky thing is what should happen when non-ASCII bytes are used
inside literals.  For bytes literals, this is considered illegal.  But
for str literals, those bytes are supposed to be decoded using the
encoding declared for the file (UTF-8 by default).

We have to test this with various file encodings.  We also test it with
exec()/eval(), which uses a different code path.

This file is really about correct treatment of encodings and
backslashes.  It doesn't concern itself with issues like single
vs. double quotes or singly- vs. triply-quoted strings: that's dealt
with elsewhere (I assume).
�N)�use_old_parsera�# coding: %s
a = 'x'
assert ord(a) == 120
b = '\x01'
assert ord(b) == 1
c = r'\x01'
assert list(map(ord, c)) == [92, 120, 48, 49]
d = '\x81'
assert ord(d) == 0x81
e = r'\x81'
assert list(map(ord, e)) == [92, 120, 56, 49]
f = '\u1881'
assert ord(f) == 0x1881
g = r'\u1881'
assert list(map(ord, g)) == [92, 117, 49, 56, 56, 49]
h = '\U0001d120'
assert ord(h) == 0x1d120
i = r'\U0001d120'
assert list(map(ord, i)) == [92, 85, 48, 48, 48, 49, 100, 49, 50, 48]
cCs
t|g�S�N)�bytes)�i�r�>/opt/alt/python39/lib64/python3.9/test/test_string_literals.py�byte=src@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd)dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S)*�TestLiteralscCs.tjdd�|_t��|_tj�d|j�dS)Nr)�sys�path�	save_path�tempfileZmkdtemp�tmpdir�insert��selfrrr�setUpCs
zTestLiterals.setUpcCs$|jtjdd�<tj|jdd�dS)NT)�
ignore_errors)rr
r�shutilZrmtreerrrrr�tearDownHszTestLiterals.tearDowncCstD]}qdSr)�TEMPLATE)r�crrr�
test_templateLszTestLiterals.test_templatecCs�|�td�d�|�td�td��|�td�td��|�td�td��|�td�td��|�td	�td
��|�td�td
��|�td�td
��|�td�td
��dS)Nz 'x' �xz '\x01' �z '' z '\x81' �u '' z
 '\u1881' �u 'ᢁ' z '\U0001d120' � �u '𝄠' ��assertEqual�eval�chrrrrr�test_eval_str_normalRsz!TestLiterals.test_eval_str_normalcCs�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd	�|�ttd
�|�ttd�|�ttd�|�ttd
�|�ttd�dS)Nz '\x' z '\x0' z '\u' z '\u0' z '\u00' z	 '\u000' z '\U' z '\U0' z '\U00' z	 '\U000' z
 '\U0000' z '\U00000' z '\U000000' z
 '\U0000000' ��assertRaises�SyntaxErrorr rrrr�test_eval_str_incomplete]sz%TestLiterals.test_eval_str_incompletec	Cs�tdd�D]T}|dvrq
|�t��,|�td|�dt|��Wd�q
1sT0Yq
tjdd��&}tjdtd	�td
�Wd�n1s�0Y|�t	|�d�|�|dj
d�|�|djd�tjdd��X}tjd
td	�|�t
��}td
�Wd�n1�s0Y|j}Wd�n1�sB0Y|�|g�|�|j
d�|�|jd�|�|jd�dS)Nr�s

"'01234567NU\abfnrtuvxz'\%c'�\T��record�always��categoryz	'''
\z'''r�<string>�error)�range�assertWarns�DeprecationWarningrr r!�warnings�catch_warnings�simplefilter�len�filename�linenor$r%�	exception�offset�r�b�w�cm�excrrr�test_eval_str_invalid_escapems(<&(&z)TestLiterals.test_eval_str_invalid_escapecCs�|�td�d�|�td�d�|�td�td��|�td�d�|�td	�td
��|�td�d�|�td
�td��|�td�d�|�td�td��dS)Nz r'x' rz	 r'\x01' z\x01z r'' rz	 r'\x81' z\x81u r'' rz r'\u1881' z\u1881u r'ᢁ' rz r'\U0001d120' z
\U0001d120u	 r'𝄠' rrrrrr�test_eval_str_raw�szTestLiterals.test_eval_str_rawcCs�|�td�d�|�td�td��|�td�td��|�td�td��|�ttd�|�td	�d
�|�ttd�|�td�d
�|�ttd�dS)Nz b'x' �xz	 b'\x01' rz b'' z	 b'\x81' ru b'' � br'\u1881' �\u1881u b'ᢁ' � br'\U0001d120' �
\U0001d120u	 b'𝄠' �rr rr$r%rrrr�test_eval_bytes_normal�sz#TestLiterals.test_eval_bytes_normalcCs |�ttd�|�ttd�dS)Nz b'\x' z b'\x0' r#rrrr�test_eval_bytes_incomplete�sz'TestLiterals.test_eval_bytes_incompletec	Cs�tdd�D]V}|dvrq
|�t��.|�td|�dt|g��Wd�q
1sV0Yq
tjdd��&}tjdtd	�td
�Wd�n1s�0Y|�t	|�d�|�|dj
d�t�r�|�|djd�tjdd��X}tjd
td	�|�
t��}td
�Wd�n1�s$0Y|j}Wd�n1�sJ0Y|�|g�|�|j
d�t��r�|�|jd�dS)Nrr's

"'01234567\abfnrtvxzb'\%c'�\Tr)r+r,z
b'''
\z'''rr.r/)r0r1r2rr rr3r4r5r6r7rr8r$r%r9r;rrr�test_eval_bytes_invalid_escape�s*>&(&z+TestLiterals.test_eval_bytes_invalid_escapecCst|�td�d�|�td�d�|�td�d�|�td�d�|�td�td��|�td	�td��|�td
�d�|�td�d�|�ttd
�|�ttd�|�td�d�|�td�d�|�ttd�|�ttd�|�td�d�|�td�d�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�dS)Nz br'x' rBz rb'x' z
 br'\x01' s\x01z
 rb'\x01' z br'' rz rb'' z
 br'\x81' s\x81z
 rb'\x81' u br'' u rb'' rCrDz rb'\u1881' u	 br'ᢁ' u	 rb'ᢁ' rErFz rb'\U0001d120' u
 br'𝄠' u
 rb'𝄠' z bb'' z rr'' z brr'' z bbr'' z rrb'' z rbb'' rGrrrr�test_eval_bytes_raw�s0z TestLiterals.test_eval_bytes_rawcCsl|�td�d�|�td�d�|�td�d�|�ttd�|�ttd�|�ttd�|�ttd	�dS)
Nz u'x' ru U'ä' �äu u'ä' z ur'' z ru'' z bu'' z ub'' )rr r$r%rrrr�test_eval_str_u�szTestLiterals.test_eval_str_u�cCsvd|�dd�}tj�|j|d�}t|d|d�}z$|�t|�|�|�W|��n
|��0t	|�t
j|=dS)NZxx_�-�_z.pyr=)�encoding)�replace�osr�joinr�open�writer�close�
__import__r
�modules)rrR�extra�modname�fn�frrr�check_encoding�szTestLiterals.check_encodingcCsd}|�d|�dS)Nu#z = 'ሴ'; assert ord(z) == 0x1234
�utf-8�r_�rr[rrr�test_file_utf_8�szTestLiterals.test_file_utf_8cCsd}|�t|jd|�dS)Nub'€'
r`)r$r%r_rbrrr�test_file_utf_8_error�sz"TestLiterals.test_file_utf_8_errorcCs|�d�dS)Nr`rarrrr�test_file_utf8�szTestLiterals.test_file_utf8cCs|�d�dS)Nz
iso-8859-1rarrrr�test_file_iso_8859_1�sz!TestLiterals.test_file_iso_8859_1cCs|�d�dS)Nzlatin-1rarrrr�test_file_latin_1�szTestLiterals.test_file_latin_1cCs|�d�dS)N�latin9rarrrr�test_file_latin9�szTestLiterals.test_file_latin9N)rO)�__name__�
__module__�__qualname__rrrr"r&r@rArHrIrKrLrNr_rcrdrerfrgrirrrrr	As&	
r	�__main__)�__doc__rTr
rr
Zunittestr3Ztest.supportrrrZTestCaser	rj�mainrrrr�<module>s<