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_string_literals.cpython-310.opt-1.pyc
o

�i�(�@sjdZddlZddlZddlZddlZddlZddlZdZdd�ZGdd�dej	�Z
edkr3e��dSdS)	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).
�Na�# 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�6/usr/local/lib/python3.10/test/test_string_literals.py�byte<s
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd+dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S),�TestLiteralscCs.tjdd�|_t��|_tj�d|j�dS)Nr)�sys�path�	save_path�tempfile�mkdtemp�tmpdir�insert��selfrrr�setUpBs
zTestLiterals.setUpcCs$|jtjdd�<tj|jdd�dS)NT)�
ignore_errors)rr	r
�shutil�rmtreerrrrr�tearDownGszTestLiterals.tearDowncCstD]}qdSr)�TEMPLATE)r�crrr�
test_templateKszTestLiterals.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_normalQsz!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]*}|dvrq|�t��|�td|�dt|��Wd�n1s*wYqtjdd��}tjdtd	�td
�Wd�n1sLwY|�t	|�d�|�|dj
d�|�|djd�tjdd��+}tjd
td	�|�t
��}td
�Wd�n1s�wY|j}Wd�n1s�wY|�|g�|�|j
d�|�|jd�|�|jd�dS)Nr�s

"'01234567NU\abfnrtuvxz'\%c'�\T��record�always��categoryz	'''
\z'''r�<string>�error)�range�assertWarns�DeprecationWarningr r!r"�warnings�catch_warnings�simplefilter�len�filename�linenor%r&�	exception�offset�r�b�w�cm�excrrr�test_eval_str_invalid_escapels2��
�
��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' �\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'𝄠' �r r!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	Csvtdd�D]+}|dvrq|�t��|�td|�dt|g��Wd�n1s+wYqtjdd��}tjdtd	�td
�Wd�n1sMwY|�t	|�d�|�|dj
d�|�|djd�tjdd��+}tjd
td	�|�t
��}td
�Wd�n1s�wY|j}Wd�n1s�wY|�|g�|�|j
d�|�|jd�dS)Nrr(s

"'01234567\abfnrtvxzb'\%c'�\Tr*r,r-z
b'''
\z'''rr/r0)r1r2r3r r!rr4r5r6r7r8r9r%r&r:r<rrr�test_eval_bytes_invalid_escape�s0 ��
�
��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' rDz rb'x' z
 br'\x01' �\x01z
 rb'\x01' z br'' rz rb'' z
 br'\x81' s\x81z
 rb'\x81' u br'' u rb'' rErFz rb'\u1881' u	 br'ᢁ' u	 rb'ᢁ' rGrHz rb'\U0001d120' u
 br'𝄠' u
 rb'𝄠' z bb'' z rr'' z brr'' z bbr'' z rrb'' z rbb'' rIrrrr�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'' )r r!r%r&rrrr�test_eval_str_u�szTestLiterals.test_eval_str_ucCsV|�td�d�|�td�d�|�td�d�|�td�d��|�td	�d
�dS)Nz B'x' rDz	 R'\x01' rBz
 BR'\x01' rNz
 F'{1+1}' �z U'\U0001d120' u𝄠)r r!rrrr�test_uppercase_prefixes�s
z$TestLiterals.test_uppercase_prefixes�cCsvd|�dd�}tj�|j|d�}t|d|d�}z|�t|�|�|�W|��n|��wt	|�t
j|=dS)NZxx_�-�_z.pyr>)�encoding)�replace�osr
�joinr�open�writer�close�
__import__r	�modules)rrW�extra�modname�fn�frrr�check_encoding�szTestLiterals.check_encodingcCsd}|�d|�dS)Nu#z = 'ሴ'; assert ord(z) == 0x1234
�utf-8�rd�rr`rrr�test_file_utf_8�szTestLiterals.test_file_utf_8cCsd}|�t|jd|�dS)Nub'€'
re)r%r&rdrgrrr�test_file_utf_8_error�sz"TestLiterals.test_file_utf_8_errorcC�|�d�dS)Nrerfrrrr�test_file_utf8��zTestLiterals.test_file_utf8cCrj)Nz
iso-8859-1rfrrrr�test_file_iso_8859_1�rlz!TestLiterals.test_file_iso_8859_1cCrj)Nzlatin-1rfrrrr�test_file_latin_1�rlzTestLiterals.test_file_latin_1cCrj)N�latin9rfrrrr�test_file_latin9�rlzTestLiterals.test_file_latin9N)rT)�__name__�
__module__�__qualname__rrrr#r'rArCrJrKrMrOrQrSrdrhrirkrmrnrprrrrr@s*	
r�__main__)
�__doc__rYr	rrZunittestr4rrZTestCaserrq�mainrrrr�<module>sA