Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_cgi.cpython-34.pyc

�
g f�K�@s�ddlmZmZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
Gdd�d�Ze�e_Gdd�d�Zd	d
�Zded�fd
ed�fded�fded�fded�fdifdifdifdidgd6fded�fded�fded�fdidgd6fdidgd6fdidgd6fdid gd6fd!ed�fd"ed#�fd$id%gd6d&gd6fd'id%d(gd6fd)id*gd+6d,gd-6d.gd/6fd0id*gd+6d,gd-6d.gd/6fd1id*gd+6d,gd-6d.gd/6fd2id3gd46d5gd66d7gd86d9gd:6d;gd<6d=gd>6d?gd@6dAgdB6fdCidDgdE6dFgdG6dHgdI6d*gdJ6dKgdL6dMgdN6fgZdOdP�ZdQdR�ZdSdT�ZdUdV�ZGdWdX�dXej�ZdYZdZZd[Zd\Zd]Zd^d_�Zed`kr�e�ndS)a�)�run_unittest�check_warningsN)�
namedtuple)�StringIO�BytesIOc@seZdZgZejZdS)�HackedSysModuleN)�__name__�
__module__�__qualname__�argv�sys�stdin�rr�2/opt/alt/python34/lib64/python3.4/test/test_cgi.pyrsrc@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__szComparableException.__eq__cCst|j|�S)N)�getattrr)r�attrrrr�__getattr__ szComparableException.__getattr__N)rr	r
rrrrrrrrrsrcCs�i}|dkr/d}d|d<||d<n^|dkr}t|jd��}d|d<d|d<tt|��|d<ntd	|��ytj||d
d�SWn/tk
r�}zt|�SWYdd}~XnXdS)N�GET�REQUEST_METHOD�QUERY_STRING�POSTzlatin-1z!application/x-www-form-urlencoded�CONTENT_TYPE�CONTENT_LENGTHzunknown method: %sZstrict_parsing�)	r�encoder�len�
ValueError�cgi�parserr)Zbuf�method�env�fprrrr�do_test#s



r.�zbad query field: ''�&z&&�;z;&;�=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 cza=a+b&a=b+azb azx=1&y=2.0&z=2-3.%2b0�1�xz2.0�yz2-3.+0�zzx=1;y=2.0&z=2-3.%2b0zx=1;y=2.0;z=2-3.%2b0z�Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=envZ400006z1Hbc5161168c542333633315dee1182227:key_store_seqid�rZcuyerZ	964546263Zexpirez
130003.300038Zkidzen-USZlobaleZ 0bb2e248638833d48cb7fed300000f1bZorder_idr,ZssZbustomerZviewzQgroup_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=BrowseZBrowseZSUBMITZ31392Z_assigned_toZ100Z	_categoryZ_statusZ5470Zgroup_idZcustom�setcCst|dt�S)N�key)�sorted�repr)�seqrrr�normdsr?cCsdd�|D�S)NcSsg|]}|d�qS)rr)�.0�prrr�
<listcomp>hs	zfirst_elts.<locals>.<listcomp>r)�listrrr�
first_eltsgsrDcCsdd�|D�S)NcSs(g|]}|d|ddf�qS)rr%r)r@rArrrrBks	z%first_second_elts.<locals>.<listcomp>r)rCrrr�first_second_eltsjsrEcCs�d}t|j|��}|jd�tjd|d|d|�}i}xKt|�j�D]7\}}t|t�r�|j	|�p�|j
||<q_W|S)Nzlatin-1rr-�environ�encoding)rr&�seekr)�FieldStorage�dict�itemsrrCZgetlist�value)�datarFrGZ
fake_stdinZform�result�k�vrrr�
gen_resultms
/rQc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zidd6ddgd6d d!6d"d#6Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0S)1�CgiTestscCs�ttjd��}itjd�d6dd6}tj||�}idgd6dgd6d	gd
6dgd6}|j||�dS)
N�latin1�boundary�558zCONTENT-LENGTHs Add �submits1234�ids
Testing 123.
�file��title)r�POSTDATAr&�BOUNDARYr)Zparse_multipart�assertEqual)rr-r,rNZexpectedrrr�test_parse_multipart{s
zCgiTests.test_parse_multipartcCs�tj�}|j|�|jdt|��|jt|�t|j���|jjt	dd�d��|j
|�dS)NrIZMockFieldStorage�nameZ
fieldvalue)r)rIZassertFalse�assertInr=r]rC�keys�appendrZ
assertTrue)r�fsrrr�test_fieldstorage_properties�s
"z%CgiTests.test_fieldstorage_propertiescCsl|jttjddidd6�|jttjdd�tjdidd	6�}|jtt|�dS)
Nznot-a-file-objrF�PUTr ZfooZbarZheadersz
text/plainzcontent-type)ZassertRaises�	TypeErrorr)rI�bool)rrcrrr�test_fieldstorage_invalid�s
z"CgiTests.test_fieldstorage_invalidcCsxtj��ftjddt�|jdtjd��|jdtjd��|jdtjdd	��WdQXdS)
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_escapecCstxmtD]e\}}t|d�}|j||dt|��t|d�}|j||dt|��i|d6}tjd|�}t|t�r|jt|�t|��|j	|j
�|j
��|j|jdd�d�x||j
�D]k}||}|j||�t|�d	krH|j|j|�|�q�|j|j|�|d
�q�WqqWdS)NrzError parsing %s method GETr"zError parsing %s method POSTr!rFznonexistent field�defaultr%r)
�parse_strict_test_casesr.r]r=r)rIrrJr'ZassertCountEqualra�getvaluer`)rZorig�expect�dr,rcr;Z
expect_valrrr�test_strict�s"

zCgiTests.test_strictcCs�tjd�t�t_tjdd�tjdd�|jtjj�d�tjj	tj
�r�dt_tj
t_tjdd�|jtj
�tjd�ndS)NZTestingz%szTesting initlog 1z
Testing log 2z Testing initlog 1
Testing log 2
z
Testing log 3z
Testing log 4)r)�logrZlogfpZinitlogr]rr�os�path�exists�devnullZlogfile�
addCleanupZcloselog)rrrr�test_log�s
	zCgiTests.test_logcCs�Gdd�d�}|tjd��}|j|j�|jddd�|jd�idd	6}tjd
|d|�}|j|jj�|j	|j
d�|j�dS)
Nc@s7eZdZdd�Zddd�Zdd�ZdS)z=CgiTests.test_fieldstorage_readline.<locals>.TestReadlineFilecSs||_d|_dS)Nr)rX�numcalls)rrXrrrr�s	zFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__init__NcSs6|jd7_|r%|jj|�S|jj�SdS)Nr%)r}rX�readline)r�sizerrrr~�szFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.readlinecSsB|jd}t||�}t|t�s>t|||�n|S)NrX)�__dict__rr�int�setattr)rr_rXr3rrrr�s

zICgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__getattr__)rr	r
rr~rrrrr�TestReadlineFile�sr�zwb+�x�irrer r-rF�)�tempfileZ
TemporaryFiler{�close�writerHr)rIrXZ
assertGreaterr})rr��fr,rcrrr�test_fieldstorage_readline�s

z#CgiTests.test_fieldstorage_readlinec	Cs>idd6djt�d6dd6}ttjd��}tj|d|d	d�}|jt|j	�d
�idd6dd
6dd6idd6dd
6dd6idd6dd
6dd6idd6dd
6dd6g}xdt
t|j	��D]M}xD||j�D]2\}}t|j	||�}|j||�qWq�WdS)Nr"r z multipart/form-data; boundary={}r#rUr$zlatin-1rFrG�rWr_�filename�1234rLrZr/rXztest.txts
Testing 123.
rVz Add )
�formatr\rr[r&r)rIr]r'rC�rangerKr)	rr,r-rcrsr6rO�exp�gotrrr�test_fieldstorage_multipart�s
z$CgiTests.test_fieldstorage_multipartc	CsBidd6djt�d6dd6}tdtjd��}tj|d	|d
d�}|jt|j	�d�idd
6dd6dd6idd
6dd6dd6idd
6dd6dd6idd
6dd6dd6g}xdt
t|j	��D]M}xD||j�D]2\}}t|j	||�}|j||�qWq�WdS)Nr"r z multipart/form-data; boundary={}r#Z560r$s
zlatin-1rFrGr�rWr_r�r�rLrZr/rXztest.txts
Testing 123.
rVz Add )
r�r\rr[r&r)rIr]r'rCr�rKr)	rr,r-rcrsr6rOr�r�rrr�.test_fieldstorage_multipart_leading_whitespace�s
z7CgiTests.test_fieldstorage_multipart_leading_whitespacec
Cs
idd6djt�d6dd6}x�ddgD]�}ttj|��}tj|d	|d
|�}|jt|j	�d�idd
6dd6dd6g}xdt
t|j	��D]M}xD||j�D]2\}}t|j	||�}	|j|	|�q�Wq�Wq1WdS)Nr"r z multipart/form-data; boundary={}r#rUr$z
iso-8859-1zutf-8rFrGr%rWr_r�uçñ€rL)
r�r\r�POSTDATA_NON_ASCIIr&r)rIr]r'rCr�rKr)
rr,rGr-rcrsr6rOr�r�rrr�%test_fieldstorage_multipart_non_asciis

z.CgiTests.test_fieldstorage_multipart_non_asciicsod}d�_�fdd�}|d|d�|d|dd�|d|ddd|d�dS)	Nr%�csjdjdd�|}itt|��d6dd6dd6}�jt||�i|jd	�d
6�dS)Nzp---123
Content-Disposition: form-data; name="upload"; filename="fake.txt"
Content-Type: text/plain

