Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_httpservers.cpython-312.pyc

�

'Μg�����dZddlmZddlmZmZmZmZddlm	Z	m
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl Z ddl!m"Z"m#Z#ddlZddl$m%Z%dd	l&m'Z'dd
l&m(Z(e%jRd��Gd
�d�Z*Gd�dejV�Z,Gd�dejZ�Z.Gd�de.�Z/Gd�de.�Z0Gd�de.�Z1dZ2dZ3dZ4dZ5ejle7ed�xrejp�dk(d�Gd�d e.��Z9Gd!�d"e�Z:Gd#�d$e:�Z;Gd%�d&�Z<Gd'�d(ejZ�Z=Gd)�d*ejZ�Z>Gd+�d,ejZ�Z?Gd-�d.ejZ�Z@d/�ZAeBd0k(rej��yy)1z�Unittests for the various HTTPServer modules.

Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
�)�OrderedDict)�BaseHTTPRequestHandler�
HTTPServer�SimpleHTTPRequestHandler�CGIHTTPRequestHandler)�server�
HTTPStatusN)�mock)�BytesIO�StringIO)�support)�	os_helper)�threading_helperT)�modulec��eZdZd�Zdd�Zy)�NoLogRequestHandlerc��y�N�)�self�argss  �2/usr/local/lib/python3.12/test/test_httpservers.py�log_messagezNoLogRequestHandler.log_message(s���Nc��y�N�r)r�ns  r�readzNoLogRequestHandler.read,s��rr)�__name__�
__module__�__qualname__rrrrrrr's��
�rrc��eZdZd�Zd�Zd�Zy)�TestServerThreadc�^�tjj|�||_||_yr)�	threading�Thread�__init__�request_handler�test_object)rr*r)s   rr(zTestServerThread.__init__1s&�����!�!�$�'�.���&��rc���td|j�|_|jjj	�\|j
_|j
_|j
jj�d|_	|jjd�|jj�y#|jj�wxYw)N)�	localhostrg�������?)rr)r�socket�getsocknamer*�HOST�PORT�server_started�set�
serve_forever�server_close�rs r�runzTestServerThread.run6s��� �!1�4�3G�3G�H���7;�{�{�7I�7I�7U�7U�7W�4�����t�/�/�4����'�'�+�+�-����	'��K�K�%�%�d�+��K�K�$�$�&��D�K�K�$�$�&�s�
C�Cc�X�|jj�|j�yr)r�shutdown�joinr5s r�stopzTestServerThread.stop@s���������	�	�rN)r r!r"r(r6r:rrrr$r$0s��'�
'�rr$c�&�eZdZd�Zd�Zddifd�Zy)�BaseTestCasec�@�tj�|_tj�t
_tj�|_	t||j�|_|jj�|jj�yr)r�threading_setup�_threadsr�EnvironmentVarGuard�os�environr&�Eventr1r$r)�thread�start�waitr5s r�setUpzBaseTestCase.setUpFsg��(�8�8�:��
��2�2�4��
�'�o�o�/���&�t�T�-A�-A�B������������ � �"rc��|jj�d|_tjj	�tj|j�yr)rDr:rArB�__exit__r�threading_cleanupr?r5s r�tearDownzBaseTestCase.tearDownNs;�����������
�
�
�����*�*�D�M�M�:r�GETNc���tjj|j|j�|_|j
j
||||�|j
j�Sr)�http�client�HTTPConnectionr/r0�
connection�request�getresponse)r�uri�method�body�headerss     rrRzBaseTestCase.requestTsM���+�+�4�4�T�Y�Y��	�	�J����������T�7�;����*�*�,�,r)r r!r"rGrKrRrrrr<r<Es��#�;�#(�d�B�-rr<c��eZdZGd�dee�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�BaseHTTPServerTestCasec�J�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)�&BaseHTTPServerTestCase.request_handler�HTTP/1.1c��|jtj�|jdd�|jdd�|j	�y)N�Content-Type�	text/html�
Connection�close��
send_responser	�
NO_CONTENT�send_header�end_headersr5s r�do_TESTz.BaseHTTPServerTestCase.request_handler.do_TEST_sB�����z�4�4�5����^�[�9����\�7�3����rc��|jtj�|jdd�|jdd�|j	�y)Nr^r_r`�
keep-aliverbr5s r�do_KEEPz.BaseHTTPServerTestCase.request_handler.do_KEEPesB�����z�4�4�5����^�[�9����\�<�8����rc�&�|jd�y)N����
send_errorr5s r�do_KEYERRORz2BaseHTTPServerTestCase.request_handler.do_KEYERRORks���O�O�C� rc�B�|jtj�yr�rnr	�	NOT_FOUNDr5s r�do_NOTFOUNDz2BaseHTTPServerTestCase.request_handler.do_NOTFOUNDns���O�O�J�0�0�1rc�*�|jddd�y)Nrlz
Short MessagezThis is a long 
 explanationrmr5s r�do_EXPLAINERRORz6BaseHTTPServerTestCase.request_handler.do_EXPLAINERRORqs���O�O�C��;�
=rc��|jd�|jdd�|jdd�|j�y)Nrlr^r_r`ra)rcrerfr5s r�	do_CUSTOMz0BaseHTTPServerTestCase.request_handler.do_CUSTOMus<�����s�#����^�[�9����\�7�3����rc��|jd�|jdd�|jdd�|j�|jdj	d�}|j
j
|�y)Nrl�	X-Special�Dängerous Mindr`razx-special-incoming�utf-8)rcrerfrW�encode�wfile�write)rrVs  r�do_LATINONEHEADERz8BaseHTTPServerTestCase.request_handler.do_LATINONEHEADER{si�����s�#����[�*;�<����\�7�3������<�<� 4�5�<�<�W�E�D��J�J���T�"rc�R�|jt|jdd��y�N��rn�int�pathr5s r�
do_SEND_ERRORz4BaseHTTPServerTestCase.request_handler.do_SEND_ERROR�����O�O�C��	�	�!�"�
�.�/rc�R�|jt|jdd��yr�r�r5s r�do_HEADz.BaseHTTPServerTestCase.request_handler.do_HEAD�r�rN)r r!r"�protocol_version�default_request_versionrgrjrorsrurwrr�r�rrrr)r[[s;��%��",��	�	�	!�	2�	=�	�	#�	0�	0rr)c���tj|�tjj	|j
|j�|_|jj�yr)	r<rGrNrOrPr/r0�con�connectr5s rrGzBaseHTTPServerTestCase.setUp�s@�����4� ��;�;�-�-�d�i�i����C��������rc���|jjdd�|jj�}|j|jt
j�y)NrL�/)r�rRrS�assertEqual�statusr	�NOT_IMPLEMENTED�r�ress  r�test_commandz#BaseHTTPServerTestCase.test_command�sB���������$��h�h�"�"�$��������Z�%?�%?�@rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)Nz	HTTP/1.1
�XYZBOGUSr��	r��
_http_vsn_str�
putrequest�
endheadersrSr�r�r	r�r�s  r�test_request_line_trimmingz1BaseHTTPServerTestCase.test_request_line_trimming�s^��!-����������J��,��������h�h�"�"�$��������Z�%?�%?�@rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)N�FUBARrLr��	r�r�r�r�rSr�r�r	�BAD_REQUESTr�s  r�test_version_bogusz)BaseHTTPServerTestCase.test_version_bogus�s^��!(����������E�3�'��������h�h�"�"�$��������Z�%;�%;�<rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)Nz
HTTP/9.9.9rLr�r�r�s  r�test_version_digitsz*BaseHTTPServerTestCase.test_version_digits�s^��!-����������E�3�'��������h�h�"�"�$��������Z�%;�%;�<rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)NzHTTP/-9_9_9.+9_9_9rLr�r�r�s  r�"test_version_signs_and_underscoresz9BaseHTTPServerTestCase.test_version_signs_and_underscores�s^��!5����������E�3�'��������h�h�"�"�$��������Z�%;�%;�<rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)NzHTTP/909876543210.0rLr�r�r�s  r�"test_major_version_number_too_longz9BaseHTTPServerTestCase.test_major_version_number_too_long��^��!6����������E�3�'��������h�h�"�"�$��������Z�%;�%;�<rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)NzHTTP/1.909876543210rLr�r�r�s  r�"test_minor_version_number_too_longz9BaseHTTPServerTestCase.test_minor_version_number_too_long�r�rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)NrrLr�r�r�s  r�test_version_none_getz,BaseHTTPServerTestCase.test_version_none_get�s^��!#����������E�3�'��������h�h�"�"�$��������Z�%?�%?�@rc��d|j_|jjdd�|jj�|jj	�}|j|jtj�y)Nr�CUSTOMr�r�r�s  r�test_version_nonez(BaseHTTPServerTestCase.test_version_none�s^��!#����������H�c�*��������h�h�"�"�$��������Z�%;�%;�<rc�<�d|j_d|j_|jjdd�|jj	�|jj�}|j
|jtj�y)N�czHTTP/9.9rLr�)
r��	_http_vsnr�r�r�rSr�r�r	�HTTP_VERSION_NOT_SUPPORTEDr�s  r�test_version_invalidz+BaseHTTPServerTestCase.test_version_invalid�sj�������!+����������E�3�'��������h�h�"�"�$��������Z�%J�%J�Krc��d|j_|jjdd�|jj�|jj	�}|j|jtj�yrr�r�s  r�test_send_blankz&BaseHTTPServerTestCase.test_send_blank�s^��!#����������B��#��������h�h�"�"�$��������Z�%;�%;�<rc�0�|jjdd�|jjdd�|jj�|jj	�}|j|jtj�y)NrLr�r`ra)	r�r��	putheaderr�rSr�r�r	r�r�s  r�test_header_closez(BaseHTTPServerTestCase.test_header_close�sf�������E�3�'������<��1��������h�h�"�"�$��������Z�%?�%?�@rc�R�d|j_|jjdd�|jjdd�|jj	�|jj�}|j
|jtj�y)Nr\rLr�r`ri)
r�r�r�r�r�rSr�r�r	r�r�s  r�test_header_keep_alivez-BaseHTTPServerTestCase.test_header_keep_alive�sr��!+����������E�3�'������<��6��������h�h�"�"�$��������Z�%?�%?�@rc���|jjdd�|jj�}|j|jt
j�y)N�TESTr�)r�rRrSr�r�r	rdr�s  r�test_handlerz#BaseHTTPServerTestCase.test_handler�sB���������%��h�h�"�"�$��������Z�%:�%:�;rc�4�|jjdd�|jj�}|j|j	d�d�|jjdd�|j|jj�y)N�KEEPr�r`rir�)r�rRrSr��	getheader�
addCleanuprar�s  r�test_return_header_keep_alivez4BaseHTTPServerTestCase.test_return_header_keep_alive�si���������%��h�h�"�"�$��������|�4�l�C��������%���������'rc��|jjdd�|jj�}|j|jd�y)N�KEYERRORr�rl�r�rRrSr�r�r�s  r�test_internal_key_errorz.BaseHTTPServerTestCase.test_internal_key_error�s<��������S�)��h�h�"�"�$��������S�)rc��|jjdd�|jj�}|j|jd�y)Nr�r�rlr�r�s  r�test_return_custom_statusz0BaseHTTPServerTestCase.test_return_custom_status�s<��������3�'��h�h�"�"�$��������S�)rc��|jjdd�|jj�}|j|jd�|jt
|jd���y)N�EXPLAINERRORr�rl�Content-Length)r�rRrSr�r��
assertTruer�r�r�s  r�test_return_explain_errorz0BaseHTTPServerTestCase.test_return_explain_errorsW���������-��h�h�"�"�$��������S�)�����C�M�M�*:�;�<�=rc��|jjddddi��|jj�}|j|j	d�d�|j|j�dj
d��y)	N�LATINONEHEADERr�zX-Special-IncominguÄrger mit Unicode�rWryrzr{)r�rRrSr�r�rr|r�s  r�test_latin1_headerz)BaseHTTPServerTestCase.test_latin1_headersw�������)�3� �(<�9
��	��h�h�"�"�$��������{�3�5F�G��������%9�%@�%@��%I�Jrc�J�|jjdd�|jj�}|j|jt
j�|j�}|jt|jd��t|��y)N�NOTFOUNDr�r�)r�rRrSr�r�r	rrrr�r��len)rr��datas   r�test_error_content_lengthz0BaseHTTPServerTestCase.test_error_content_lengthsp��������S�)��h�h�"�"�$��������Z�%9�%9�:��x�x�z������S�]�]�+;�<�=�s�4�y�Irc��tjtjf}tjtjtjtjtj
fD]�}|jjddj|��|jj�}|j||j�|jd|jd��|jd|jd��||vr!|jd|jd��|j�}|jd|���y)N�
SEND_ERROR�/{}r�r^�Transfer-Encodingr)r	�NOT_MODIFIED�
RESET_CONTENTrd�
PROCESSING�SWITCHING_PROTOCOLSr�rR�formatrSr�r�r�r�r�allow_transfer_encoding_codes�coder�r�s     r�test_send_errorz&BaseHTTPServerTestCase.test_send_errors
��)3�)@�)@�)3�)A�)A�)C�%��*�*�J�,C�,C��*�*�J�,D�,D��3�3�5�D�
�H�H���\�5�<�<��+=�>��(�(�&�&�(�C����T�3�:�:�.����T�3�=�=�1A�#B�C����T�3�=�=��#@�A��8�8�� � ��s�}�}�5H�'I�J��8�8�:�D����S�$�'�5rc��tjtjf}tjtjtjtjtj
fD�]N}|jjddj|��|jj�}|j||j�|tjk(rN|jt|jd��dkD�|jd|jd��nB|jd|jd��|jd|jd��||vr!|jd|jd��|j!�}|jd|���Qy)	N�HEADr�r�rr_r^r�r)r	r�r��OKrdr�r�rRr�rSr�r�r�r�r��assertInrr�s     r�test_head_via_send_errorz/BaseHTTPServerTestCase.test_head_via_send_error(sK��)3�)@�)@�)3�)A�)A�)C�%��]�]�J�$9�$9��,�,�j�.F�.F��3�3�5�D�
�H�H���V�U�\�\�$�%7�8��(�(�&�&�(�C����T�3�:�:�.��z�}�}�$�����C�M�M�2B�$C� D�q� H�I��
�
�k�3�=�=��+H�I�� � ��s�}�}�5E�'F�G�� � ��s�}�}�^�'D�E��8�8�� � ��s�}�}�5H�'I�J��8�8�:�D����S�$�'�!5rN)r r!r"rrr)rGr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrYrYZs���,0�-�/E�,0�\�
A�
A�=�=�=�=�=�A�=�L�=�A�A�<�
(�*�
*�
>�K�J�(�"(rrYc�.�eZdZGd�de�Zd�Zd�Zy)�RequestHandlerLoggingTestCasec� �eZdZdZdZd�Zd�Zy)�-RequestHandlerLoggingTestCase.request_handlerr\c�b�|jtj�|j�yr)rcr	r�rfr5s r�do_GETz4RequestHandlerLoggingTestCase.request_handler.do_GETCs �����z�}�}�-����rc�D�|jtjd�y)NzFile not foundrqr5s r�do_ERRORz6RequestHandlerLoggingTestCase.request_handler.do_ERRORGs���O�O�J�0�0�2B�CrN)r r!r"r�r�r�r�rrrr)r�?s��%��",��	�	Drr)c���tjj|j|j�|_|j
j
�tj�5}|j
jdd�|j
j�ddd�|jj�jd��y#1swY�8xYw)NrLr�z"GET / HTTP/1.1" 200 -
)rNrOrPr/r0r�r�r
�captured_stderrrRrSr��getvalue�endswith)r�errs  r�test_getz&RequestHandlerLoggingTestCase.test_getJs����;�;�-�-�d�i�i����C���������
�
$�
$�
&�#��H�H���U�C�(��H�H� � �"�'�	
����L�L�N�#�#�$>�?�	A�	'�
&�s�(7C�Cc�2�tjj|j|j�|_|j
j
�tj�5}|j
jdd�|j
j�ddd�j�jd�}|j|djd��|j|djd��y#1swY�oxYw)N�ERRORr��
rz code 404, message File not foundr�z"ERROR / HTTP/1.1" 404 -)rNrOrPr/r0r�r�r
r�rRrSr��splitr�r�)rr��liness   r�test_errz&RequestHandlerLoggingTestCase.test_errUs����;�;�-�-�d�i�i����C���������
�
$�
$�
&�#��H�H���W�c�*��H�H� � �"�'�����$�$�T�*������a��)�)�*L�M�N�����a��)�)�*D�E�F�
'�
&�s�(7D
�
DN)r r!r"rr)r�r�rrrr�r�>s��	D�0�	D�	A�
Grr�c�\��eZdZGd�dee�Z�fd�Z�fd�Zdd�Ze	jejdk(d�e	jejdk(d	�e	jejd
�d����Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�SimpleHTTPServerTestCasec��eZdZy)�(SimpleHTTPServerTestCase.request_handlerN)r r!r"rrrr)rcs��rr)c���t�|��tj�|_tj�}tj|�d|_tj|��|_
tjj|j�|_
d|jz|_tjj|jd�}t!|d�5}|j#|j�|j%�ddd�tj&|�j(}t*j*j-|t*j.j0�}|j3d��|_t6j8j;|j=�d�	�|_y#1swY��xYw)
NsWe are the knights who say Ni!)�dirr��test�wbr)�microsecondT��usegmt) �superrGrA�getcwd�cwd�tempfile�
gettempdir�chdirr��mkdtemp�tempdirr��basename�tempdir_name�base_urlr9�openr~�flush�stat�st_mtime�datetime�
fromtimestamp�timezone�utc�replace�last_modif_datetime�email�utils�
formatdate�	timestamp�last_modif_header)r�basetempdir�tempname�temp�mtime�
last_modif�	__class__s      �rrGzSimpleHTTPServerTestCase.setUpfsA���
��
���9�9�;����)�)�+��
�����5��	��'�'�K�8����G�G�,�,�T�\�\�:����d�/�/�/��
��7�7�<�<����f�5��
�(�D�
!�T��J�J�t�y�y�!��J�J�L�"�����!�*�*���&�&�4�4�U����!�!�#�
�#-�#5�#5�!�#5�#D�� �!&���!7�!7�� � �"�4�"8�"1���"�
!�s�,,G�Gc����	tj|j�	tj|j
�t�|��y#Y�xYw#t�|��wxYwr)rArr�shutil�rmtreerr
rK�rr)s �rrKz!SimpleHTTPServerTestCase.tearDown{sP���	��H�H�T�X�X��
��
�
�d�l�l�+�
�G����
����G���s�A�A�A�A�A(c�������fd�}d�|�_�j�}|j��|j�j|�|j�j�|r|j||�|j�jd�|j�jjdd�d�|j�jd�dd��j�|S)Nc�,���j�d�_y)zWDon't close reader yet so we can check if there was leftover
            buffered inputN)�fp)�reader�responses��r�
close_connzDSimpleHTTPServerTestCase.check_status_and_reason.<locals>.close_conn�s����[�[�F��H�Kr�
r`ra�rzConnection should be closed)�_close_connrr�r�r��assertIsNotNone�reason�version�msg�getra)rr2r�r�r3rVr1s `    @r�check_status_and_reasonz0SimpleHTTPServerTestCase.check_status_and_reason�s����	���)����}�}�������!�������&�1����X�_�_�-�����T�4�(�	
����)�)�2�.�������)�)�,��@�'�J�������R��#�/L�M������r�darwinz2undecodable name cannot always be decoded on macOS�win32z+undecodable name cannot be decoded on win32z!need os_helper.TESTFN_UNDECODABLEc���tj�}tjtj
�dz}t
tjj|j|�d�5}|jtj
�ddd�|j|jdz�}tjdk(r-tj|j�D]}|dk7s�	|}n|j|t j"�}t$j&j)|d��}|j+d|zj-|d	�|�|j+d
t/j0|d��zj-|d	�|�|j|jdz|z�}|j|t j"tj
�
�y#1swY��ZxYw)Nz.txtrr�r=r�
surrogatepass)�errorsz	href="%s"�surrogateescape�>%s<F��quote�r�)�sys�getfilesystemencodingrA�fsdecoder�TESTFN_UNDECODABLErr�r9rr~rRr�platform�listdirr<r	r��urllib�parserEr�r|�html�escape)r�enc�filename�fr2�namerV�
quotednames        r�test_undecodable_filenamez2SimpleHTTPServerTestCase.test_undecodable_filename�sv���'�'�)���;�;�y�;�;�<�v�E��
�"�'�'�,�,�t�|�|�X�6��
=��
�G�G�I�0�0�1�>��<�<��
�
�� 3�4���<�<�8�#��
�
�4�<�<�0���6�>�#�H��1��+�+�H�j�m�m�D���\�\�'�'���'�I�
��
�
�{�Z�/��v�c�#4�5�t�	=��
�
�v����H�E� B�B��v�c�#4�5�t�	=��<�<��
�
�� 3�j� @�A���$�$�X�z�}�}�*3�*F�*F�	%�	H�#>�
=�s�/ G'�'G1c�p�|j|jdz�j�}|j|d|j�d�j	d��|j|jdz�j�}|j|d|j�d�j	d��y)Nz/?x=123zlisting for z/\?x=123�latin1z/?x=%bbz/\?x=\xef\xbf\xbd)rRrr�assertRegexr|�rr2s  r�test_undecodable_parameterz3SimpleHTTPServerTestCase.test_undecodable_parameter�s����<�<��
�
�	� 9�:�?�?�A������l�4�=�=�/��#J�#Q�#Q�RZ�#[�\��<�<��
�
�	� 9�:�?�?�A������l�4�=�=�/�AR�#S�#Z�#Z�[c�#d�erc���tjtjj|jd��d|j
�d�}|�d�}|j
|�}|j|tj�|jd�}|j||d��d|��}|j
|�}|j|tj�|jd�}|j|jd�|��|j||d	��d|��}|j
|�}|j|tj�|j|jd�|�d
|��}|�d�}|j
|�}|j|tj�|jd�}|j|jd
�|��y)aIEnsure //evil.co/..%2f../../X does not put //evil.co/ in Location.

        //netloc/ in a Location header is a redirect to a new host.
        https://github.com/python/cpython/issues/87389

        This checks that a path resolving to a directory on our server cannot
        resolve into a redirect to another server.
        �existing_directoryz2/python.org/..%2f..%2f..%2f..%2f..%2f../%0a%0d/../z/existing_directoryr��Locationznon-attack failed!�r:�//zcExpected Location header to start with a single / and end with a / as this is a directory redirect.zhttps://pypi.org/N)rA�mkdirr�r9rrrRr<r	�MOVED_PERMANENTLYr�r��assertFalse�
startswithr�)	r�url�expected_locationr2�location�
attack_url�attack3_url�attack_scheme_netloc_2slash_url�expected_scheme_netloc_locations	         r�3test_get_dir_redirect_location_domain_injection_bugzLSimpleHTTPServerTestCase.test_get_dir_redirect_location_domain_injection_bug�s���	��������d�l�l�,@�A�B�B�4�CT�CT�BU�Uh�i��"�e�1�I���<�<��$���$�$�X�z�/K�/K�L��%�%�j�1������#4�:N��O����Y�
��<�<�
�+���$�$�X�z�/K�/K�L��%�%�j�1������,�,�T�2���A�����#4�@�	�	A�
�3�%�j���<�<��,���$�$�X�z�/K�/K�L�����+�+�J�7�9J�K�->�c�U�*C�'�-L�,M�Q�*O�'��<�<� ?�@���$�$�X�z�/K�/K�L��%�%�j�1��	
����+�+�,?�@�h��Orc�.�|j|jdz�}|j|tj|j
��|j|jdz�}|j|tj�|j|jdz�}|j|tj�|j|j�}|j|tj�|j|jd�d�|j|jdz�}|j|tj�|j|jdz�}|j|tj�|j|jd	�|jd
z�|jd�}|j|tj�|jd�}|j|tj�tjtjj|jd
d��|j|jdz�}|j|tj�d}ttjj|j d�d�5}|j#|�ddd�|j|jdz�}|j|tj|�tj$dk(r�tj&�dk7r�tj(|jd�	|j|jdz�}|j|tj�tj(|jd�yyy#1swY��xYw#tj(|jd�wxYw)N�/testrF�/test/r�r��0�/?hi=2�?hi=1r^�/?hi=1z/ThisDoesNotExistz/ThisDoesNotExist/�spamz
index.htmlz/spam/sDummy index file
r�posixri�)rRrr<r	r�r�rrrbr�r�rA�makedirsr�r9rrrr~rT�geteuid�chmod)rr2r�rSs    rr�z!SimpleHTTPServerTestCase.test_get�s����<�<��
�
�� 7�8���$�$�X�z�}�}�4�9�9�$�M��<�<��
�
�� 8�9���$�$�X�z�/C�/C�D��<�<��
�
�� 3�4���$�$�X�z�}�}�=��<�<��
�
�.���$�$�X�z�/K�/K�L�����+�+�,<�=�s�C��<�<��
�
�� 8�9���$�$�X�z�}�}�=��<�<��
�
�� 7�8���$�$�X�z�/K�/K�L�����+�+�J�7�����1�	3��<�<� 3�4���$�$�X�z�/C�/C�D��<�<� >�?���$�$�X�z�/C�/C�D�
���B�G�G�L�L����v�|�D�E��<�<��
�
�� 8�9���$�$�X�z�}�}�=�&��
�"�'�'�,�,�t�0�0�,�?��
F�!�
�G�G�D�M�G��<�<��
�
�� 3�4���$�$�X�z�}�}�d�C��7�7�g��"�*�*�,�!�"3��H�H�T�\�\�1�%�
.��<�<��
�
��(;�<���,�,�X�z�7K�7K�L�������u�-�
#4��G�
F��������u�-�s�!O&�>O2�&O/�2"Pc�@�|j|jdzd��}|j|tj�|j|j
d�tt|j���|j|j
d�d�y)Nrnr��rUzcontent-lengthzcontent-typezapplication/octet-stream)
rRrr<r	r�r�r��strr�r�rZs  r�	test_headz"SimpleHTTPServerTestCase.test_heads����<�<��M�M�G�#�F� �4���$�$�X�z�}�}�=�����+�+�,<�=��S����^�,�	.�����+�+�N�;�3�	5rc�(�tjj�}|j|d<|j	|j
dz|��}|j
|tj�|jtjd��z}tjj�}tjj|d��|d<|j	|j
dz|��}|j
|tj�y)	z�Check that when a request to /test is sent with the request header
        If-Modified-Since set to date of last modification, the server returns
        status code 304, not 200
        �If-Modified-Sincernr�r�)�hoursTrN)r�message�Messager#rRrr<r	r�rr�	timedeltar �format_datetime)rrWr2�new_dts    r�test_browser_cachez+SimpleHTTPServerTestCase.test_browser_cache's���
�-�-�'�'�)��'+�'=�'=��#�$��<�<��
�
�� 7��<�I���$�$�X�z�/F�/F�G��)�)�H�,>�,>�Q�,G�G���-�-�'�'�)��',�{�{�'B�'B�6��(C�(��#�$��<�<��
�
�� 7��<�I���$�$�X�z�/F�/F�Grc�R�|j}|tjd��z
}tjj�}tjj|d��|d<|j|jdz|��}|j|tj�y)Nim)�daysTrr~rnr�)
rrr�rr�r�r r�rRrr<r	r�)r�dt�old_dtrWr2s     r�test_browser_cache_file_changedz8SimpleHTTPServerTestCase.test_browser_cache_file_changed9s���
�
%�
%���h�(�(�c�2�2���-�-�'�'�)��',�{�{�'B�'B�6��(C�(��#�$��<�<��
�
�� 7��<�I���$�$�X�z�}�}�=rc���tjj�}|j|d<d|d<|j	|j
dz|��}|j
|tj�y)Nr~�*z
If-None-Matchrnr�)	rr�r�r#rRrr<r	r�)rrWr2s   r�,test_browser_cache_with_If_None_Match_headerzESimpleHTTPServerTestCase.test_browser_cache_with_If_None_Match_headerDs`���-�-�'�'�)��'+�'=�'=��#�$�#&��� ��<�<��
�
�� 7��<�I���$�$�X�z�}�}�=rc�6�|jdd��}|j|tj�|jdd��}|j|tj�|jdd��}|j|tj�y)Nr��FOOrz�custom�GETs)rRr<r	r�rZs  r�test_invalid_requestsz.SimpleHTTPServerTestCase.test_invalid_requestsMsz���<�<��E�<�2���$�$�X�z�/I�/I�J��<�<��H�<�5���$�$�X�z�/I�/I�J��<�<��F�<�3���$�$�X�z�/I�/I�Jrc���|j|jdz�}|j|tj|j
��|jd}|j||j�y)z�Checks that the datetime returned in Last-Modified response header
        is the actual datetime of last modification, rounded to the second
        rnrFz
Last-modifiedN)	rRrr<r	r�r�rWr�r#)rr2r#s   r�test_last_modifiedz+SimpleHTTPServerTestCase.test_last_modifiedVs`���<�<��
�
�� 7�8���$�$�X�z�}�}�4�9�9�$�M�$�,�,�_�=�����*�D�,B�,B�Crc�Z�|j|jdz�}|j|tj|j
��|j|jdz�}|j|tj�|j|jdz�}|j|tj�|j|j�}|j|tj�|j|jdz�}|j|tj�|j|jdz�}|j|tj�|j|jd�|jdz�y)	NrnrFror�rqrrr^rs)
rRrr<r	r�r�rrrbr�r�rZs  r�test_path_without_leading_slashz8SimpleHTTPServerTestCase.test_path_without_leading_slash_sC���<�<�� 1� 1�G� ;�<���$�$�X�z�}�}�4�9�9�$�M��<�<�� 1� 1�H� <�=���$�$�X�z�/C�/C�D��<�<�� 1� 1�C� 7�8���$�$�X�z�}�}�=��<�<�� 1� 1�2���$�$�X�z�/K�/K�L��<�<�� 1� 1�H� <�=���$�$�X�z�}�}�=��<�<�� 1� 1�G� ;�<���$�$�X�z�/K�/K�L�����+�+�J�7��*�*�X�5�	7rc��d}tjj|j|�}	t	|d�j�	|j|jdz�}|j|tj�}|jj�}tj |�|j#|�dt%j&|d��z}|j)|j+|�|�y#t$rtjd|z��wxYw#tj |�wxYw)Nz<test&>.txtrz-Can not create file %s on current file systemr�rCFrD)rAr�r9rrra�OSError�unittest�SkipTestrRrr<r	r�rW�get_content_charset�unlinkr7rOrPr�r|)rrR�fullpathr2rVrQ�	html_texts       r�test_html_escape_filenamez2SimpleHTTPServerTestCase.test_html_escape_filenameos�� ���7�7�<�<����h�7��	9���4� �&�&�(�
	 ��|�|�D�M�M�C�$7�8�H��/�/��*�-�-�H�D��"�"�6�6�8�C��I�I�h�����S�!��T�[�[���?�?�	��
�
�i�&�&�s�+�T�2���	9��#�#�%-�/7�%8�9�
9�	9��
�I�I�h��s�D�	AD(�"D%�(D?r)r r!r"rrr)rGrKr<r��skipIfrGrK�
skipUnlessrrJrVr[rlr�r|r�r�r�r�r�r�r��
__classcell__�r)s@rrrbs����
�-�/G�
�1�*��2�X�_�_�S�\�\�X�-�I�K��X�_�_�S�\�\�W�,�B�D��X����5�5�<�>�H�>�D�K�H�.f�/P�b(.�T5�H�$	>�>�K�D�7� 3rrzD#!%s

print("Content-type: text/html")
print()
print("Hello World")
a�#!%s
import os
import sys
import urllib.parse

print("Content-type: text/html")
print()

content_length = int(os.environ["CONTENT_LENGTH"])
query_string = sys.stdin.buffer.read(content_length)
params = {key.decode("utf-8"): val.decode("utf-8")
            for key, val in urllib.parse.parse_qsl(query_string)}

print("%%s, %%s, %%s" %% (params["spam"], params["eggs"], params["bacon"]))
zR#!%s
import os

print("Content-type: text/html")
print()

print(os.environ["%s"])
a'#!%s
import os

print("X-ambv: was here")
print("Content-type: text/html")
print()
print("<pre>")
for k, v in os.environ.items():
    try:
        k.encode('ascii')
        v.encode('ascii')
    except UnicodeEncodeError:
        continue  # see: BPO-44647
    print(f"{k}={v}")
print("</pre>")
rwz7This test can't be run reliably as root (issue #13308).c��eZdZGd�dee�Zejjd�Zd�Z	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�CGIHTTPServerTestCasec���eZdZ�fd�Z�xZS)�%CGIHTTPServerTestCase.request_handlerc���tjdt��5t�|��cddd�S#1swYyxYw)N�ignore)�action�category)�warnings�catch_warnings�DeprecationWarningr
�run_cgir-s �rr�z-CGIHTTPServerTestCase.request_handler.run_cgi�s-����(�(��CU�V��w��(�W�V�V�s�5�>)r r!r"r�r�r�s@rr)r��s
���	)�	)rr)�asciic��tj|�tj�|_tj�|_tjj|jd�|_
tjj|jd�|_tjj|jd�|_tjj|jd�|_
tjj|jd�|_tj|j�tj|j�tj|j�tj|j�tj|j�d|_d|_d|_d|_d|_d|_d|_t/j0�rbtjj|jd�|_t5j6|j2�j9�|_nt:j<|_	|j2j?d�tjj|jd�|_tG|j d	d�
�5}|jItJ|j2z�ddd�tjL|j d�tjj|jd�|_tG|j"d	d�
�5}|jItJ|j2z�ddd�tjL|j"d�tjj|jd
�|_tG|j$d	d�
�5}|jItN|j2z�ddd�tjL|j$d�tjj|jd�|_tG|j&d	d�
�5}|jItJ|j2z�ddd�tjL|j&d�tjj|jd�|_tG|j(d	d�
�5}|jItP|j2dfz�ddd�tjL|j(d�tjj|jd�|_tG|j*d	d�
�5}|jItJ|j2z�ddd�tjL|j*d�tjj|jd�|_)tG|jRd	d�
�5}|jItT|j2z�ddd�tjL|jRd�tjV|j�y#t@$r%|jC�|jEd�Y��MwxYw#1swY���xYw#1swY��dxYw#1swY���xYw#1swY��ZxYw#1swY���xYw#1swY��NxYw#1swY��xYw)Nzcgi-binz	child-dir�subr�pythonr{z0Python executable path is not encodable to utf-8znocgi.py�w)�encodingi�zfile1.pyzfile2.pyzfile3.pyzfile4.py�QUERY_STRINGzfile5.pyzfile6.py),r<rGrArrr
r�
parent_dirr�r9�cgi_dir�
cgi_child_dir�	sub_dir_1�	sub_dir_2�cgi_dir_in_sub_dirra�
nocgi_path�
file1_path�
file2_path�
file3_path�
file4_path�
file5_path�_pythonexe_symlinkr�can_symlink�	pythonexer
�
PythonSymlink�	__enter__rG�
executabler|�UnicodeEncodeErrorrK�skipTestrr~�	cgi_file1rx�	cgi_file2�	cgi_file4�
file6_path�	cgi_file6r)rr0�file1�file2�file3�file4�file5�file6s        rrGzCGIHTTPServerTestCase.setUp�s������4� ��9�9�;���"�*�*�,����w�w�|�|�D�O�O�Y�?����W�W�\�\�$�,�,��D��������d�o�o�u�=��������d�n�n�e�<���"$�'�'�,�,�t�~�~�y�"I���
�������
����#�#�$�
������ �
������ �
����(�(�)�������������������#'���� � �"��W�W�\�\�$�/�/�8�D�D�N�&-�&;�&;�D�N�N�&K�&U�&U�&W�D�#� �^�^�D�N�	N�
�N�N�!�!�'�*�
�'�'�,�,�t���
�C���
�$�/�/�3��
9�R��H�H�Y����/�0�:�
������%�(��'�'�,�,�t�|�|�Z�@���
�$�/�/�3��
9�U��K�K�	�D�N�N�2�3�:�
������%�(��'�'�,�,�t�|�|�Z�@���
�$�/�/�3��
9�U��K�K�	�D�N�N�2�3�:�
������%�(��'�'�,�,�t�'9�'9�:�F���
�$�/�/�3��
9�U��K�K�	�D�N�N�2�3�:�
������%�(��'�'�,�,�t�|�|�Z�@���
�$�/�/�3��
9�U��K�K�	�T�^�^�^�$D�D�E�:�
������%�(��'�'�,�,�t�'>�'>�
�K���
�$�/�/�3��
9�U��K�K�	�D�N�N�2�3�:�
������%�(��'�'�,�,�t�|�|�Z�@���
�$�/�/�3��
9�U��K�K�	�D�N�N�2�3�:�
������%�(�
������!��O"�	N��M�M�O��M�M�L�M�	N��
:�
9��
:�
9��
:�
9��
:�
9��
:�
9��
:�
9��
:�
9�sf�[�-#[7�?#\�#\�##\�5%\+�	#\8�#]�*[4�3[4�7\�\�\�\(�+\5�8]�]c�<�	tj|j�|jr|jj	ddd�|j
rtj|j
�|jrtj|j�|jrtj|j�|jrtj|j�|jrtj|j�|jrtj|j�|jrtj|j�tj|j�tj|j�tj|j �tj|j"�tj|j$�t'j(tj*j-|j.d��tj|j.�t0j3|�y#t0j3|�wxYw)Nzgmon.out)rArrr�rIr��remover�r�r�r�r�r��rmdirr�r�r�r�r�rr�r�r9r�r<rKr5s rrKzCGIHTTPServerTestCase.tearDowns}��	(��H�H�T�X�X���&�&��'�'�0�0��t�T�B�����	�	�$�/�/�*�����	�	�$�/�/�*�����	�	�$�/�/�*�����	�	�$�/�/�*�����	�	�$�/�/�*�����	�	�$�/�/�*�����	�	�$�/�/�*��H�H�T�'�'�(��H�H�T�\�\�"��H�H�T�,�,�-��H�H�T�^�^�$��H�H�T�^�^�$�
���R�W�W�\�\�$�/�/�:�F�G��H�H�T�_�_�%��!�!�$�'��L�!�!�$�'�s�I,J�Jc
���idd�dt�dt�dd�dd�dd�dd�d	d
�d
d
�dd�d
d�dd�dd�dd�dd�dd�dd�dddddtddtddd��}|j�D]y\}}t|t�r2t	|t
�r"|j
|tj|��Htj|�}|j||d|�d|�d|�����{y)Nrr`z..z/.//..r�z/\z//\z/.//�cgi-bin/file1.py�/cgi-bin/file1.py�az//az/az./az./C:/z/C:/z/a/bz/a/b/z/a/b/.z/a/b/dz/a/b/d/fz/a/b/fz/a/fz//f)z	/a/b/c/..z/a/b/c/../dz/a/b/c/../d/e/../fz/a/b/c/../d/e/../../fz/a/b/c/../d/e/.././././..//fz../a/b/c/../d/e/.././././..//fz/a/b/c/../d/e/../../../fz/a/b/c/../d/e/../../../../fz/a/b/c/../d/e/../../../../../fz/a/b/c/../d/e/../../../../f/..z /a/b/c/../d/e/../../../../f/../.zpath = z	
Got:    z	
Wanted: r_)
�
IndexError�items�
isinstance�type�
issubclass�	Exception�assertRaisesr�_url_collapse_pathr�)r�test_vectorsr��expected�actuals     r�test_url_collapse_pathz,CGIHTTPServerTestCase.test_url_collapse_path2sx��
���
��*�
�
�j�
�
��	
�

�$�
�
�6�

�
�D�
�
� 3�
�
 �!4�
�
��
�
�%�
�
�5�
�
�5�
�
�V�
�
�F�
� 
�W�!
�"
�g�#
�$!�#�",�%-�,4�.8�(.�+0�.8�.2�04�9
��<+�0�0�2�N�D�(��(�D�)�j��9�.M��!�!�(�"(�";�";�T�C� �2�2�4�8��� � ��6�"&���&:�!�;�
3rc���|jd�}|j|j�|jd�|jfd|j
zdtjf�y)Nr��Content-type�Hello Worldr_)rRr�rr�r��linesepr	r�r�s  r�test_headers_and_contentz.CGIHTTPServerTestCase.test_headers_and_content\sT���l�l�.�/�����
�X�X�Z����~�6��
�
�C�
�d�l�l�
*�K����G�	Irc�z�|jd�}|j|jtj�y)Nz)///////////nocgi.py/../cgi-bin/nothere.sh)rRr�r�r	rrr�s  r�test_issue19435z%CGIHTTPServerTestCase.test_issue19435bs+���l�l�F�G��������Z�%9�%9�:rc���tjjdddd��}ddi}|jdd||�}|j	|j�d	|jz�y)
Nr�r�i@�)rt�eggs�baconr�z!application/x-www-form-urlencodedz/cgi-bin/file2.py�POSTs1, python, 123456)rMrN�	urlencoderRr�rr�)r�paramsrWr�s    r�	test_postzCGIHTTPServerTestCase.test_postfs`�����'�'��(�f�=�?��!�$G�H���l�l�.����H���������%9�D�L�L�%H�Irc��|jd�}|j�|j|jtj
�y)Nz/cgi-bin/invalid)rRrr�r�r	rrr�s  r�test_invaliduriz%CGIHTTPServerTestCase.test_invalidurins4���l�l�-�.�����
�������Z�%9�%9�:rc��ddtjd�zi}|jdd|��}|jd|jzdt
jf|j�|jd	�|jf�y)
Ns
AuthorizationsBasic s
username:passr�rLr�r�r_r�)
�base64�	b64encoderRr�r�r	r�rr�r�)rrWr�s   r�test_authorizationz(CGIHTTPServerTestCase.test_authorizationssz��#�i��#�#�$4�5�'6�7���l�l�.��w�l�G�����
�d�l�l�
*�K����G�
�X�X�Z����~�6��
�
�C�	Erc���|jd�}|jd|jzdtjf|j�|j
d�|jf�y)Nr�r�r_r��rRr�r�r	r�rr�r�r�s  r�test_no_leading_slashz+CGIHTTPServerTestCase.test_no_leading_slash{sT���l�l�-�.�����
�d�l�l�
*�K����G�
�X�X�Z����~�6��
�
�C�	Erc�J�d}|tjd<|jd�}|jd|jzdt
jf|j�|jd�|jf�|jtjd|�y)NzTest CGI Server�SERVER_SOFTWAREr�r�r_r�)
rArBrRr�r�r	r�rr�r�)r�	signaturer�s   r�test_os_environ_is_not_alteredz4CGIHTTPServerTestCase.test_os_environ_is_not_altered�s���%�	�(1��
�
�$�%��l�l�.�/�����
�d�l�l�
*�K����G�
�X�X�Z����~�6��
�
�C�	E�	
������$5�6�	�Brc���|jd�}|jd|jzdtjf|j�|j
d�|jf�y)Nz/cgi-bin%2ffile1.pyr�r_r�r�r�s  r�#test_urlquote_decoding_in_cgi_checkz9CGIHTTPServerTestCase.test_urlquote_decoding_in_cgi_check�sT���l�l�0�1�����
�d�l�l�
*�K����G�
�X�X�Z����~�6��
�
�C�	Erc���|jd�}|jd|jzdtjf|j�|j
d�|jf�y)Nz/cgi-bin/child-dir/file3.pyr�r_r�r�r�s  r�test_nested_cgi_path_issue21323z5CGIHTTPServerTestCase.test_nested_cgi_path_issue21323�sT���l�l�8�9�����
�d�l�l�
*�K����G�
�X�X�Z����~�6��
�
�C�	Erc���|jd�}|jd|jzdtjf|j�|j
d�|jf�y)Nz/cgi-bin/file4.py?a=b?c=dsa=b?c=dr_r�r�r�s  r�&test_query_with_multiple_question_markz<CGIHTTPServerTestCase.test_query_with_multiple_question_mark�sT���l�l�6�7�����
�$�,�,�
&��Z�]�]�C�
�X�X�Z����~�6��
�
�C�	Erc���|jd�}|jd|jzdtjf|j�|j
d�|jf�y)Nz0/cgi-bin/file4.py?k=aa%2F%2Fbb&//q//p//=//a//b//sk=aa%2F%2Fbb&//q//p//=//a//b//r_r�r�r�s  r�"test_query_with_continuous_slashesz8CGIHTTPServerTestCase.test_query_with_continuous_slashes�sW���l�l�M�N�����
.����
=�
�*�-�-�
)�
�X�X�Z����~�6��
�
�C�	Erc��	tjjd�|jd�}|j	d|j
zdtjf|j�|jd�|jf�tjjd�y#tjjd�wxYw)Nz/sub/dir/cgi-binz/sub/dir/cgi-bin/file5.pyr�r_r�)r�cgi_directories�appendrRr�r�r	r�rr�r�r�r�s  r� test_cgi_path_in_sub_directoriesz6CGIHTTPServerTestCase.test_cgi_path_in_sub_directories�s���	M�!�1�1�8�8�9K�L��,�,�:�;�C�����$�,�,�.��Z�]�]�K�����S�]�]�>�:�C�J�J�G�
I�
"�1�1�8�8�9K�L��!�1�1�8�8�9K�L�s�B
B,�,!C
c��d}d|ff|fddf}|D]�\}}t|�}|j|�5|jdd|��}|jtj
j|j�d|��jd	�}|j||j��ddd���y#1swY��xYw)
Nz?text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8�Accept)rr)))rr_)�ACCEPTz
text/plainztext/html,text/plainz/cgi-bin/file6.pyrLr�zHTTP_ACCEPT=r�)r�subTestrRr�rNr	r�r�r|r�r)r�browser_accept�testsrWr�r�s      r�test_acceptz!CGIHTTPServerTestCase.test_accept�s���U�	���(�
*�N�;��
'�	
��"'��G�X�!�'�*�G����g�&��l�l�#6��w�l�O��� � ����!3�!3�S�Z�Z�@�)�(��4�;�;�G�D���
�
�h����
�3�	'�&�"'�&�&�s�A=B9�9C	N)r r!r"rrr)rAr�r|rGrKr�r�r�r�r�r�r�rrrr	rrrrrrr�r��s���)�-�/D�)��j�j����(�G�J"�X(�>(;�TI�;�J�;�
E�E�C�E�E�E�E�M�4rr�c�,��eZdZd�fd�	Zd�Zd�Z�xZS)�SocketlessRequestHandlerc���tj�}t�|j_t
�|�|dd|��d|_d|_y)N��	directoryFr\)	r
�Mockr�makefile�return_valuer
r(�
get_calledr�)rrrRr)s   �rr(z!SocketlessRequestHandler.__init__�sC����)�)�+��(/�	����%�
����$��	��B���� *��rc���d|_|jtj�|j	dd�|j�|jjd�y)NTr^r_� <html><body>Data</body></html>
)rrcr	r�rerfr}r~r5s rr�zSocketlessRequestHandler.do_GET�sJ��������:�=�=�)������5������
�
���>�?rc��yrr)rr�rs   rrz$SocketlessRequestHandler.log_message�s��rr)r r!r"r(r�rr�r�s@rrr�s���+�@�
rrc��eZdZd�Zy)�!RejectingSocketlessRequestHandlerc�B�|jtj�y)NF)rnr	�EXPECTATION_FAILEDr5s r�handle_expect_100z3RejectingSocketlessRequestHandler.handle_expect_100�s�����
�5�5�6�rN)r r!r"r'rrrr$r$�s��rr$c�.�eZdZd�Zd�Zd�Zed��Zy)�AuditableBytesIOc��g|_yr)�datasr5s rr(zAuditableBytesIO.__init__�s	����
rc�:�|jj|�yr)r+r)rr�s  rr~zAuditableBytesIO.write�s���
�
���$�rc�8�dj|j�S)Nr)r9r+r5s r�getDatazAuditableBytesIO.getData�s���x�x��
�
�#�#rc�,�t|j�Sr)r�r+r5s r�	numWriteszAuditableBytesIO.numWrites�s���4�:�:��rN)r r!r"r(r~r.�propertyr0rrrr)r)�s%��� �$����rr)c��eZdZdZej
d�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�BaseHTTPRequestHandlerTestCasezrTest the functionality of the BaseHTTPServer.

       Test the support for the Expect 100-continue header.
       sHTTP/1.[0-9]+ 200 OKc�"�t�|_yr)r�handlerr5s rrGz$BaseHTTPRequestHandlerTestCase.setUp�s��/�1��rc���t|�}t�}||j_||j_|jj	�|jd�|j
�S�Nr)rr5�rfiler}�handle_one_request�seek�	readlines)rr��input�outputs    r�send_typical_requestz3BaseHTTPRequestHandlerTestCase.send_typical_request�sU���� �����"�����#��������'�'�)����A�����!�!rc�N�|j|jj�yr)r�r5rr5s r�verify_get_calledz0BaseHTTPRequestHandlerTestCase.verify_get_called�s��������/�/�0rc�\��dD]&�|jt�fd�|D��d��(y)N)sServer: sDate: sContent-Type: c3�@�K�|]}|j�����y�wr)rd)�.0�h�	fieldNames  �r�	<genexpr>zIBaseHTTPRequestHandlerTestCase.verify_expected_headers.<locals>.<genexpr>s����� J�'�Q����i�!8�'�s�r�)r��sum)rrWrEs  @r�verify_expected_headersz6BaseHTTPRequestHandlerTestCase.verify_expected_headerss)���B�I����S� J�'� J�J�A�N�Crc�\�|jj|�}|j|�yr)�HTTPResponseMatch�searchr7)rr2�matchs   r�verify_http_server_responsez:BaseHTTPRequestHandlerTestCase.verify_http_server_responses&���&�&�-�-�h�7�����U�#rc���d|j_tj}tj
j
tdt��5}||jd�||jd�||jdd�||jdd�||jd�ddd�j�}|jd	|�|jd
|�|j�}|jd|d�|jd|d
�|jd|d�|jd|d�|jd|d�y#1swY��xYw)N)�	127.0.0.1i9�stderrz/fooz/barz	/spam %s.r�uŸ beansz"GET /foo\b"ar HTTP/1.0"��rz/\x1bbar\x00\x1br�z/spam a.�u/spam \x1b\x7f\x9f beans.�z"GET /foo\\b"ar\x07 HTTP/1.0"�)
r5�client_addressrrr
�patch�objectrGrr��assertNotIn�
splitlinesr�)rr�fake_stderrrPr�s     r�test_unprintable_not_loggedz:BaseHTTPRequestHandlerTestCase.test_unprintable_not_logged	s+��':����#�,�8�8��
�Z�Z�
�
�s�H�h�j�
9�[�����f�-�����&8�9�����k�3�7�����k�3J�K�����&E�F�:��%�%�'�������(������(��!�!�#���
�
�f�e�A�h�'��
�
�)�5��8�4��
�
�j�%��(�+��
�
�7��q��B��
�
�6��a��A�:�
9�s
�A"E'�'E0c�X�|jd�}|j|d�|j|dd�|j�|j	|dd�|j	|j
jd�|j	|j
jd�|j	|j
jd�|j	|j
jd	�|j|j
jj�d
�y)N�GET / HTTP/1.1

