Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_cgi.cpython-39.opt-1.pyc

a

��g�X�@s�ddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZGdd�d�Ze�e_Gdd�d�Z
d	d
�Zded�fd
ed�fded�fdifdifdddgifded�fded�fded�fdddgifdddgifdddgifdddgifded�fded �fd!d"gd#gd$�fd%dd"d&gifd'd(gd)gd*gd+�fd,d-gd.gd/gd0gd1gd2gd3gd4gd5�fd6d7gd8gd9gd(gd:gd;gd<�fgZd=d>�Zd?d@�ZdAdB�ZdCdD�ZGdEdF�dFej�ZdGZdHZdIZdJZdKZedLk�r�e��dS)M�N)�
namedtuple)�StringIO�BytesIO)�supportc@seZdZgZejZdS)�HackedSysModuleN)�__name__�
__module__�__qualname__�argv�sys�stdin�r
r
�)/usr/local/lib/python3.9/test/test_cgi.pyr
src@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ComparableExceptioncCs
||_dS�N)�err)�selfrr
r
r�__init__szComparableException.__init__cCs
t|j�Sr)�strr�rr
r
r�__str__szComparableException.__str__cCs*t|t�stS|jj|jko(|jj|jkSr)�
isinstance�	Exception�NotImplementedr�	__class__�args)rZanExcr
r
r�__eq__s

�zComparableException.__eq__cCst|j|�Sr)�getattrr)r�attrr
r
r�__getattr__szComparableException.__getattr__N)rrr	rrrrr
r
r
rrsrc
Cs�i}|dkr"d}d|d<||d<nD|dkrZt|�d��}d|d<d|d<tt|��|d<ntd	|��ztj||d
d�WSty�}zt|�WYd}~Sd}~00dS)N�GET�REQUEST_METHOD�QUERY_STRING�POST�latin-1�!application/x-www-form-urlencoded�CONTENT_TYPE�CONTENT_LENGTHzunknown method: %s�)�strict_parsing)	r�encoder�len�
ValueError�cgi�parserr)�buf�method�env�fprr
r
r�do_test"s
r3��bad query field: ''�&z&&�=z=&=z=a�az&=az=a&z=&a�bad query field: 'a'zb=a�bzb+=azb za=b=aza=+b=az b=az&b=azb&=a�bad query field: 'b'za=a+b&b=b+c�a b�b c�r8r:za=a+b&a=b+a�b azx=1&y=2.0&z=2-3.%2b0�1�2.0�2-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 0bb2e248638833d48cb7fed300000f1br1Zbustomer)z1Hbc5161168c542333633315dee1182227:key_store_seqidZcuyerZexpireZkidZlobaleZorder_id�ss�viewzQgroup_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)�seqr
r
r�norm^srOcCsdd�|D�S)NcSsg|]}|d�qS)rr
��.0�pr
r
r�
<listcomp>b�zfirst_elts.<locals>.<listcomp>r
��listr
r
r�
first_eltsasrWcCsdd�|D�S)NcSs g|]}|d|ddf�qS)rr(r
rPr
r
rrSerTz%first_second_elts.<locals>.<listcomp>r
rUr
r
r�first_second_eltsdsrXcCshd}t|�|��}|�d�tj|||d�}i}t|���D]&\}}t|t�rX|�	|�p\|j
||<q<|S)Nr$r)r2�environ�encoding)rr*�seekr-�FieldStorage�dict�itemsrrVZgetlist�value)�datarYrZZ
fake_stdinZform�result�k�vr
r
r�
gen_resultgs
 rdc@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$d%gd&d'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5S)6�CgiTestscCsPtt�d��}t�d�dd�}t�||�}dgdgdgdgd�}|�||�dS)	N�latin1�558��boundaryzCONTENT-LENGTH� Add �1234�
Testing 123.
r4)�submit�id�file�title)r�POSTDATAr*�BOUNDARYr-�parse_multipart�assertEqual)rr2r1ra�expectedr
r
r�test_parse_multipartus��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--
rfri�JfISa01�submit-namezjust a string
)rr*r-rsrt)rrqr2r1rarur
r
r�+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)
Nrwu]--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 3

