Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib64/python3.7/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/test/__pycache__/test_cgi.cpython-37.pyc

B

� f�]�@sddlmZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZGdd�d�Ze�e_Gdd	�d	�Zd
d�Zded
�fded
�fded
�fdifdifdddgifded
�fded
�fded�fdddgifdddgifdddgifdddgifded
�fd ed!�fd"d#gd$gd%�fd&dd#d'gifd(d)gd*gd+gd,�fd-d.gd/gd0gd1gd2gd3gd4gd5gd6�fd7d8gd9gd:gd)gd;gd<gd=�fgZd>d?�Zd@dA�ZdBdC�ZdDdE�ZGdFdG�dGej�ZdHZdIZdJZdKZdLZedMk�r�e� �dS)N�)�check_warningsN)�
namedtuple)�StringIO�BytesIO)�supportc@seZdZgZejZdS)�HackedSysModuleN)�__name__�
__module__�__qualname__�argv�sys�stdin�rr�2/opt/alt/python37/lib64/python3.7/test/test_cgi.pyrsrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ComparableExceptioncCs
||_dS)N)�err)�selfrrrr�__init__szComparableException.__init__cCs
t|j�S)N)�strr)rrrr�__str__szComparableException.__str__cCs*t|t�stS|jj|jko(|jj|jkS)N)�
isinstance�	Exception�NotImplementedr�	__class__�args)rZanExcrrr�__eq__s
zComparableException.__eq__cCst|j|�S)N)�getattrr)r�attrrrr�__getattr__!szComparableException.__getattr__N)rr	r
rrrrrrrrrsrc
Cs�i}|dkr"d}d|d<||d<nD|dkrZt|�d��}d|d<d|d<tt|��|d<ntd	|��ytj||d
d�Stk
r�}zt|�Sd}~XYnXdS)N�GET�REQUEST_METHOD�QUERY_STRING�POSTzlatin-1z!application/x-www-form-urlencoded�CONTENT_TYPE�CONTENT_LENGTHzunknown method: %s�)Zstrict_parsing)	r�encoder�len�
ValueError�cgi�parserr)Zbuf�method�env�fprrrr�do_test$s
r.�zbad query field: ''�&z&&�=z=&=z=a�az&=az=a&z=&azbad query field: 'a'zb=a�bzb+=azb za=b=aza=+b=az b=az&b=azb&=azbad query field: 'b'za=a+b&b=b+cza bzb c)r2r3za=a+b&a=b+azb azx=1&y=2.0&z=2-3.%2b0�1z2.0z2-3.+0)�x�y�zz�Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=envZ400006�rZ	964546263z
130003.300038zen-USZ 0bb2e248638833d48cb7fed300000f1br,Zbustomer)z1Hbc5161168c542333633315dee1182227:key_store_seqidZcuyerZexpireZkidZlobaleZorder_idZssZviewzQgroup_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=BrowseZBrowseZ31392Z100Z5470Zcustom)ZSUBMITZ_assigned_toZ	_categoryZ_statusZgroup_id�setcCst|td�S)N)�key)�sorted�repr)�seqrrr�norm`sr>cCsdd�|D�S)NcSsg|]}|d�qS)rr)�.0�prrr�
<listcomp>dszfirst_elts.<locals>.<listcomp>r)�listrrr�
first_eltscsrCcCsdd�|D�S)NcSs g|]}|d|ddf�qS)rr%r)r?r@rrrrAgsz%first_second_elts.<locals>.<listcomp>r)rBrrr�first_second_eltsfsrDcCsld}t|�|��}|�d�tj|||d�}i}x6t|���D]&\}}t|t�rZ|�	|�p^|j
||<q>W|S)Nzlatin-1r)r-�environ�encoding)rr&�seekr)�FieldStorage�dict�itemsrrBZgetlist�value)�datarErFZ
fake_stdinZform�result�k�vrrr�
gen_resultis
"rPc@s�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&d'gd(d)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;S)<�CgiTestscCsPtt�d��}t�d�dd�}t�||�}dgdgdgdgd�}|�||�dS)	N�latin1�558)�boundaryzCONTENT-LENGTHz Add �1234s
Testing 123.
r/)�submit�id�file�title)r�POSTDATAr&�BOUNDARYr)�parse_multipart�assertEqual)rr-r,rM�expectedrrr�test_parse_multipartwszCgiTests.test_parse_multipartcCsFd}t|�d��}dd�d�i}t�||�}ddgi}|�||�dS)NzY--JfISa01
Content-Disposition: form-data; name="submit-name"

just a string

--JfISa01--
rRrT�JfISa01zsubmit-namezjust a string
)rr&r)r\r])rrZr-r,rMr^rrr�+test_parse_multipart_without_content_length�s
z4CgiTests.test_parse_multipart_without_content_lengthcCs�d}d}t|�d��}|�d�tt|�d���d�}tj||ddd�}d	d
gi}|�||�|�d�d�|d	d�dd��dS)
Nr`u]--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 3

☃
--JfISa01�utf8rR)rTzCONTENT-LENGTH�ascii�surrogateescape)rF�errorszsubmit-nameu	���u☃r)rr&rr'r)r\r])rr[rZr-r,rMr^rrr�%test_parse_multipart_invalid_encoding�s

z.CgiTests.test_parse_multipart_invalid_encodingcCs^t��}|�|�|�dt|��|�t|�t|����|j�t	dd�d��|�
|�dS)NrHZMockFieldStorage�nameZ
fieldvalue)r)rH�assertFalse�assertInr<r]rB�keys�appendr�
assertTrue)r�fsrrr�test_fieldstorage_properties�s
z%CgiTests.test_fieldstorage_propertiescCsL|jttjdddid�|�ttjdd�tjddid	�}|�tt|�dS)
Nznot-a-file-objr �PUT)rEZfooZbarzcontent-typez
text/plain)Zheaders)�assertRaises�	TypeErrorr)rH�bool)rrmrrr�test_fieldstorage_invalid�s
z"CgiTests.test_fieldstorage_invalidc	Cs^t���Lt�ddt�|�dt�d��|�dt�d��|�dt�dd	��WdQRXdS)
N�ignorezcgi\.escapeztest &amp; stringz
test & stringz&lt;test string&gt;z
<test string>z&quot;test string&quot;z
"test string"T)�warnings�catch_warnings�filterwarnings�DeprecationWarningr]r)�escape)rrrr�test_escape�s
zCgiTests.test_escapecCs�xtD�]�\}}t|d�}|�||dt|��t|d�}|�||dt|��d|i}tj|d�}t|t�r|�t|�t|��|�	|�
�|�
��|�|�dd�d�xZ|�
�D]N}||}|�||�t|�d	kr�|�|�|�|�q�|�|�|�|d
�q�WqWdS)NrzError parsing %s method GETr"zError parsing %s method POSTr!)rEznonexistent field�defaultr%r)
�parse_strict_test_casesr.r]r<r)rHrrIr'ZassertCountEqualrj�getvalueri)r�orig�expect�dr,rmr:�
expect_valrrr�test_strict�s"


zCgiTests.test_strictcCs
ddgdgd�fddgdgdgd�fdtd	�fd
td	�fdtd�fd
td	�fdtd�fddgdgd�fddddgifg	}x�|D]�\}}d|i}tjd|d�}t|t�r~xZ|��D]N}||}|�||�t|�dkr�|�|�	|�|�q�|�|�	|�|d�q�Wq~WdS)Nz	x=1;y=2.0r4z2.0)r5r6zx=1;y=2.0;z=2-3.%2b0z2-3.+0)r5r6r7�;zbad query field: ''z;;z=;azbad query field: 'a'z;b=azb;=azbad query field: 'b'za=a+b;b=b+cza bzb c)r2r3za=a+b;a=b+ar2zb ar!)Z	separatorrEr%r)
r(r)rHrrIrjrir'r]r})rZparse_semicolonr~rr,rmr:r�rrr�test_separator�s&





zCgiTests.test_separatorcCs~t�d�t�t_t�dd�t�dd�|�tj��d�tj�	tj
�rzdt_tj
t_t�dd�|�tj
�t�d�dS)NZTestingz%szTesting initlog 1z
Testing log 2z Testing initlog 1
Testing log 2
z
Testing log 3z
Testing log 4)r)�logr�logfp�initlogr]r}�os�path�exists�devnull�logfile�
addCleanup�closelog)rrrr�test_log�s
zCgiTests.test_logcCs~Gdd�d�}|t�d��}|�|j�|�dd�|�d�ddi}tj||d	�}|�|jj�|�	|j
d
�|��dS)Nc@s&eZdZdd�Zddd�Zdd�ZdS)	z=CgiTests.test_fieldstorage_readline.<locals>.TestReadlineFilecSs||_d|_dS)Nr)rX�numcalls)rrXrrrr�szFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__init__NcSs,|jd7_|r|j�|�S|j��SdS)Nr%)r�rX�readline)r�sizerrrr�szFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.readlinecSs.|jd}t||�}t|t�s*t|||�|S)NrX)�__dict__rr�int�setattr)rrgrXr2rrrr	s



zICgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__getattr__)N)rr	r
rr�rrrrr�TestReadlineFile�s
r�zwb+sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxirr ro)r-rE�)�tempfileZ
TemporaryFiler��close�writerGr)rHrXZ
assertGreaterr�)rr��fr,rmrrr�test_fieldstorage_readline�s
z#CgiTests.test_fieldstorage_readlinec	Cs�dd�t�dd�}tt�d��}tj||dd�}|�t|j	�d�ddd	d
�dddd
�d
ddd
�dddd
�g}xLt
t|j	��D]:}x4||��D]$\}}t|j	||�}|�||�q�Wq~WdS)Nr"z multipart/form-data; boundary={}rS)r r#r$zlatin-1)rErF�rWrU)rg�filenamerKrYr/rXztest.txts
Testing 123.
rVz Add )
�formatr[rrZr&r)rHr]r'rB�rangerJr)	rr,r-rmrr5rN�exp�gotrrr�test_fieldstorage_multiparts


z$CgiTests.test_fieldstorage_multipartc	Cs�dd�t�dd�}tdt�d��}tj||dd�}|�t|j	�d�d	dd
d�ddd
d�dddd�dddd�g}xLt
t|j	��D]:}x4||��D]$\}}t|j	||�}|�||�q�Wq�WdS)Nr"z multipart/form-data; boundary={}Z560)r r#r$s
zlatin-1)rErFr�rWrU)rgr�rKrYr/rXztest.txts
Testing 123.
rVz Add )
r�r[rrZr&r)rHr]r'rBr�rJr)	rr,r-rmrr5rNr�r�rrr�.test_fieldstorage_multipart_leading_whitespace/s


z7CgiTests.test_fieldstorage_multipart_leading_whitespacec
Cs�dd�t�dd�}x�dD]�}tt�|��}tj|||d�}|�t|j	�d�ddd	d
�g}xLt
t|j	��D]:}x4||��D]$\}}t|j	||�}	|�|	|�q|WqjWqWdS)Nr"z multipart/form-data; boundary={}rS)r r#r$)z
iso-8859-1zutf-8)rErFr%rWuçñ€)rgr�rK)
r�r[r�POSTDATA_NON_ASCIIr&r)rHr]r'rBr�rJr)
rr,rFr-rmrr5rNr�r�rrr�%test_fieldstorage_multipart_non_asciiBs
z.CgiTests.test_fieldstorage_multipart_non_asciics^d}d�_�fdd�}|d|d�|d|dd�|d|ddd|d�dS)NicsDd�dd�|}tt|��ddd�}��t||�d|�d�i�dS)	Nzp---123
Content-Disposition: form-data; name="upload"; filename="fake.txt"
Content-Type: text/plain

%s
---123--
�
z
z"multipart/form-data; boundary=-123r")r$r#r �uploadrR)�replacerr'r]rPr&)�contentrLrE)rrr�checkUs
z;CgiTests.test_fieldstorage_multipart_maxline.<locals>.checkr5r%�
r6)ZmaxDiff)rZmaxliner�r)rr�#test_fieldstorage_multipart_maxlineQsz,CgiTests.test_fieldstorage_multipart_maxlinec
Csdd�t�ttt��d�}tt�d��}tj||dd�}|�	t|j
�d�|�	|j
djd�|�	|j
djd	�|�	|j
d
jd�|j
d
j}|�	t|�d�ddd
d�dddd�g}xHt
t|��D]8}x2||��D]"\}}t|||�}	|�	|	|�q�Wq�WdS)Nr"z multipart/form-data; boundary={})r r#r$zlatin-1)rErFr�rzsubmit-name�Larryr%�filesz	file1.txts... contents of file1.txt ...)rgr�rKz	file2.gifs...contents of file2.gif...)r��BOUNDARY_W3rr'�POSTDATA_W3rr&r)rHr]rBrgrKr�rJr)
rr,r-rmr�rr5rNr�r�rrr�test_fieldstorage_multipart_w3chs"
z(CgiTests.test_fieldstorage_multipart_w3ccCs~d}d}dd�|�tt|��d�}t|�d��}tj||dd�}|�t|j�d�|�|jd	j	d
�|�|jd	j
d�dS)Nr`z_--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 5

Larry
--JfISa01r"z multipart/form-data; boundary={})r r#r$zlatin-1)rErFr%rzsubmit-namer�)r�rr'rr&r)rHr]rBrgrK)rr[rZr,r-rmrrr�%test_fieldstorage_part_content_length}sz.CgiTests.test_fieldstorage_part_content_lengthcCs@td�}dd|d�}tj||d�}|�t|dj���d�dS)Nsa--MyBoundary
Content-Disposition: form-data; name="my-arg"; filename="foo"

Test

--MyBoundary--
r"z(multipart/form-data; boundary=MyBoundary)r r#z
wsgi.input)rEzmy-arg�)rr)rHr]r'rX�read)rr-r,Zfieldsrrr�.test_field_storage_multipart_no_content_length�sz7CgiTests.test_field_storage_multipart_no_content_lengthc	Cs�td�}ddi}tj||d��}|j��}|�|jj�WdQRX|�|jj�|�|d�|�	t
d��|j��WdQRXdS)Ns
xxxxxxxxxxr ro)r-rEZ
xxxxxxxxxxzI/O operation on closed file)rr)rHrXr�rh�closedrlr]ZassertRaisesRegexr()rr-r,rmr�rrr�$test_fieldstorage_as_context_manager�s
z-CgiTests.test_fieldstorage_as_context_managerZvalue1Zvalue2xZvalue2yZvalue3Zvalue4)Zkey1Zkey2Zkey3Zkey4cCs6d}tt|��dddd�}t||�}|�|j|�dS)Nz$key2=value2x&key3=value3&key4=value4z!application/x-www-form-urlencodedzkey1=value1&key2=value2yr")r$r#r!r )rr'rPr]�
_qs_result)rrLrErOrrr�testQSAndUrlEncode�s

zCgiTests.testQSAndUrlEncodec	Cs�d�dgd�}tt|��ddd�}|�t��tjt|���|dd�WdQRXd	}tt|��d
ddd�}|�t��tjt|���|d
d�WdQRXtjt|���|dd�dS)Nr0za=a�z!application/x-www-form-urlencodedr")r$r#r �
)r-rEZmax_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--
z"multipart/form-data; boundary=-123za=1&a=2)r$r#r!r r�r�)	�joinrr'rpr(r)rHrr&)rrLrErrr�test_max_num_fields�s.




zCgiTests.test_max_num_fieldscCs6d}tt|��dddd�}t||�}|�|j|�dS)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--
z"multipart/form-data; boundary=-123zkey1=value1&key2=value2xr")r$r#r!r )rr'rPr]r�)rrLrErOrrr�testQSAndFormData�s

zCgiTests.testQSAndFormDatacCsLd}tt|��dddd�}|j��}|�ddi�t||�}|�||�dS)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--
z"multipart/form-data; boundary=-123zkey1=value1&key2=value2xr")r$r#r!r r�s%this is the content of the fake file
)rr'r��copy�updaterPr])rrLrErMrOrrr�testQSAndFormDataFile
s



zCgiTests.testQSAndFormDataFilec	Cs<tdtf��&|�dgdgdgd�t�d��WdQRXdS)Nz=cgi.parse_qs is deprecated, use urllib.parse.parse_qs instead�A1�B3�B2)r2�Br3za=A1&b=B2&B=B3)rrxr]r)Zparse_qs)rrrr�test_deprecated_parse_qs,s
z!CgiTests.test_deprecated_parse_qsc	Cs4tdtf��|�dddgt�d��WdQRXdS)Nz?cgi.parse_qsl is deprecated, use urllib.parse.parse_qsl instead)r2r�)r3r�)r�r�za=A1&b=B2&B=B3)rrxr]r)Z	parse_qsl)rrrr�test_deprecated_parse_qsl3s
z"CgiTests.test_deprecated_parse_qslcCs�|�t�d�dif�|�t�d�dif�|�t�d�dddif�|�t�d�dddif�|�t�d�ddd	d
�f�|�t�d�dd
dif�|�t�d�dd
dif�|�t�d�dddd�f�|�t�d�dddd�f�dS)Nz
text/plainztext/vnd.just.made.this.up ; ztext/vnd.just.made.this.upztext/plain;charset=us-ascii�charsetzus-asciiztext/plain ; charset="us-ascii"z,text/plain ; charset="us-ascii"; another=optZopt)r�Zanotherz attachment; filename="silly.txt"Z
attachmentr�z	silly.txtz#attachment; filename="strange;name"zstrange;namez-attachment; filename="strange;name";size=123;Z123)r�r�z-form-data; name="files"; filename="fo\"o;bar"z	form-datar�zfo"o;bar)rgr�)r]r)Zparse_header)rrrr�test_parse_header:s6

zCgiTests.test_parse_headerc	Cs*ddddddddd	h	}tj|t|d
�dS)Nr�r�r�ZdologZnologr�r��maxlenZvalid_boundary)�	blacklist)rZcheck__all__r))rr�rrr�test_allWs
zCgiTests.test_allN)rr	r
r_rarfrnrsrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrQus<		%6"rQz6---------------------------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
ZAaB03xa�--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__)!Ztest.supportrr)r�rr�Zunittestru�collectionsr�iorrZtestrrrr.r(r|r>rCrDrPZTestCaserQr[rZr�r�r�r�mainrrrr�<module>s|








k