rr����r!�GET / HTTP/1.1rLr�r\r�
r>rMrHr@r�r5�requestline�commandr��request_version�assertSequenceEqualrWr��r�results  r�
test_http_1_1z,BaseHTTPRequestHandlerTestCase.test_http_1_1�����*�*�+D�E���(�(����3��$�$�V�A�b�\�2���� �������%J�K�������1�1�3C�D�������-�-�u�5�������*�*�C�0�������5�5�z�B�� � ����!5�!5�!;�!;�!=�r�Brc�X�|jd�}|j|d�|j|dd�|j�|j	|dd�|j	|j
jd�|j	|j
jd�|j	|j
jd�|j	|j
jd	�|j|j
jj�d
�y)NsGET / HTTP/1.0

rr�r_r!�GET / HTTP/1.0rLr��HTTP/1.0rrarfs  r�
test_http_1_0z,BaseHTTPRequestHandlerTestCase.test_http_1_0*rirc��|jd�}|jt|�d�|j|dd�|j�y)NsGET / HTTP/0.9

r�rr!)r>r�r�r@rfs  r�
test_http_0_9z,BaseHTTPRequestHandlerTestCase.test_http_0_96sH���*�*�+D�E������V��a�(�������$I�J���� rc��|jd�}|j|djd��|j|d|j	d��|j|jj�y)Ns)GET /spaced out HTTP/1.1
Host: dummy

rs
HTTP/1.1 400 r��
)r>r�rdrH�indexrcr5rrfs  r�test_extra_spacez/BaseHTTPRequestHandlerTestCase.test_extra_space<sk���*�*�
�
��
	
����q�	�,�,�-=�>�?��$�$�V�A�f�l�l�7�.C�%D�E�������0�0�1rc�\�|jd�}|j|d�|j|dd�|j�|j	|dd�|j	|j
jd�|j	|j
jd�|j	|j
jd�|j	|j
jd	�d
}|j|j
jj�|�y)Ns(GET / HTTP/1.0
Expect: 100-continue

rr�r_r!rkrLr�rl�)�Expectz100-continuera�rrgrWs   r�test_with_continue_1_0z5BaseHTTPRequestHandlerTestCase.test_with_continue_1_0Fs����*�*�+\�]���(�(����3��$�$�V�A�b�\�2���� �������%J�K�������1�1�3C�D�������-�-�u�5�������*�*�C�0�������5�5�z�B�/��� � ����!5�!5�!;�!;�!=�w�Grc��|jd�}|j|dd�|j|dd�|j|dd�|j|dd�|j�|j|dd	�|j|jj
d
�|j|jjd�|j|jjd�|j|jjd
�d}|j|jjj�|�y)N�(GET / HTTP/1.1
Expect: 100-continue

rsHTTP/1.1 100 Continue
r�rqrSsHTTP/1.1 200 OK
r_r!r`rLr�r\ru)r>r�rHr@r5rbrcr�rdrerWr�rws   r�test_with_continue_1_1z5BaseHTTPRequestHandlerTestCase.test_with_continue_1_1Ss���*�*�+\�]��������$@�A�������G�,�������$:�;��$�$�V�A�b�\�2���� �������%J�K�������1�1�3C�D�������-�-�u�5�������*�*�C�0�������5�5�z�B�/��� � ����!5�!5�!;�!;�!=�w�Grc���td�}t�}t�}||_||_d|_d|_d|_|jd�|j|jd�y)Nr^r\r�rS)rr)rr8r}rdrbrcrnr�r0�rr<r=r5s    r�#test_header_buffering_of_send_errorzBBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_errorbsf���1�2��!�#��*�,����
���
�",��� ���������3������)�)�1�-rc��td�}t�}t�}||_||_d|_|j
d�|j|jd�|j�|j|jd�y)Nr^r\r}rr�)
rr)rr8r}rd�send_response_onlyr�r0rfr~s    r�+test_header_buffering_of_send_response_onlyzJBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_response_onlypsy���1�2��!�#��*�,����
���
�",����"�"�3�'�����)�)�1�-���������)�)�1�-rc��td�}t�}t�}||_||_d|_|j
dd�|j
dd�|j|jd�|j�|j|j�d�|j|jd�y)	Nr^r\�Foo�foo�barrsFoo: foo
bar: bar

r�)rr)rr8r}rdrer�r0rfr.r~s    r�$test_header_buffering_of_send_headerzCBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_header~s����1�2��!�#��*�,����
���
�",������E�5�)����E�5�)�����)�)�1�-�����������)�+J�K�����)�)�1�-rc��d�}td�}t�}||j_||j_d|j_|jj�|j
||�d�||�jd�}|j|dd�|j|dd�|j|d	d
�y)Nc��|j�}|jd�|j�}|j|�|Sr7)�tellr:r)rS�posr�s   r�_readAndReseekz[BaseHTTPRequestHandlerTestCase.test_header_unbuffered_when_continue.<locals>._readAndReseek�s3���&�&�(�C�
�F�F�1�I��6�6�8�D�
�F�F�3�K��Krrzr\rrqrsHTTP/1.1 100 Continuer�rSsHTTP/1.1 200 OK)	rr5r8r}rdr9�assertNotEqualr�r�)rr�r<r=rgs     r�$test_header_unbuffered_when_continuezCBaseHTTPRequestHandlerTestCase.test_header_unbuffered_when_continue�s���	��I�J�����"�����#�����'1����$����'�'�)����N�6�2�C�8���'�-�-�g�6��������$<�=�������C�(�������$6�7rc�P�|j}t�|_|jd�}|j|dd�|j	|dd�|j|jj�|jtd�|ddD��d�||_y)Nrzrs!HTTP/1.1 417 Expectation Failed
r�r_c3�&K�|]	}|dk(���y�w)sConnection: close
Nr)rC�rs  rrFzMBaseHTTPRequestHandlerTestCase.test_with_continue_rejected.<locals>.<genexpr>�s����Q�L�q�Q�":�:�L�s�)r5r$r>r�rHrcrrG)r�
usual_handlerrgs   r�test_with_continue_rejectedz:BaseHTTPRequestHandlerTestCase.test_with_continue_rejected�s������
�8�:����*�*�+\�]��������$J�K��$�$�V�A�b�\�2�	
������0�0�1�����Q�F�1�R�L�Q�Q�ST�U�$��rc��|jdddzz�}|j|dd�|j|jj�|j|jjt�y)NsGET �x�rs#HTTP/1.1 414 Request-URI Too Long
)r>r�rcr5r�assertIsInstancerbr{rfs  r�test_request_lengthz2BaseHTTPRequestHandlerTestCase.test_request_length�sd���*�*�7�T�E�\�+A�B��������$L�M�������0�0�1����d�l�l�6�6��<rc��|jdddzzdz�}|j|dd�|j|jj�|j|jj
d�y)NsGET / HTTP/1.1
X-Foo: bar�rr�s

rsHTTP/1.1 431 Line too long
r`�r>r�rcr5rrbrfs  r�test_header_lengthz1BaseHTTPRequestHandlerTestCase.test_header_length�sl���*�*�+�d�U�l�:�[�H�J��������$E�F�������0�0�1�������1�1�3C�Drc���|jd�}|j|dd�|j|jj�|j|jj
d�y)Ns�GET / HTTP/1.1
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar
X-Foo: bar