☃
--JfISa01�utf8rfrh�ascii�surrogateescape)rZ�errorsrxu	���u☃r)rr*rr+r-rsrt)rrrrqr2r1rarur
r
r�%test_parse_multipart_invalid_encoding�s�
�
�z.CgiTests.test_parse_multipart_invalid_encodingcCs^t��}|�|�|�dt|��|�t|�t|����|j�t	dd�d��|�
|�dS)Nr\ZMockFieldStorage�nameZ
fieldvalue)r-r\�assertFalse�assertInrMrtrV�keys�appendr�
assertTrue�r�fsr
r
r�test_fieldstorage_properties�s
z%CgiTests.test_fieldstorage_propertiescCsL|jttjdddid�|�ttjdd�tjddid	�}|�tt|�dS)
Nznot-a-file-objr!�PUT�rYZfooZbarzcontent-type�
text/plain)Zheaders)�assertRaises�	TypeErrorr-r\�boolr�r
r
r�test_fieldstorage_invalid�s�z"CgiTests.test_fieldstorage_invalidcCstD]�\}}t|d�}|�||dt|��t|d�}|�||dt|��d|i}tj|d�}t|t�r|�t|�t|��|�	|�
�|�
��|�|�dd�d�|�
�D]N}||}|�||�t|�d	kr�|�|�|�|�q�|�|�|�|d
�q�qdS)Nr zError parsing %s method GETr#zError parsing %s method POSTr"r�znonexistent field�defaultr(r)
�parse_strict_test_casesr3rtrMr-r\rr]r+ZassertCountEqualr��getvaluer�)r�orig�expect�dr1r�rK�
expect_valr
r
r�test_strict�s"


zCgiTests.test_strictcCsddgdgd�fddgdgdgd�fdtd	�fd
td	�fdtd�fd
td	�fdtd�fddgdgd�fddddgifg	}|D]�\}}d|i}tjd|d�}t|t�r||��D]N}||}|�||�t|�dkr�|�|�	|�|�q�|�|�	|�|d�q�q|dS)Nz	x=1;y=2.0r@rA)rDrEzx=1;y=2.0;z=2-3.%2b0rBrC�;r5z;;z=;ar9z;b=azb;=ar;za=a+b;b=b+cr<r=r>za=a+b;a=b+ar8r?r")�	separatorrYr(r)
r,r-r\rr]r�r�r+rtr�)rZparse_semicolonr�r�r1r�rKr�r
r
r�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�initlogrtr��os�path�exists�devnull�logfile�
addCleanup�closelogrr
r
r�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)ro�numcalls)rror
r
rr�szFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__init__NcSs,|jd7_|r|j�|�S|j��SdS)Nr()r�ro�readline)r�sizer
r
rr��szFCgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.readlinecSs.|jd}t||�}t|t�s*t|||�|S)Nro)�__dict__rr�int�setattr)rrror8r
r
rr�s



zICgiTests.test_fieldstorage_readline.<locals>.TestReadlineFile.__getattr__)N)rrr	rr�rr
r
r
r�TestReadlineFile�s
r�zwb+sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxirr!r��r2rY�)�tempfile�
TemporaryFiler��close�writer[r-r\roZ
assertGreaterr�)rr��fr1r�r
r
r�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}t
t|j	��D]6}||��D]$\}}t|j	||�}|�||�q�q|dS)Nr#� multipart/form-data; boundary={}rg�r!r&r'r$�rYrZ�rnrk�r�filenamer_rpr4ro�test.txtrlrmrj�
�formatrrrrqr*r-r\rtr+rV�ranger^r�	rr1r2r�r�rDrb�exp�gotr
r
r�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}t
t|j	��D]6}||��D]$\}}t|j	||�}|�||�q�q�dS)Nr#r�Z560r�s
r$r�r�rnrkr�rpr4ror�rlrmrjr�r�r
r
r�.test_fieldstorage_multipart_leading_whitespace$s �



�z7CgiTests.test_fieldstorage_multipart_leading_whitespacec
Cs�dd�t�dd�}dD]�}tt�|��}tj|||d�}|�t|j	�d�ddd	d
�g}t
t|j	��D]6}||��D]$\}}t|j	||�}	|�|	|�qvqfqdS)Nr#r�rgr�)z
iso-8859-1zutf-8r�r(rnuçñ€r�)
r�rrr�POSTDATA_NON_ASCIIr*r-r\rtr+rVr�r^r)
rr1rZr2r�r�rDrbr�r�r
r
r�%test_fieldstorage_multipart_non_ascii7s�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
�"multipart/form-data; boundary=-123r#�r'r&r!�uploadrf)�replacerr+rtrdr*)�contentr`rYrr
r�checkJs��
��z;CgiTests.test_fieldstorage_multipart_maxline.<locals>.checkrDr(�
rE)ZmaxDiff)rZmaxliner�r
rr�#test_fieldstorage_multipart_maxlineFs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}t
t|��D]4}||��D]"\}}t|||�}	|�	|	|�q�q�dS)Nr#r�r�r$r�r�rrx�Larryr(�filesz	file1.txts... contents of file1.txt ...r�z	file2.gifs...contents of file2.gif...)r��BOUNDARY_W3rr+�POSTDATA_W3rr*r-r\rtrVrr_r�r^r)
rr1r2r�r�r�rDrbr�r�r
r
r�test_fieldstorage_multipart_w3c]s&
�

�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)Nrwz_--JfISa01
Content-Disposition: form-data; name="submit-name"
Content-Length: 5

Larry
--JfISa01r#r�r�r$r�r(rrxr�)r�rr+rr*r-r\rtrVrr_)rrrrqr1r2r�r
r
r�%test_fieldstorage_part_content_lengthrs
�z.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.inputr�zmy-arg�)rr-r\rtr+ro�read)rr2r1�fieldsr
r
r�.test_field_storage_multipart_no_content_length�s�z7CgiTests.test_field_storage_multipart_no_content_lengthcCs�td�}ddi}tj||d��(}|j��}|�|jj�Wd�n1sL0Y|�|jj�|�|d�|�	t
d��|j��Wd�n1s�0YdS)Ns
xxxxxxxxxxr!r�r�Z
xxxxxxxxxxzI/O operation on closed file)rr-r\ror�r��closedr�rtZassertRaisesRegexr,)rr2r1r�r�r
r
r�$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=value4r%zkey1=value1&key2=value2yr#�r'r&r"r!�rr+rdrt�
_qs_result�rr`rYrcr
r
r�testQSAndUrlEncode�s
�
zCgiTests.testQSAndUrlEncodecCs�d�dgd�}tt|��ddd�}|�t��(tjt|���|dd�Wd�n1s\0Yd	}tt|��d
ddd�}|�t��(tjt|���|d
d�Wd�n1s�0Ytjt|���|dd�dS)Nr6za=a�r%r#r��
)r2rY�max_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--
r�za=1&a=2r�r�r�)	�joinrr+r�r,r-r\rr*)rr`rYr
r
r�test_max_num_fields�s8
�
�$
�
�$
�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--
r��key1=value1&key2=value2xr#r�r�r�r
r
r�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--
r�r�r#r�r�s%this is the content of the fake file
)rr+r��copy�updaterdrt)rr`rYrarcr
r
r�testQSAndFormDataFile�s
�
�
zCgiTests.testQSAndFormDataFilecCs�|�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)Nr�ztext/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=opt�opt)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)rr�)rtr-Zparse_headerrr
r
r�test_parse_header!sH��
�
��
�
���zCgiTests.test_parse_headercCshd�}tj|t|d�dS)N>	r��maxlenr�r�r�r�ZnologZvalid_boundaryZdolog)�	blacklist)rZcheck__all__r-)rr�r
r
r�test_all>szCgiTests.test_allN)rrr	rvryr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rress8	%�6"rez6---------------------------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__)r-r�rr�Zunittest�collectionsr�iorr�testrrrr3r,r�rOrWrXrdZTestCasererrrqr�r�r�r�mainr
r
r
r�<module>s�







�����*T


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists