python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_string_literals.cpython-312.pyc

Αe.2dZddlZddlZddlZddlZddlZddlZdZdZGddejZ
edk(rejyy)aTest 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]
ct|gS)N)bytes)is M/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_string_literals.pybyter<s!:ceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZddZdZdZdZdZdZdZy)TestLiteralsctjdd|_tj|_tjj
d|j
y)Nr)syspath	save_pathtempfilemkdtemptmpdirinsertselfs rsetUpzTestLiterals.setUpBs7!&&(4;;'rc|jtjddtj|j
dy)NT)
ignore_errors)rrr
shutilrmtreerrs rtearDownzTestLiterals.tearDownGs%nn

dkk6rc`tD]%}|dk(r	d|cxkrdkrnJt|y)N
 ~)TEMPLATErepr)rcs  r
test_templatezTestLiterals.test_templateKs0	9A9qC8a8	9rcz|jtdd|jtdtd|jtdtd|jtdtd|jtdtd|jtd	td
|jtdtd
|jtdtd
|jtdtd
y)Nz 'x' xz '\x01' z '' z '\x81' u '' z
 '\u1881' u 'ᢁ' z '\U0001d120'  u '𝄠' assertEqualevalchrrs rtest_eval_str_normalz!TestLiterals.test_eval_str_normalQsk*C0o.A7n-s1v6o.D	:n-s4y9/0#f+>./V=34c'lC23S\Brc|jttd|jttd|jttd|jttd|jttd|jttd|jttd|jttd|jttd	|jttd
|jttd|jttd|jttd
|jttdy)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' assertRaisesSyntaxErrorr+rs rtest_eval_str_incompletez%TestLiterals.test_eval_str_incomplete\s+t];+t^<+t];+t^<+t_=+t-=>+t];+t^<+t_=+t-=>+t->?+t-?@+t-@A+t-ABrc	tddD]O}|dvr|jt5|jt	d|zdt|zdddQt
jd5}t
jdt	t	d
ddd|jtd|jt|djd|j|djd
|j|djdt
jd5}t
jdt	|jt5}t	d
dddj }ddd|j|g|jj"d|j|jd
|j|jd|j|j$dy#1swYxYw#1swYxYw#1swYxYw#1swYxYw)Nr%s

"'01234567NU\abfnrtuvxz'\%c'\Trecordalwayscategoryz	'''
\z'''rinvalid escape sequence '\z'<string>errorrangeassertWarns
SyntaxWarningr*r+r,warningscatch_warningssimplefilterlenstrmessagefilenamelinenor0r1	exceptionmsgoffsetrbwcmexcs     rtest_eval_str_invalid_escapez)TestLiterals.test_eval_str_invalid_escapelsq#	DA66!!-0
D  hl!3TCF]C
D
D	D
$
$D
1	 Q!!(]C	 	
Q#QqT\\*,KL1
31a(

$
$D
1	Q!!'MB"";/
$2]#
$,,C		
	
B"ABz2Q'Q')
D
D	 	 
$
$		s;+H5'H$;1H=,H18H=H!	$H.1H:	6H==IctddD]G}|jt5|jt	d|zt|dddIt
jd5}t
jdtt	dddd|jtd	|jt|d
jd|j|d
jd|j|d
jd	t
jd5}t
jd
t|jt5}t	ddddj }ddd|j|g|jj"d|j|jd|j|jd	|j|j$d	y#1swYxYw#1swYxYw#1swYxYw#1swYxYw)Nz'\%o'Tr6r8r9z'''
\407'''r%r$invalid octal escape sequence '\407'r<r=r>rrrOrPrQs     r"test_eval_str_invalid_octal_escapez/TestLiterals.test_eval_str_invalid_octal_escapesuf%	=A!!-0
=  hl!3SV<
=
=	=
$
$D
1	"Q!!(]C!	"	
Q#QqT\\*@	B1
31a(

$
$D
1	Q!!'MB"";/
&2_%
&,,C		
	
B"IJz2Q'Q'+
=
=	"	"
&
&		s;(H-'H31H5$H)0H5H	H&)H2	.H55H>c2|jtdd|jtdd|jtdtd|jtdd|jtd	td
|jtdd|jtd
td|jtdd|jtdtdy)Nz r'x' r$z	 r'\x01' \x01z r'' r%z	 r'\x81' z\x81u r'' r&z r'\u1881' z\u1881u r'ᢁ' r'z r'\U0001d120' z
\U0001d120u	 r'𝄠' r(r)rs rtest_eval_str_rawzTestLiterals.test_eval_str_rawsl+S1./>o.A7./>o.D	:01>B/0#f+>457IJ34c'lCrc |jtdd|jtdtd|jtdtd|jtdtd|jttd|jtd	d
|jttd|jtdd
|jttdy)Nz b'x' xz	 b'\x01' r%z b'' z	 b'\x81' r&u b''  br'\u1881' \u1881u b'ᢁ'  br'\U0001d120' 
\U0001d120u	 b'𝄠' r*r+rr0r1rs rtest_eval_bytes_normalz#TestLiterals.test_eval_bytes_normalsl+T2./a9o.Q8./d<+t_=124DE+t->?568LM+t-BCrcp|jttd|jttdy)Nz b'\x' z b'\x0' r/rs rtest_eval_bytes_incompletez'TestLiterals.test_eval_bytes_incompletes&+t^<+t_=rc	\tddD]P}|dvr|jt5|jt	d|zdt|gzdddRt
jd5}t
jdt	t	d
ddd|jtd|jt|djd|j|djd
|j|djdt
jd5}t
jdt	|jt5}t	d
dddj }ddd|j|g|jj"d|j|jd
|j|jdy#1swYxYw#1swYnxYw#1swYxYw#1swYxYw)Nr%r4s

"'01234567\abfnrtvxzb'\%c'\Tr6r8r9z
b'''
\z'''rr;r<r=r?r@rAr*r+rrBrCrDrErFrGrHrIr0r1rJrKrMs     rtest_eval_bytes_invalid_escapez+TestLiterals.test_eval_bytes_invalid_escapesq#	JA33!!-0
J  i!m!4eeQCj6HI
J
J	J
$
$D
1	!Q!!(]C 	!	
Q#QqT\\*,KL1
31a(

$
$D
1	Q!!'MB"";/
%2^$
%,,C		
	
B"ABz2Q''
J
J	!	!
%
%		s;,G<6'H	<1H"-H9H"<H		HH	H""H+c	RtddD]K}|jt5|jt	d|zt|dzgdddMt
jd5}t
jdtt	d	ddd|jtd
|jt|djd|j|djd
|j|djd
t
jd5}t
jdt|jt5}t	d	dddj }ddd|j|g|jj"d|j|jd
|j|jd
y#1swYxYw#1swYnxYw#1swYxYw#1swYxYw)NrTrUzb'\%o'Tr6r8r9zb'''
\407'''r%rrVr<r=rhrWs     r$test_eval_bytes_invalid_octal_escapez1TestLiterals.test_eval_bytes_invalid_octal_escapesuf%	JA!!-0
J  i!m!4eQYK6HI
J
J	J
$
$D
1	#Q!!(]C!"	#	
Q#QqT\\*@	B1
31a(

$
$D
1	Q!!'MB"";/
'2%&
',,C		
	
B"IJz2Q')
J
J	#	#
'
'		s;,G71'H71H(H4H7H	HH	HH&c8|jtdd|jtdd|jtdd|jtdd|jtdtd|jtd	td|jtd
d|jtdd|jttd
|jttd|jtdd|jtdd|jttd|jttd|jtdd|jtdd|jttd|jttd|jttd|jttd|jttd|jttd|jttd|jttdy)Nz br'x' r]z rb'x' z
 br'\x01' \x01z
 rb'\x01' z br'' r%z rb'' z
 br'\x81' s\x81z
 rb'\x81' u br'' u rb'' r^r_z rb'\u1881' u	 br'ᢁ' u	 rb'ᢁ' r`raz rb'\U0001d120' u
 br'𝄠' u
 rb'𝄠' z bb'' z rr'' z brr'' z bbr'' z rrb'' z rbb'' rbrs rtest_eval_bytes_rawz TestLiterals.test_eval_bytes_rawsm,d3m,d3/0.A/0.A./a9./a9/0.A/0.A+t-=>+t-=>124DE124DE+t-?@+t-?@568LM568LM+t-CD+t-CD+t\:+t\:+t];+t];+t];+t];rc~|jtdd|jtdd|jtdd|jttd|jttd|jttd|jttd	y)
Nz u'x' r$u U'ä' äu u'ä' z ur'' z ru'' z bu'' z ub'' )r*r+r0r1rs rtest_eval_str_uzTestLiterals.test_eval_str_usl+S1/0$7PQSWX+t\:+t\:+t\:+t\:rc|jtdd|jtdd|jtdd|jtdd|jtd	d
y)Nz B'x' r]z	 R'\x01' rZz
 BR'\x01' rnz
 F'{1+1}' z U'\U0001d120' u𝄠)r*r+rs rtest_uppercase_prefixesz$TestLiterals.test_uppercase_prefixes
sql+T2./9/0(;./C5:45}Erczd|jddz}tjj|j|dz}t|d|}	|j
t|z|j
||jt|tj|=y#|jwxYw)Nxx_-_z.pyrO)encoding)replaceosr
joinropenwriterclose
__import__rmodules)rrzextramodnamefnfs      rcheck_encodingzTestLiterals.check_encodings(**344
WW\\$++w
7S8,	
GGHx'(
GGEN
GGI7KK 
GGIs)B((B:c,d}|jd|y)Nu#z = 'ሴ'; assert ord(z) == 0x1234
utf-8rrrs  rtest_file_utf_8zTestLiterals.test_file_utf_8 s9GU+rcLd}|jt|jd|y)Nub'€'
r)r0r1rrs  rtest_file_utf_8_errorz"TestLiterals.test_file_utf_8_error$s!+t':':GUKrc&|jdy)Nrrrs rtest_file_utf8zTestLiterals.test_file_utf8(sG$rc&|jdy)Nz
iso-8859-1rrs rtest_file_iso_8859_1z!TestLiterals.test_file_iso_8859_1+sL)rc&|jdy)Nzlatin-1rrs rtest_file_latin_1zTestLiterals.test_file_latin_1.sI&rc&|jdy)Nlatin9rrs rtest_file_latin9zTestLiterals.test_file_latin91sH%rN))__name__
__module____qualname__rrr"r-r2rRrXr[rcrerirlrorrrurrrrrrrrrr
r
@sv(
79	CC (4(2	D	D>(2(0<4;F
!,L%*'&rr
__main__)
__doc__r|rrrunittestrBrrTestCaser
rmainrrr<module>rsY:


,r&8$$r&jzHMMOr