rsHTTP/1.1 431 Too many headers
r`r�rfs  r�test_too_many_headersz4BaseHTTPRequestHandlerTestCase.test_too_many_headers�s^���*�*�E�G��������$H�I�������0�0�1�������1�1�3C�Drc��|jd�}dj|�}d}|jtj|d��jd�|�y)Ns*<script>alert("hello")</script> / HTTP/1.1rz<script>alert("hello")</script>FrDr�)r>r9r�rOrPr|)rrg�texts   r�test_html_escape_on_errorz8BaseHTTPRequestHandlerTestCase.test_html_escape_on_error�sL���*�*�9�;�����&�!��0���
�
�d�k�k�$�e�4�;�;�G�D�f�Mrc�6�����fd�}|�j_td���jj��j	t
t��td���jj��j	t
t��y)Nc�:��t���j_yr)�nextr5�close_connection)�close_valuesrs��rr9zPBaseHTTPRequestHandlerTestCase.test_close_connection.<locals>.handle_one_request�s���,0��,>�D�L�L�)r)T)FFT)r5r9�iter�handler��
StopIterationr�)rr9r�s` @r�test_close_connectionz4BaseHTTPRequestHandlerTestCase.test_close_connection�sl���	?�*<����'��G�}�����������-��|�<��0�1�����������-��|�<rc	�6�tj�}tj|�\	}}}}}}}}	}
d|jj|||jj|||||fz}|j|jj
|��|�y)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)r")�time�gmtimer5�weekdayname�	monthnamer��date_time_string)r�now�year�month�day�hh�mm�ss�wd�y�zr�s            r�test_date_time_stringz4BaseHTTPRequestHandlerTestCase.test_date_time_string�s����i�i�k��15���S�1A�.��e�S�"�b�"�b�!�Q�8��L�L�$�$�R�(���L�L�"�"�5�)��"�b�"�	<
�
��	
������6�6��6�E�x�PrN)r r!r"�__doc__�re�compilerJrGr>r@rHrMr\rhrmrorsrxr{rr�r�r�r�r�r�r�r�r�r�rrrr3r3�s����
#��
�
�#:�;��2�"�1�O�$�B�*
C�
C�!�2�H�
H�.�.�.� 8�,
%�=�E�E�N�
=�
Qrr3c�(�eZdZdZd�Zd�Zd�Zd�Zy)� SimpleHTTPRequestHandlerTestCasez Test url parsing c��tjjtj�d�|_tjjdd�|_tjjdd�|_t�|_td��|_	ttjd���|_y)NrRr�r�r)
rAr�r9r�translated_1�translated_2�translated_3r�	handler_1�	handler_2�pathlib�PurePath�	handler_3r5s rrGz&SimpleHTTPRequestHandlerTestCase.setUp�sz���G�G�L�L�����j�A����G�G�L�L��
�;����G�G�L�L��
�;���1�3���1�E�B���1�G�<L�<L�U�<S�T��rc���|jjd�}|j||j�|jjd�}|j||j
�|jjd�}|j||j�|jjd�}|j||j�|jjd�}|j||j
�|jjd�}|j||j�|jjd�}|j||j�|jjd�}|j||j
�|jjd�}|j||j�y)Nz	/filenamez/filename?foo=barz/filename?a=b&spam=eggs#zot�r��translate_pathr�r�r�r�r�r��rr�s  r�test_query_argumentsz5SimpleHTTPRequestHandlerTestCase.test_query_arguments�s����~�~�,�,�[�9������t�0�0�1��~�~�,�,�[�9������t�0�0�1��~�~�,�,�[�9������t�0�0�1��~�~�,�,�-@�A������t�0�0�1��~�~�,�,�-@�A������t�0�0�1��~�~�,�,�-@�A������t�0�0�1��~�~�,�,�-J�K������t�0�0�1��~�~�,�,�-J�K������t�0�0�1��~�~�,�,�-J�K������t�0�0�1rc��|jjd�}|j||j�|jjd�}|j||j
�|jjd�}|j||j�|jjd�}|j||j�|jjd�}|j||j
�|jjd�}|j||j�y)Nz
//filenamez//filename?foo=barr�r�s  r�test_start_with_double_slashz=SimpleHTTPRequestHandlerTestCase.test_start_with_double_slash
s���~�~�,�,�\�:������t�0�0�1��~�~�,�,�\�:������t�0�0�1��~�~�,�,�\�:������t�0�0�1��~�~�,�,�-A�B������t�0�0�1��~�~�,�,�-A�B������t�0�0�1��~�~�,�,�-A�B������t�0�0�1rc�	�tjtjdt�5|j
j
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|j
j
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|j
j
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|j
j
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�|jj
d�}|jtjtj�}|j||j�ddd�y#1swYyxYw)Nr�zc:c:c:foo/filenamez\c:../filenamezc:\c:..\foo/filenamezc:c:foo\c:c:bar/filename)r
�	swap_attrrrA�ntpathr�r�r�sepr�r�r�r�r�r�r�s  r�test_windows_colonz3SimpleHTTPRequestHandlerTestCase.test_windows_colonsI��
�
�
�v�y�y�&�&�
9��>�>�0�0�1E�F�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1E�F�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1E�F�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1B�C�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1B�C�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1B�C�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1I�J�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1I�J�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1I�J�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1L�M�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1L�M�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5��>�>�0�0�1L�M�D��<�<��
�
�B�F�F�3�D����T�4�#4�#4�5�O:�
9�
9�s�R=S0�0S9N)r r!r"r�rGr�r�r�rrrr�r��s���U�2�,
2�(6rr�c��eZdZd�Zy)�MiscTestCasec��g}hd�}tt�D]J}|jd�s||vr�tt|�}t|dd�dk(s�:|j	|��L|jtj|�y)N>rr��
nobody_uid�_r!zhttp.server)rrrd�getattrr�assertCountEqual�__all__)rr��denylistrT�
module_objects     r�test_allzMiscTestCase.test_allEso����7����K�D����s�#�t�x�'7��#�F�D�1�M��}�l�D�9�]�J�����%� �	
���f�n�n�h�7rN)r r!r"r�rrrr�r�Ds��	8rr�c���eZdZd�Zej
d�d��Zej
d�d��ZdZdZ	ej
d�d��Z
ej
d�d��Zy	)
�ScriptTestCasec���tjtjtjtjtjd�����������S)Nc��y)N)rrrrrr�<lambda>z2ScriptTestCase.mock_server_class.<locals>.<lambda>Ys��r)r.)r-)r)r�)r
�	MagicMockr5s r�mock_server_classz ScriptTestCase.mock_server_classSsF���~�~�����.�.�!%���#�~�~�(7� �"���

�
	
rzbuiltins.printc���|j�}tj|d��|j|jt
jt
jf�y�N��ServerClass�bind�r�rrr��address_familyr-�AF_INET6�AF_INET�rr��mock_servers   r�test_server_test_unspecz&ScriptTestCase.test_server_test_unspec`sC���,�,�.������$�7��
�
��&�&�
�_�_�f�n�n�-�	
rc���|j�}tj|d��|j|jt
jt
jf�y)Nr,r�r�r�s   r�test_server_test_localhostz)ScriptTestCase.test_server_test_localhostisC���,�,�.������+�>��
�
��&�&�
�_�_�f�n�n�-�	
r)z::z'2001:0db8:85a3:0000:0000:8a2e:0370:7334z::1)z0.0.0.0z8.8.8.8rOc���|jD]S}|j�}tj||��|j	|j
tj��Uyr�)�
ipv6_addrsr�rrr�r�r-r��rr�r�r�s    r�test_server_test_ipv6z$ScriptTestCase.test_server_test_ipv6~sF���O�O�D��0�0�2�K��K�K�K�d�;����[�7�7����I�$rc���|jD]S}|j�}tj||��|j	|j
tj��Uyr�)�
ipv4_addrsr�rrr�r�r-r�r�s    r�test_server_test_ipv4z$ScriptTestCase.test_server_test_ipv4�sF���O�O�D��0�0�2�K��K�K�K�d�;����[�7�7����H�$rN)r r!r"r�r
rWr�r�r�r�r�r�rrrr�r�Qs���
��T�Z�Z� �!�
�"�
��T�Z�Z� �!�
�"�
��J��J��T�Z�Z� �!�J�"�J��T�Z�Z� �!�I�"�Irr�c�p�tjtjtj��yr)r��addModuleCleanuprArrrrr�setUpModuler��s�����b�h�h��	�	��4r�__main__)Dr��collectionsr�http.serverrrrrrNrr	rAr-rGr�r�r�r�r+�
email.messager�email.utilsrO�http.client�urllib.parserMr
r�rr&r�r
r��iorrrr
�test.supportrr�requires_working_socketrr'r$�TestCaser<rYr�rr�r�r�r�r��hasattrrwr�rr$r)r3r�r�r�r�r �mainrrr�<module>r
s����
$�5�5�#�	�
�
�	�
�
��
������������ ���"�)�����t�,����y�'�'��*-�8�$�$�-�*a(�\�a(�H!G�L�!G�H`3�|�`3�F	
�	�
�	�"
�	�
�	�&������Y�'�=�J�B�J�J�L�A�,=�A�C�A4�L�A4�C�A4�H
�7�
�&�(@��
�
� }Q�X�%6�%6�}Q�@W6�x�'8�'8�W6�t
8�8�$�$�
8�9I�X�&�&�9I�x5��z���H�M�M�O�r

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