%s
---123--
�
z
r$z"multipart/form-data; boundary=-123r#r"r rS�upload)�replacerr'r]rQr&)ZcontentrMrF)rrr�check!s
z;CgiTests.test_fieldstorage_multipart_maxline.<locals>.checkr6�
r7i)ZmaxDiff)rZmaxliner�r)rr�#test_fieldstorage_multipart_maxlines	z,CgiTests.test_fieldstorage_multipart_maxlinec
Cs�idd6djt�d6ttt��d6}ttjd��}tj|d|dd�}|j	t|j
�d	�|j	|j
d
jd�|j	|j
d
jd�|j	|j
d
jd�|j
d
j}|j	t|�d	�idd6dd6dd6idd6dd6dd6g}x^t
t|��D]J}xA||j�D]/\}}t|||�}	|j	|	|�qMWq6WdS)Nr"r z multipart/form-data; boundary={}r#r$zlatin-1rFrGr�rzsubmit-name�Larryr%�filesr_z	file1.txtr�s... contents of file1.txt ...rLz	file2.gifs...contents of file2.gif...)r��BOUNDARY_W3rr'�POSTDATA_W3rr&r)rIr]rCr_rLr�rKr)
rr,r-rcr�rsr6rOr�r�rrr�test_fieldstorage_multipart_w3c4s$z(CgiTests.test_fieldstorage_multipart_w3ccCs�d}d}idd6dj|�d6tt|��d6}t|jd��}tj|d	|d
d�}|jt|j�d�|j|jdj	d
�|j|jdj
d�dS)NZJfISa01z_--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 5

Larry
--JfISa01r"r z multipart/form-data; boundary={}r#r$zlatin-1rFrGr%rzsubmit-namer�)r�rr'rr&r)rIr]rCr_rL)rr\r[r,r-rcrrr�%test_fieldstorage_part_content_lengthIsz.CgiTests.test_fieldstorage_part_content_lengthZvalue1Zkey1Zvalue2xZvalue2yZkey2Zvalue3Zkey3Zvalue4Zkey4cCsZd}itt|��d6dd6dd6dd6}t||�}|j|j|�dS)	Nz$key2=value2x&key3=value3&key4=value4r$z!application/x-www-form-urlencodedr#zkey1=value1&key2=value2yr!r"r )rr'rQr]�
_qs_result)rrMrFrPrrr�testQSAndUrlEncodebs
zCgiTests.testQSAndUrlEncodecCsZd}itt|��d6dd6dd6dd6}t||�}|j|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--
r$z"multipart/form-data; boundary=-123r#zkey1=value1&key2=value2xr!r"r )rr'rQr]r�)rrMrFrPrrr�testQSAndFormDatams
zCgiTests.testQSAndFormDatacCszd}itt|��d6dd6dd6dd6}|jj�}|jid	d
6�t||�}|j||�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--
r$z"multipart/form-data; boundary=-123r#zkey1=value1&key2=value2xr!r"r s%this is the content of the fake file
r�)rr'r��copy�updaterQr])rrMrFrNrPrrr�testQSAndFormDataFile�s
	zCgiTests.testQSAndFormDataFilecCsTtdtf��<|jidgd6dgd6dgd6tjd��WdQXdS)	Nz=cgi.parse_qs is deprecated, use urllib.parse.parse_qs instead�A1r3�B3�B�B2r4za=A1&b=B2&B=B3)rrmr]r)Zparse_qs)rrrr�test_deprecated_parse_qs�s
'z!CgiTests.test_deprecated_parse_qscCs?tdtf��'|jd	d
dgtjd��WdQXdS)Nz?cgi.parse_qsl is deprecated, use urllib.parse.parse_qsl insteadr3r�r4r�r�r�za=A1&b=B2&B=B3)r3zA1)r4zB2)r�zB3)rrmr]r)Z	parse_qsl)rrrr�test_deprecated_parse_qsl�s
z"CgiTests.test_deprecated_parse_qslcCsa|jtjd�dif�|jtjd�dif�|jtjd�didd6f�|jtjd�didd6f�|jtjd�didd6d	d
6f�|jtjd�did
d6f�|jtjd�didd6f�|jtjd�didd6dd6f�|jtjd�didd6dd6f�dS)Nz
text/plainztext/vnd.just.made.this.up ; ztext/vnd.just.made.this.upztext/plain;charset=us-asciizus-ascii�charsetztext/plain ; charset="us-ascii"z,text/plain ; charset="us-ascii"; another=optZoptZanotherz attachment; filename="silly.txt"Z
attachmentz	silly.txtr�z#attachment; filename="strange;name"zstrange;namez-attachment; filename="strange;name";size=123;Z123rz-form-data; name="files"; filename="fo\"o;bar"z	form-datar�r_zfo"o;bar)r]r)Zparse_header)rrrr�test_parse_header�s6

zCgiTests.test_parse_headerN)rr	r
r^rdrhrorur|r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrRys0		%

"rRz6---------------------------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--
cCstt�dS)N)rrRrrrr�	test_mainsr��__main__) Ztest.supportrrr)rwrr�Zunittestrj�collectionsr�iorrrrr.r(rqr?rDrErQZTestCaserRr\r[r�r�r�r�rrrrr�<module>s�			'''












�[