python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_cgi.cpython-312.opt-2.pyc

͑eYddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZejdZGddZee_Gd	d
ZdZdifd
edfdedfdifdifdddgifdedfdedfdedfdddgifdddgifdddgifdddgifdedfd ed!fd"d#gd$gd%fd&dd#d'gifd(d)gd*gd+gd,fd-d.gd/gd0gd1gd2gd3gd4gd5gd6fd7d8gd9gd:gd)gd;gd<gd=fgZd>Zd?Zd@ZdAZGdBdCej0ZdDZdEZdFZdGZdHZedIk(rej@yy)JN)
namedtuple)StringIOBytesIO)support)warnings_helpercgic(eZdZgZej
Zy)HackedSysModuleN)__name__
__module____qualname__argvsysstdinA/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_cgi.pyr
r

sDIIErr
c$eZdZdZdZdZdZy)ComparableExceptionc||_yN)err)selfrs  r__init__zComparableException.__init__s	rc,t|jSr)strrrs r__str__zComparableException.__str__s488}rct|tstS|jj|jk(xr#|jj
|j
k(Sr)
isinstance	ExceptionNotImplementedr	__class__args)ranExcs  r__eq__zComparableException.__eq__sF%+!!""eoo5,

+	-rc.t|j|Sr)getattrr)rattrs  r__getattr__zComparableException.__getattr__"stxx&&rN)rrr
rrr&r*rrrrrs-'rrc<i}|dk(r
d}d|d<||d<nO|dk(r<t|jd}d|d<d|d<tt||d<nt	d	|z	t
j
||d
S#t$r}t|cYd}~Sd}~wwxYw)NGETREQUEST_METHODQUERY_STRINGPOSTlatin-1!application/x-www-form-urlencodedCONTENT_TYPECONTENT_LENGTHzunknown method: %s)strict_parsing)	rencoderlen
ValueErrorrparser!r)bufmethodenvfprs     rdo_testr>%s
C

 %!N	6	
SZZ	*
+ &AN #CH
-677(yySy33("3''(s%A==	B
BBB&bad query field: ''z&&=z=&=z=aaz&=az=a&z=&abad query field: 'a'zb=abzb+=azb za=b=aza=+b=az b=az&b=azb&=abad query field: 'b'za=a+b&b=b+ca bb crCrEza=a+b&a=b+ab azx=1&y=2.0&z=2-3.%2b012.02-3.+0xyzzHbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env400006r	964546263z
130003.300038zen-US 0bb2e248638833d48cb7fed300000f1br<bustomer)z1Hbc5161168c542333633315dee1182227:key_store_seqidcuyerexpirekidlobaleorder_idssviewzQgroup_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=BrowseBrowse313921005470custom)SUBMIT_assigned_to	_category_statusgroup_idsetc$t|tS)N)key)sortedrepr)seqs rnormrnas#4  rc2|Dcgc]}|d	c}Scc}wNrrlistps  r
first_eltsrtdsQAaDscB|Dcgc]}|d|ddfc}Scc}w)Nrr4rrqs  rfirst_second_eltsrvgs&%)*QqT1Q47O***sc>d}t|j|}|jdtj	|||}i}t|j
D]9\}}t|txr|j|xs|j||<;|S)Nr0r)r=environencoding)rr6seekrFieldStoragedictitemsr rrgetlistvalue)datarxry
fake_stdinformresultkvs        r
gen_resultrjsHX./JOOAz7XND
FT
  "G1q$';DLLOFqwwq	GMrceZdZdZdZdZdZdZdZdZ	e
jed	Z
d
ZdZdZd
ZdZdZdZdZdZdddgdddZdZdZdZdZdZdZy) CgiTestscttjd}tjddd}tj||}dgdgdgdgd}|j
||y)	Nlatin1558boundaryzCONTENT-LENGTH Add 1234
Testing 123.
r?)submitidfiletitle)rPOSTDATAr6BOUNDARYrparse_multipartassertEqual)rr=r<rexpecteds     rtest_parse_multipartzCgiTests.test_parse_multipartxsh
X__X.
/#??84!&($$R-&ix./2$@*rcd}t|jd}ddjdi}tj||}ddgi}|j	||y)NzY--JfISa01
Content-Disposition: form-data; name="submit-name"

just a string

--JfISa01--
rrJfISa01submit-namezjust a string
)rr6rrr)rrr=r<rrs      r+test_parse_multipart_without_content_lengthz4CgiTests.test_parse_multipart_without_content_lengthscX__X.
/9++H56$$R-!$5#67*rcxd}d}t|jd}|jdtt|jdd}tj||dd}d	d
gi}|j
|||j
djd|d	djddy)
Nru]--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 3

☃
--JfISa01utf8rrasciisurrogateescape)ryerrorsru	u☃r)rr6rr7rrr)rrrr=r<rrs       r%test_parse_multipart_invalid_encodingz.CgiTests.test_parse_multipart_invalid_encodings
X__V,
-#??84!$S)@%A!BD$$Rw,=%?!$8#9:*0
.q188ARS	Urc`tj}|j||jdt	||jt
|t
|j|jjtddd|j|y)Nr{MockFieldStoragename
fieldvalue)rr{assertFalseassertInrlrrrkeysappendr
assertTruerfss  rtest_fieldstorage_propertiesz%CgiTests.test_fieldstorage_propertiessz





nd2h/b4	?3
=z"4f=lKLrc|jttjdddi|jttjddtjddi	}|jtt|y)
Nznot-a-file-objr-PUTrxfoobarzcontent-type
text/plain)headers)assertRaises	TypeErrorrr{boolrs  rtest_fieldstorage_invalidz"CgiTests.test_fieldstorage_invalidsp)S%5%57GEUV[D\		^)S%5%5ueD


~l&C

D)T2.rc	tD]{\}}t|d}|j||dt|zt|d}|j||dt|zd|i}tj|}t
|ts|jt|t||j|j|j|j|jddd|jD]m}||}|j||t|d	kDr"|j|j||J|j|j||d
o~y)Nr,zError parsing %s method GETr/zError parsing %s method POSTr.rznonexistent fielddefaultr4r)
parse_strict_test_casesr>rrlrr{r r|r7assertCountEqualrgetvaluer)rorigexpectdr<rrj
expect_vals        rtest_strictzCgiTests.test_strictsP3	JLD&e$AQ(ET
(RSf%AQ(Fd(ST!4(C!!#!.B&$'  Vc"g6%%fkkmRWWY?  -@)!LiX!;;=JC!'JMM#r*:*((S)9:F((S)9:a=I
J#	Jrc.ddgdgdfddgdgdgdfdtd	fd
td	fdtdfd
td	fdtdfddgdgdfddddgifg	}|D]\}}d|i}tjd|}t|ts2|jD]m}||}|j
||t|dkDr"|j|j||J|j|j||doy)Nz	x=1;y=2.0rKrL)rOrPzx=1;y=2.0;z=2-3.%2b0rMrN;rAz;;z=;arDz;b=azb;=arFza=a+b;b=b+crGrHrIza=a+b;a=b+arCrJr.)	separatorrxr4r)
r8rr{r r|rrr7rr)rparse_semicolonrrr<rrjrs        rtest_separatorzCgiTests.test_separatorsG
UG45
#C5whZ%PQ
*234
:345
J567
Z 567
Z 678
5'89
S5%.12

,
	JLD&!4(C!!C!=B&$'!;;=JC!'JMM#r*:*((S)9:F((S)9:a=I
J	
	Jr)categoryc@tjdtt_tj	ddtjdd|jtjj
dtjjtjrodt_tjt_tj	dd|jtjtjdyy)NTestingz%szTesting initlog 1z
Testing log 2z Testing initlog 1
Testing log 2
z
Testing log 3z
Testing log 4)rlogrlogfpinitlogrrospathexistsdevnulllogfile
addCleanupcloselogrs rtest_logzCgiTests.test_logs	J	D-.o&++-/ST
77>>"**%CI**CKKKo.OOCLL)GGO$&rcGdd}|tjd}|j|j|j	ddz|jdddi}tj||	}|j|jj|j|jd
|jy)Nc eZdZdZddZdZy)=CgiTests.test_fieldstorage_readline.<locals>.TestReadlineFilec ||_d|_yrp)rnumcalls)rrs  rrzFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__init__s 	 !
rNc|xjdz
c_|r|jj|S|jjS)Nr4)rrreadline)rsizes  rrzFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.readlines;

"
99--d3399--//rcv|jd}t||}t|ts
t	||||S)Nr)__dict__r(r intsetattr)rrrrCs    rr*zICgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__getattr__s7}}V,D$'!!S)D$*rr)rrr
rrr*rrrTestReadlineFilers
"
0
rrzwb+sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxirr-rr=rx)tempfile
TemporaryFilerclosewriterzrr{r
assertGreaterr)rrfr<rs     rtest_fieldstorage_readlinez#CgiTests.test_fieldstorage_readlines
		&
X33E:; 	
T!"	q	&


C

0

&	
1::q)		rcddjtdd}ttj	d}t
j
||d}|jt|jdddd	d
dddd
d
ddd
dddd
g}tt|jD]H}||jD]0\}}t|j||}|j||2Jy)Nr/ multipart/form-data; boundary={}rr-r2r3r0rxryrrrfilenamerrr?rtest.txtrrr
formatrrrr6rr{rr7rrranger}r(	rr<r=rrrOrexpgots	         rtest_fieldstorage_multipartz$CgiTests.test_fieldstorage_multiparts%>EEhO#%X__Y/
0


b#	

BRWWq)4@!dB? ZARS"tWEGs277|$	+A )//+
+3bggaj!,  c*
+	+rcddjtdd}tdtj	dz}t
j
||d}|jt|jdd	dd
dddd
dddddddddg}tt|jD]H}||jD]0\}}t|j||}|j||2Jy)Nr/r560rs
r0rrrrrrr?rrrrrrrs	         r.test_fieldstorage_multipart_leading_whitespacez7CgiTests.test_fieldstorage_multipart_leading_whitespace(s$>EEhO#%Wxy99
:


b#	

BRWWq)4@!dB? ZARS"tWEGs277|$	+A )//+
+3bggaj!,  c*
+	+rcddjtdd}dD]}ttj	|}t
j
|||}|jt|jdddd	d
g}tt|jD]H}||jD]0\}}t|j||}	|j|	|2Jy)Nr/rrr)z
iso-8859-1zutf-8rr4ruçñ€r)
rrrPOSTDATA_NON_ASCIIr6rr{rr7rrrr}r()
rr<ryr=rrrOrrrs
          r%test_fieldstorage_multipart_non_asciiz.CgiTests.test_fieldstorage_multipart_non_ascii;s &>EEhO"$/	/H+228<=B!!"c8!DBS\1-"t^LMF3rww<(
/$Qioo//FAs!"''!*a0C$$S#./
/	/rcd}d_fd}|d|dz
z|d|dz
zdz|d|dz
zdzd|dz
zzy)Nicdjdd|z}tt|ddd}jt	||d|jdiy)	Nzp---123
Content-Disposition: form-data; name="upload"; filename="fake.txt"
Content-Type: text/plain

%s
---123--

z
"multipart/form-data; boundary=-123r/r3r2r-uploadr)replacerr7rrr6)contentrrxrs   rcheckz;CgiTests.test_fieldstorage_multipart_maxline.<locals>.checkNsdGD&G
$D%(D	N$H$*G

Zg6&x(@A
CrrOr4
rP)maxDiff)rmaxliners`  r#test_fieldstorage_multipart_maxlinez,CgiTests.test_fieldstorage_multipart_maxlineJsb	C	cWq[!"
cWq[!D()
cWq[!D(3'A++>>?rc8ddjttttd}ttj
d}tj||d}|jt|jd|j|jdjd|j|jdjd	|j|jd
jd|jd
j}|jt|dddd
dddddg}tt|D]>}||jD]&\}}t|||}	|j|	|(@y)Nr/rrr0rrrrLarryr4filesz	file1.txts... contents of file1.txt ...rz	file2.gifs...contents of file2.gif...)rBOUNDARY_W3rr7POSTDATA_W3rr6rr{rrrrrrr}r()
rr<r=rrrrOrrrs
          rtest_fieldstorage_multipart_w3cz(CgiTests.test_fieldstorage_multipart_w3cas`%>EEkR!#k"235[''	2
3


b#	

BRWWq)-8))73'2
  UQ'[Ccd[Cabds5z"	+A )//+
+3eAh*  c*
+	+rcd}d}ddj|tt|d}t|j	d}t
j
||d}|jt|jd|j|jd	jd
|j|jd	jdy)Nrz_--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 5

Larry
--JfISa01r/rrr0rr4rrr)rrr7rr6rr{rrrrr)rrrr<r=rs      r%test_fieldstorage_part_content_lengthz.CgiTests.test_fieldstorage_part_content_lengthvs
%>EEhO!#h-02X__Y/
0


b#	

BRWWq)-8))73rctd}dd|d}tj||}|jt	|dj
j
dy)Nsa--MyBoundary
Content-Disposition: form-data; name="my-arg"; filename="foo"

Test

--MyBoundary--
r/z(multipart/form-data; boundary=MyBoundary)r-r2z
wsgi.inputrzmy-arg)rrr{rr7rread)rr=r<fieldss    r.test_field_storage_multipart_no_content_lengthz7CgiTests.test_field_storage_multipart_no_content_lengthsc
%F

!!"c!2VH-22779:A>rctd}ddi}tj||5}|jj	}|j|jjddd|jjj|jd|jtd5|jj	dddy#1swYzxYw#1swYyxYw)Ns
xxxxxxxxxxr-rr
xxxxxxxxxxzI/O operation on closed file)rrr{rrrclosedrrassertRaisesRegexr8)rr=r<rrs     r$test_fieldstorage_as_context_managerz-CgiTests.test_fieldstorage_as_context_managers
Y
'


S

1	-RggllnGRWW^^,	-	
'(+

#
#J0N
O	GGLLN			-	-
		sAC <C, C),C5value1value2xvalue2yvalue3value4)key1key2key3key4cd}tt|dddd}t||}|j|j|y)Nz$key2=value2x&key3=value3&key4=value4r1zkey1=value1&key2=value2yr/r3r2r.r-rr7rr
_qs_resultrrrxrs    rtestQSAndUrlEncodezCgiTests.testQSAndUrlEncodesD5 #CI C : &	

tW%!,rcVdjdgdz}tt|ddd}|jt5t
j
t|j|ddddd	}tt|d
ddd}|jt5t
j
t|j|d
dddt
j
t|j|dy#1swYxYw#1swYExYw)Nr@za=ar1r/r
)r=rxmax_num_fieldsz---123
Content-Disposition: form-data; name="a"

3
---123
Content-Type: application/x-www-form-urlencoded

a=4
---123
Content-Type: application/x-www-form-urlencoded

a=5
---123--
rza=1&a=2r-rr)	joinrr7rr8rr{rr6)rrrxs   rtest_max_num_fieldszCgiTests.test_max_num_fieldssxx
#!#d)n?$


z
*	4;;=)!

	
!$CI D ) &	


z
*	4;;=) 

		t{{}%		
O		B		s0D+0DDD(cd}tt|dddd}t||}|j|j|y)Nz---123
Content-Disposition: form-data; name="key2"

value2y
---123
Content-Disposition: form-data; name="key3"

value3
---123
Content-Disposition: form-data; name="key4"

value4
---123--
rkey1=value1&key2=value2xr/r-r.r0s    rtestQSAndFormDatazCgiTests.testQSAndFormDatasH
!$CI D : &	

tW%!,rcd}tt|dddd}|jj}|j	ddit||}|j
||y)NaE---123
Content-Disposition: form-data; name="key2"

value2y
---123
Content-Disposition: form-data; name="key3"

value3
---123
Content-Disposition: form-data; name="key4"

value4
---123
Content-Disposition: form-data; name="upload"; filename="fake.txt"
Content-Type: text/plain

this is the content of the fake file

---123--
rr9r/r-r	s%this is the content of the fake file
)rr7r/copyupdaterr)rrrxrrs     rtestQSAndFormDataFilezCgiTests.testQSAndFormDataFileso*!$CI D : &	
%%'

?
	
tW%#rc|jtjddif|jtjddif|jtjddddif|jtjddddif|jtjdddd	d
f|jtjddd
dif|jtjddd
dif|jtjdddddf|jtjdddddfy)Nrztext/vnd.just.made.this.up ; ztext/vnd.just.made.this.upztext/plain;charset=us-asciicharsetzus-asciiztext/plain ; charset="us-ascii"z,text/plain ; charset="us-ascii"; another=optopt)r@anotherz attachment; filename="silly.txt"
attachmentrz	silly.txtz#attachment; filename="strange;name"zstrange;namez-attachment; filename="strange;name";size=123;123)rrz-form-data; name="files"; filename="fo\"o;bar"z	form-datarzfo"o;bar)rr)rrparse_headerrs rtest_parse_headerzCgiTests.test_parse_header%s\*
2	 	
<=
)2.	0	
:;
Iz23	5	
>?
Iz23	5	
KL
zeDE	G	
?@
J45	7	
BC
J78	:	
LM
FG	I	
MN
7
CD	FrcDhd}tj|t|y)N>	rdologrnologmaxlenrrrvalid_boundary)not_exported)rcheck__all__r)rrLs  rtest_allzCgiTests.test_allBs(	T3\BrN)rrr
rrrrrrrrignore_warningsDeprecationWarningrrrrrrrrrr"r/r1r7r:r>rFrNrrrrrvs++U$/J4J0%_$$.@A%B%#J+$+&
/@.+*4$?"	I&	J	-4
l-0 $DF:Crrz6---------------------------721837373350705526688164684a-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="id"

1234
-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="title"


-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

Testing 123.

-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="submit"

 Add 
-----------------------------721837373350705526688164684--
u-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="id"

çñ€
-----------------------------721837373350705526688164684
AaB03xa--AaB03x
Content-Disposition: form-data; name="submit-name"

Larry
--AaB03x
Content-Disposition: form-data; name="files"
Content-Type: multipart/mixed; boundary=BbC04y

--BbC04y
Content-Disposition: file; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--BbC04y
Content-Disposition: file; filename="file2.gif"
Content-Type: image/gif
Content-Transfer-Encoding: binary

...contents of file2.gif...
--BbC04y--
--AaB03x--
__main__)!rrrunittestcollectionsriorrtestrtest.supportrimport_deprecatedrr
rr>r8rrnrtrvrTestCaserrrrrrrmainrrr<module>r[s&	
" ('o''.
'' (&H**
+,	:+,-"I
BK	B;
J,-.
J,-.
J-./
S3%LdSE]sUGn
fXZ-
./Z.
/05'01S5%.)*C5whZHIw<D:u

	56
Gl		Y
i7(Z	A(T! +
PCx  PCfD*.zHMMOr