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_httplib.cpython-312.opt-2.pyc

�

'Μg�����ddlZddlZddlmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlm
Z
ejZddlmZddlmZddlmZej(d��ej*j-e�Zej*j3ed	d
�Zej*j3ed	d�Zej*j3ed	d�Zd
ZdZdZdZ dezdzZ!dZ"dZ#ejHZ$Gd�d�Z%Gd�de%�Z&Gd�dejN�Z(Gd�dejR�Z*Gd�de�Z+Gd�de�Z,Gd �d!e�Z-Gd"�d#e�Z.Gd$�d%e�Z/Gd&�d'e/�Z0Gd(�d)e/�Z1Gd*�d+�Z2Gd,�d-e�Z3Gd.�d/e�Z4Gd0�d1e�Z5Gd2�d3e�Z6Gd4�d5e�Z7Gd6�d7e�Z8Gd8�d9e�Z9Gd:�d;e�Z:e;d<k(rejxd=�>�yy)?�N)�client�
HTTPStatus)�mock)�support)�	os_helper)�
socket_helperT)�module�certdatazkeycert.pemzkeycert2.pemzselfsigned_pythontestdotnet.pemz{HTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello worl
3
d! 
8
and now 
22
for something completely different
s7hello world! and now for something completely differentz;foo=barz0
�0�
zX-Dummy: foo
X-Dumm2: bar
c�N�eZdZejddfd�Zd�Zdd�Zd�Zd�Z	d�Z
y)	�
FakeSocketNc��t|t�r|jd�}||_||_d|_d|_d|_||_||_	y)N�ascii�rF)
�
isinstance�str�encode�text�	fileclass�data�
sendall_calls�file_closed�host�port)�selfrrrrs     �./usr/local/lib/python3.12/test/test_httplib.py�__init__zFakeSocket.__init__7sM���d�C� ��;�;�w�'�D���	�"�����	���� �����	���	rc�X�|xjdz
c_|xj|z
c_y�N�)rr�rrs  r�sendallzFakeSocket.sendallBs!�����a����	�	�T��	rc���|dk7r|dk7rtj��|j|j�|_|j
|j_|jS)N�r�rb)r�UnimplementedFileModerr�file�
file_close�close)r�mode�bufsizes   r�makefilezFakeSocket.makefileFsK���3�;�4�4�<��.�.�0�0��N�N�4�9�9�-��	��/�/��	�	���y�y�rc��d|_y)NT)r�rs rr)zFakeSocket.file_closeNs
����rc��y�N�r/s rr*zFakeSocket.closeQ���rc��yr1r2)r�level�optname�values    r�
setsockoptzFakeSocket.setsockoptTr3rr1)�__name__�
__module__�__qualname__�io�BytesIOrr#r-r)r*r8r2rrrr6s+��')�z�z��4�	��� �
�
rrc��eZdZd�Zd�Zd�Zy)�EPipeSocketc�>�tj||�||_yr1)rr�pipe_trigger)rrrAs   rrzEPipeSocket.__init__Ys�����D�$�'�(��rc�~�|j|vrttjd��|xj|z
c_y)N�gotcha)rA�OSError�errno�EPIPErr"s  rr#zEPipeSocket.sendall^s/������$��%�+�+�x�0�0��	�	�T��	rc��yr1r2r/s rr*zEPipeSocket.closecr3rN)r9r:r;rr#r*r2rrr?r?Ws��)�
�

rr?c��eZdZ	dd�Zdd�Zy)�NoEOFBytesIOc�f�tjj||�}|dk(rtd��|S�Nrzcaller tried to read past EOF)r<r=�read�AssertionError)r�nrs   rrLzNoEOFBytesIO.readls.���z�z���t�Q�'���3�;� �!@�A�A��rNc�f�tjj||�}|dk(rtd��|SrK)r<r=�readlinerM)r�lengthrs   rrPzNoEOFBytesIO.readliners0���z�z�"�"�4��0���3�;� �!@�A�A��r����r1)r9r:r;rLrPr2rrrIrIfs���
�rrIc�0��eZdZ	�fd�Z�fd�Zd�Z�xZS)�FakeSocketHTTPConnectionc�b��d|_t�|�	d�||_|j|_y)Nr�example.com)�connections�superr�fake_socket_args�create_connection�_create_connection)r�args�	__class__s  �rrz!FakeSocketHTTPConnection.__init__{s.������
����'� $���"&�"8�"8��rc�L��	|xjdz
c_t�|�	�Sr )rXrY�connect)rr^s �rr`z FakeSocketHTTPConnection.connect�s$���<����A����w�� � rc�&�t|j�Sr1)rrZ)r�pos�kws   rr[z*FakeSocketHTTPConnection.create_connection�s���4�0�0�1�1r)r9r:r;rr`r[�
__classcell__)r^s@rrUrUxs���J�9�!�
2rrUc�<�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�HeaderTestsc�p�Gd�dt�}dD]�}dD]�}tjd�}td�|_|�|_d}i}|rt
t|��||<|jdd	||�|j|j
j|j�d
�����y)Nc��eZdZd�Zd�Zy)�;HeaderTests.test_auto_headers.<locals>.HeaderCountingBufferc��i|_yr1)�countr/s rrzDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__�s	����
rc��|jd�}t|�dkDrU|djd�j�}|jj|d�|j|xxdz
cc<tj||�y)N�:r!rr)�split�len�decode�lowerrk�
setdefault�list�append)r�item�kv�lcKeys    rrtzBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.append�sl���Z�Z��%���r�7�Q�;��q�E�L�L��1�7�7�9�E��J�J�)�)�%��3��J�J�u�%��*�%����D�$�'rN�r9r:r;rrtr2rr�HeaderCountingBufferri�s��
 �
(rry)TF)�Content-length�HostzAccept-encodingrW�blahblahblah�spamspamspam�POST�/r!)rsr�HTTPConnectionr�sock�_bufferrro�request�assertEqualrkrq)rry�explicit_header�header�conn�body�headerss       r�test_auto_headerszHeaderTests.test_auto_headers�s���
	(�4�
	(� +�O�E���,�,�]�;��&�~�6��	�3�5���%����"�&)�#�d�)�n�G�F�O����V�S�$��8�� � ����!3�!3�F�L�L�N�!C�Q�G�F� +rc��Gd�dt�}d}d}tj||�D]\}}tjd�}td�|_|�|_|j|d|�|j|jjddj|����d	}|D]|}tjd�}td�|_|�|_|j|dd�|j|jjdd
j|���~|D]|}tjd�}td�|_|�|_|j|dd�|j|jjddj|���~tj||�D]|}tjd�}td�|_|�|_|j|dd�|j|jjd
dj|���~y)Nc��eZdZd�Zd�Zy)�?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckerc�<�tj|�d|_yr1)rsr�content_lengthr/s rrzHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__�s���
�
�d�#�&*��#rc���|jdd�}t|�dkDr.|dj�dk(r|dj�|_t
j
||�y)Nrmr!rscontent-length)rnrorq�stripr�rsrt)rrurvs   rrtzFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.append�sO���Z�Z��a�(���r�7�Q�;�2�a�5�;�;�=�4E�#E�*,�Q�%�+�+�-�D�'����D�$�'rNrxr2rr�ContentLengthCheckerr��s��
+�
(rr�)N�)�PUTr~�PATCHrWr�0z%Header Content-Length incorrect on {})�GET�CONNECT�DELETE�HEAD�OPTIONS�TRACEz.Header Content-Length set for empty body on {}r�� �1)
rs�	itertools�productrr�rr�r�r�r�r��format�chain)rr��bodies�methods_with_body�methodr�r��methods_without_bodys        r�test_content_length_0z!HeaderTests.test_content_length_0�s���	(�4�	(���4��%�-�-�.?��H�L�F�D��(�(��7�D�"�4�(�D�I�/�1�D�L��L�L���d�+�������+�+�T�7�>�>�v�F�
�I� 
��+�F��(�(��7�D�"�4�(�D�I�/�1�D�L��L�L���d�+�������+�+�T�@�G�G��O�
�+�+�F��(�(��7�D�"�4�(�D�I�/�1�D�L��L�L���b�)�������+�+�T�7�>�>�v�F�
�+� �o�o�&:�<M�N�F��(�(��7�D�"�4�(�D�I�/�1�D�L��L�L���c�*�������+�+�T�7�>�>�v�F�
�Orc�|�tjd�}td�|_|j	dd�|jdd�|j
d|j�|jdd�|j
d	|j�|jd
d�|j
d|j�|jd
d�|j
d|j�|jddd�|j
d|j�|jdd�|j
d|j�|jdd�|j
d|j�|jdd�|j
d|j�|jdd�|j
d|j�|jd d!�|j
d"|j�|jd#d$�|j
d%|j�|jd&d$�|j
d'|j�|jd(d$�|j
d)|j�|jd*d$�|j
d+|j�y),NrWr�rrz�*sContent-length: 42�Fooz bar s
Foo:  bar �Barz	baz	s
Bar: 	baz	�
AuthorizationzBearer mytokensAuthorization: Bearer mytoken�
IterHeader�IterA�IterBsIterHeader: IterA
	IterB�LatinHeader��sLatinHeader: ��
Utf8HeadersÀsUtf8Header: Àz
C1-Controls	next�linesC1-Control: next�linezEmbedded-Fold-Spacezis
 alloweds!Embedded-Fold-Space: is
 allowedzEmbedded-Fold-Tabzis
	allowedsEmbedded-Fold-Tab: is
	allowedz	Key Spacer7sKey Space: valuez	KeySpace sKeySpace : valuesNonbreak�SpacesNonbreak�Space: values�NonbreakSpaces�NonbreakSpace: value)rr�rr��
putrequest�	putheader�assertInr��rr�s  r�test_putheaderzHeaderTests.test_putheader�s���$�$�]�3���t�$��	�����c�"����'��,��
�
�+�T�\�\�:����u�g�&��
�
�m�T�\�\�2����u�i�(��
�
�o�t�|�|�4�����(8�9��
�
�6����E����|�W�g�6��
�
�5�t�|�|�D����}�g�.��
�
�*�D�L�L�9����|�[�1��
�
�-�t�|�|�<����|�_�5��
�
�1�4�<�<�@����,�.>�?��
�
�<�d�l�l�K����*�,=�>��
�
�;�T�\�\�J����{�G�,��
�
�)�4�<�<�8����{�G�,��
�
�)�4�<�<�8����+�W�5��
�
�1�4�<�<�@����+�W�5��
�
�1�4�<�<�@rc�,�d}tjd�}td�}||_|j	dd�|j|jj|��d}tjd�}td�}||_|j	dd�|j|jj|��d}tjd	�}td�}||_|j	dd�|j|jj|��d
}tjd�}td�}||_|j	dd�|j|jj|��y)NsCGET /foo HTTP/1.1
Host: [2001::]:81
Accept-Encoding: identity

z[2001::]:81r�r��/foosEGET /foo HTTP/1.1
Host: [2001:102A::]
Accept-Encoding: identity

z
[2001:102A::]s@GET /foo HTTP/1.1
Host: [fe80::]
Accept-Encoding: identity

z
[fe80::%2]sCGET /foo HTTP/1.1
Host: [fe80::]:81
Accept-Encoding: identity

z
[fe80::%2]:81)rr�rr�r��
assertTruer�
startswith�r�expectedr�r�s    r�test_ipv6host_headerz HeaderTests.test_ipv6host_headersB��8���$�$�]�3���"�~����	����U�F�#�����	�	�,�,�X�6�7�8���$�$�_�5���"�~����	����U�F�#�����	�	�,�,�X�6�7�8���$�$�\�2���"�~����	����U�F�#�����	�	�,�,�X�6�7�8���$�$�_�5���"�~����	����U�F�#�����	�	�,�,�X�6�7rc���d}t|�}tj|�}|j�|j	|jd�d�|j	|jd�d�y)Nz4HTTP/1.1 200 OK
First: val
: nval
Second: val

�First�val�Second)rr�HTTPResponse�beginr��	getheader�rr�r��resps    r�!test_malformed_headers_coped_withz-HeaderTests.test_malformed_headers_coped_with.s\��O���$����"�"�4�(���
�
���������0�%�8��������1�5�9rc	��dttdd��zdzttdd��zdz}t|�}tj|�}|j�|j
|jd�d	�|j
|jdd	�|j
|jd
�d�|j
|jd
d�djtttdd���}|j
|jd
�|�|j
|jd
|�|j|jd��|jd|j�|jd�|jdfD]T}|j|jd��|jd|�|j|j!d���Vy)Ns0HTTP/1.1 200 OK
!#$%&'*+-.^_`|~: value
VCHAR: �!�s
obs-text: ��sM
obs-fold: text
 folded with space
	folded with tab
Content-Length: 0

�Content-Lengthrz!#$%&'*+-.^_`|~r7r��VCHARzobs-textzobs-foldrz folded with spacezfolded with tab)�bytes�rangerrr�r�r�r��msg�join�map�chr�assertIsNotNoner�r�r��endswith)rr�r�r��vchar�foldeds      r�test_parse_all_octetsz!HeaderTests.test_parse_all_octets8s���
��u�T�8�4�5�
6�9�
�"�%��h�"7�8�
9�<�
�	
��$����"�"�4�(���
�
��������(8�9�3�?�������"2�3�S�9�������(9�:�G�D�������"3�4�g�>�����C��t�X�!6�7�8���������0�%�8�������'�*�E�2����T�^�^�J�7�8��
�
�j�$�(�(�+��~�~�j�1�4�8�8�J�3G�H�F��O�O�F�-�-�f�5�6��M�M�.��7��O�O�F�O�O�,=�>�?�Irc�T�tjd�}td�|_|j	dd�d}|D]R\}}|j||f�5|j
td�5|j||�ddd�ddd��Ty#1swY�xYw#1swY�kxYw)NrWr�r�r))s
Invalid
Name�
ValidValue)sInvalid
Namer�)sInvalid
Namer�)s

InvalidNamer�)s
InvalidNamer�)s
InvalidNamer�)s InvalidNamer�)s	InvalidNamer�)sInvalid:Namer�)s:InvalidNamer�)�	ValidNamesInvalid
Value)r�s
Invalid
Value)r�s
Invalid
Value)r�sInvalidValue
)r�s
InvalidValue
)r�s
InvalidValue
zInvalid header)	rr�rr�r��subTest�assertRaisesRegex�
ValueErrorr�)rr��cases�namer7s     r�test_invalid_headersz HeaderTests.test_invalid_headersVs����$�$�]�3���r�N��	�����s�#�
��$!�K�D�%����t�U�m�,��+�+�J�8H�I��N�N�4��/�J�-�,�!�I�I��-�,�s$�B�,B�?B�B�B�B'	c��d}t|�}tj|d��}tj�5}|j�ddd�j
�j�}|j|dd�|j|dd�|j|dd�|j|d	d
�y#1swY�|xYw)Ns9HTTP/1.1 200 OK
First: val
Second: val1
Second: val2
r!)�
debuglevelrzreply: 'HTTP/1.1 200 OK\r\n'zheader: First: val�zheader: Second: val1�zheader: Second: val2)	rrr�r�captured_stdoutr��getvalue�
splitlinesr�)rr�r�r��output�liness      r�test_headers_debuglevelz#HeaderTests.test_headers_debuglevelts���
 �	
��$����"�"�4�A�6��
�
$�
$�
&�&��J�J�L�'����!�,�,�.������q��#C�D�����q��#7�8�����q��#9�:�����q��#9�:�
'�
&�s�C�CN)r9r:r;r�r�r�r�r�r�r�r�r2rrrfrf�s1��H�:@�D A�D!8�F:�@�<0�<;rrfc��eZdZd�Zy)�HttpMethodTestsc���d}|D]Y}|jtd�5tjd�}t	d�|_|j
|d��ddd��[y#1swY�fxYw)N)	zGET
zPOST
zPUT

z
POST
Valuez
POST
HOST:abczGET
rHost:abc
zPOST
Remainder:
z
GET
HOST:
z
PUTz'method can't contain control charactersrWr)r��url)r�r�rr�rr�r�)r�methodsr�r�s    r�test_invalid_method_namesz)HttpMethodTests.test_invalid_method_names�so��

���F��'�'�� I�K��,�,�]�;��&�t�,��	����F���4�	K�K��K�K�s�9A"�"A+	N)r9r:r;r�r2rrr�r��s��5rr�c�<�eZdZdZd�Zd�Zd�Zd�Zd
d�Zd�Z	d�Z
y	)�TransferEncodingTestsIt's just a flesh woundc�`�tjd�}td�|_|j	dd�|j|j
�d��|j|jj�\}}}|j|�}|j||j�y)NrWrr~rT)�encode_chunked)rr�rr�r��
endheaders�
_make_body�_parse_requestr�_parse_chunkedr��
expected_body)rr��_r�s    r�test_endheaders_chunkedz,TransferEncodingTest.test_endheaders_chunked�s����$�$�]�3���s�O��	������$�������)�$��?��(�(������8�
��1�d��"�"�4�(������t�1�1�2rc�x�tjd�}td�|_|j	dd|j�ddi�|j
|jj�\}}}|jd|j�D�cgc]}|j���c}�|j|dd�|j||j�tjd�}td�|_|j	dd|jjd�ddi�|j
|jj�\}}}|jd|j�D�cgc]}|j���c}�|j|dd�|j||j�tjd�}td�|_|j	dddd	id
|j���|j
|jj�\}}}|jd|D�cgc]}|j���c}�|j|dd	�|j|j|�|j�ycc}wcc}wcc}w)NrWrr~r�Transfer-Encoding�chunked�content-length�latin-1z
gzip, chunkedT)r�r�r�)rr�rr�r�r�r�r�assertNotIn�keysrqr�r�rpr��rr�r�r�r��ks      r�test_explicit_headersz*TransferEncodingTest.test_explicit_headers�sT���$�$�]�3���s�O��	�	
����C����*�-@�)�,L�	N� �.�.�t�y�y�~�~�>���7�D����)�w�|�|�~�+N�~�!�A�G�G�I�~�+N�O�����!4�5�y�A�����t�1�1�2��$�$�]�3���s�O��	�����C��+�+�2�2�9�=�
 �)�,�	.� �.�.�t�y�y�~�~�>���7�D����)�w�|�|�~�+N�~�!�A�G�G�I�~�+N�O�����!4�5�y�A�����t�1�1�2��$�$�]�3���s�O��	����V�S�(�/�:�����"�	�	$� �.�.�t�y�y�~�~�>���7�D����)�w�+G�w�!�A�G�G�I�w�+G�H�����!4�5��G�����,�,�T�2�D�4F�4F�G��5,O��,O��,Hs�J-
�;J2
�J7
c	���dD]�}tjd�}td�|_|j	dd|j|���|j
|jj�\}}}|j|�}|j||j�|j|dd�|jd	|D�cgc]}|j���c}���ycc}w)
N)FTrWrr~r)�empty_linesrrr)
rr�rr�r�r�r�rr�r�r�rrq)rr
r�r�r�r�rs       r�test_requestz!TransferEncodingTest.test_request�s���)�K��(�(��7�D�"�3��D�I��L�L���T�_�_��_�E�
G� $�2�2�4�9�9�>�>�B��A�w���&�&�t�,�D����T�4�#5�#5�6����W�%8�9�9�E�
���-�7�/K�7�a����	�7�/K�L�*��0Ls�	C*c�z�tjd�}td�|_|j	ddd�|j|jj�\}}}|j|dd�|jd|D�cgc]}|j���c}�|j|d	�ycc}w)
NrWrr~rr2rrrs0

)
rr�rr�r�r�rr�rrqrs      r�test_empty_bodyz$TransferEncodingTest.test_empty_body�s����$�$�]�3���s�O��	����V�S�"�%��.�.�t�y�y�~�~�>���7�D�����!4�5�y�A����)�w�+G�w�!�A�G�G�I�w�+G�H�����|�,��,Hs�B8
c#�K�|jjd�}t|�D]-\}}|r	|dzrd��|t|�dz
kr|dz���*|���/y�w)N� r�rr!)r�rn�	enumeratero)rr
r��idx�lines     rr�zTransferEncodingTest._make_body�s\�����"�"�(�(��.��"�5�)�I�C���s�Q�w��	��S��Z�!�^�#��T�k�!��
�*�s�AAc��|jd�}|d}i}d}|t|�kr�t||�dkDr}||jd�\}}|jd�j�}|jd�j�||<|dz
}|t|�krt||�dkDr�}||dj	||dzd�fS)N�
rr!rmr)rnrorpr�r�)rrr�r�r�rN�keyr�s        rr�z#TransferEncodingTest._parse_request�s����
�
�7�#����(����
���#�e�*�n��U�1�X���!2��Q�x�~�~�d�+�H�C���*�*�Y�'�-�-�/�C��:�:�i�0�6�6�8�G�C�L�
��F�A�	�#�e�*�n��U�1�X���!2������e�A��E�F�m�!<�<�<rc��g}i}d}|jd�}	|||dz\}}t|d�}|dk(r|dz
}nA|j|t|��|j	|�|dz
}|t|�kDrn�cdj|�S)Nrrr��r!r)rn�intr�rortr�)rrr��trailersrNr��size�chunks        rr�z#TransferEncodingTest._parse_chunkeds�������
���
�
�7�#�����!�A�#�,�K�D�%��t�R�=�D��q�y��Q�������T�3�u�:�.��K�K���
��F�A��3�u�:�~��!�$�x�x��~�rN)F)r9r:r;r�r�rrr
r�r�r�r2rrr�r��s-��.�M�3�$H�LM� -�	�=�rr�c�J�eZdZd�Zd�Zd�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�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4d3�Z5d4�Z6d5�Z7y6)7�	BasicTestc
�f�|jhd�tttd���k�y)N>r�r7�phrase�description�)r��set�dirrr/s r�&test_dir_with_added_behavior_on_statusz0BasicTest.test_dir_with_added_behavior_on_statuss#�����B�c�#�j�Y\�o�J^�F_�_�`rc�j�Gd�dtj�}tj|t�y)Nc�^�eZdZ	dFd�Zed��Zed��Zed��Zed��Zed��Z	dZ
dZd	Zd
Z
dZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7d5Z8d6Z9d7Z:d8Z;d9Z<d:Z=d;Z>d<Z?d=Z@d>ZAd?ZBd@ZCdAZDdBZEdCZFdDZGyE)G�;BasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatusc�\�tj||�}||_||_||_|Sr1)r�__new__�_value_rr )�clsr7rr �objs     rr)zCBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.__new__5s,���k�k�#�u�-��#���#��
�"-����
rc�"�d|cxkxrdkScS)N�d��r2r/s r�is_informationalzLBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_informational=����d�)�c�)�)�)�)rc�"�d|cxkxrdkScS)N���+r2r/s r�
is_successzFBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_successAr1rc�"�d|cxkxrdkScS)N�,�r2r/s r�is_redirectionzJBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_redirectionEr1rc�"�d|cxkxrdkScS)N���r2r/s r�is_client_errorzKBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_client_errorIr1rc�"�d|cxkxrdkScS)N���Wr2r/s r�is_server_errorzKBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_server_errorMr1r)r.�Continuez!Request received, please continue)�ezSwitching Protocolsz.Switching to new protocol; obey Upgrade header)�f�
Processing)�gzEarly Hints)r3�OKz#Request fulfilled, document follows)���CreatedzDocument created, URL follows)���Acceptedz/Request accepted, processing continues off-line)��zNon-Authoritative InformationzRequest fulfilled from cache)��z
No Contentz"Request fulfilled, nothing follows)��z
Reset Contentz"Clear input form for further input)��zPartial ContentzPartial content follows)��zMulti-Status)��zAlready Reported)��zIM Used)r7zMultiple Choicesz,Object has several resources -- see URI list)i-zMoved Permanently�(Object moved permanently -- see URI list)i.�Found�(Object moved temporarily -- see URI list)i/z	See Otherz'Object moved -- see Method and URL list)i0zNot Modifiedz)Document has not changed since given time)i1z	Use Proxyz@You must use proxy specified in Location to access this resource)i3zTemporary RedirectrU)i4zPermanent RedirectrS)r;zBad Requestz(Bad request syntax or unsupported method)��Unauthorizedz*No permission -- see authorization schemes)i�zPayment Requiredz"No payment -- see charging schemes)i��	Forbiddenz0Request forbidden -- authorization will not help)r!�	Not FoundzNothing matches the given URI)i�zMethod Not Allowedz-Specified method is invalid for this resource)i�zNot Acceptablez%URI not available in preferred format)i�zProxy Authentication Requiredz7You must authenticate with this proxy before proceeding)i�zRequest Timeoutz"Request timed out; try again later)i��ConflictzRequest conflict)i��Gonez5URI no longer exists and has been permanently removed)i�zLength Requiredz"Client must specify Content-Length)i�zPrecondition Failedz Precondition in headers is false)i�zRequest Entity Too LargezEntity is too large)i�zRequest-URI Too LongzURI is too long)i�zUnsupported Media Typez!Entity body in unsupported format)i�zRequested Range Not SatisfiablezCannot satisfy request range)i�zExpectation Failedz'Expect condition could not be satisfied)i�zI'm a Teapotz5Server refuses to brew coffee because it is a teapot.)i�zMisdirected Requestz(Server is not able to produce a response)i�zUnprocessable Entity)i��Locked)i�zFailed Dependency)i�z	Too Early)i�zUpgrade Required)i�zPrecondition Requiredz8The origin server requires the request to be conditional)i�zToo Many RequestszOThe user has sent too many requests in a given amount of time ("rate limiting"))i�zRequest Header Fields Too LargezVThe server is unwilling to process the request because its header fields are too large)i�zUnavailable For Legal ReasonszOThe server is denying access to the resource as a consequence of a legal demand)r?zInternal Server ErrorzServer got itself in trouble)i�zNot Implementedz&Server does not support this operation)i�zBad Gatewayz+Invalid responses from another server/proxy)i�zService Unavailablez8The server cannot process the request due to a high load)i�zGateway Timeoutz4The gateway server did not receive a timely response)i�zHTTP Version Not SupportedzCannot fulfill request)i�zVariant Also Negotiates)i�zInsufficient Storage)i�z
Loop Detected)i�zNot Extended)i�zNetwork Authentication Requiredz7The client needs to authenticate to gain network accessN)r�)Hr9r:r;r)�propertyr0r5r9r=rA�CONTINUE�SWITCHING_PROTOCOLS�
PROCESSING�EARLY_HINTSrG�CREATED�ACCEPTED�NON_AUTHORITATIVE_INFORMATION�
NO_CONTENT�
RESET_CONTENT�PARTIAL_CONTENT�MULTI_STATUS�ALREADY_REPORTED�IM_USED�MULTIPLE_CHOICES�MOVED_PERMANENTLY�FOUND�	SEE_OTHER�NOT_MODIFIED�	USE_PROXY�TEMPORARY_REDIRECT�PERMANENT_REDIRECT�BAD_REQUEST�UNAUTHORIZED�PAYMENT_REQUIRED�	FORBIDDEN�	NOT_FOUND�METHOD_NOT_ALLOWED�NOT_ACCEPTABLE�PROXY_AUTHENTICATION_REQUIRED�REQUEST_TIMEOUT�CONFLICT�GONE�LENGTH_REQUIRED�PRECONDITION_FAILED�REQUEST_ENTITY_TOO_LARGE�REQUEST_URI_TOO_LONG�UNSUPPORTED_MEDIA_TYPE�REQUESTED_RANGE_NOT_SATISFIABLE�EXPECTATION_FAILED�IM_A_TEAPOT�MISDIRECTED_REQUEST�UNPROCESSABLE_ENTITY�LOCKED�FAILED_DEPENDENCY�	TOO_EARLY�UPGRADE_REQUIRED�PRECONDITION_REQUIRED�TOO_MANY_REQUESTS�REQUEST_HEADER_FIELDS_TOO_LARGE�UNAVAILABLE_FOR_LEGAL_REASONS�INTERNAL_SERVER_ERROR�NOT_IMPLEMENTED�BAD_GATEWAY�SERVICE_UNAVAILABLE�GATEWAY_TIMEOUT�HTTP_VERSION_NOT_SUPPORTED�VARIANT_ALSO_NEGOTIATES�INSUFFICIENT_STORAGE�
LOOP_DETECTED�NOT_EXTENDED�NETWORK_AUTHENTICATION_REQUIREDr2rr�CheckedHTTPStatusr'"s#��
�$
��
*��
*��
*��
*��
*��
*��
*��
*��
*��
*�L�H�#F��*�J�,�K�A�B�E�G�C�H�-Q�)�P�J�V�M�O�O�.�L�6��$�G� @��!<��L�E�S�I�=�L�T�I�"<��"<��<�K�>�L� 6��D�I�1�I�"A��9�N�-K�)�6�O�:�H�I�D�6�O�#4��('�$�$#� �&5�"�/0�+�";��I�K�#<��#>� �"�F� 8��(�I�6��%L�!�!<��/(�+�-?�)�
%0�!�:�O�?�K�#L��H�O�**�&�&D�#�#>� �0�M�.�L�/K�+rr�)�enum�IntEnum�_test_simple_enumr)rr�s  r�test_simple_httpstatusz BasicTest.test_simple_httpstatus!s*��`	K����`	K�B	
���0�*�=rc��	tjj�D]&}|j|d�|j	|d��(y)Nr.r@)r�__members__�values�assertGreaterEqual�assertLessEqual)r�members  r�test_httpstatus_rangezBasicTest.test_httpstatus_range�s>��?� �,�,�3�3�5�F��#�#�F�C�0�� � ���-�6rc���	d}tjj�D]L}|D]E\\}}}t||�}||cxkr|krnn|j	|��5|j|��G�Ny)N)))r.r/r0))r3r4r5))r7r8r9))r;r<r=))r?r@rA)rr�r��getattrr��assertFalse)r�
categoriesr�rq�upper�category�category_indicators       r�test_httpstatus_categoryz"BasicTest.test_httpstatus_category�sp��H�
�
�!�,�,�3�3�5�F�,6�(�����%,�V�X�%>�"��F�+�e�+��O�O�$6�7��$�$�%7�8�-7�6rc��d}t|�}tj|�}|j�|j	|jd�d�|j
|j��|j
|j�|j	|j�d�|j|j��|j
|j�|j�|j|j�d}t|�}tj|�}|jtj|j�y)N�HTTP/1.1 200 Ok

Textrr�TextzHTTP/1.1 400.100 Not Ok

Text)
rrr�r�r�rLr��isclosed�closedr�r*�assertRaises�
BadStatusLiner�s    r�test_status_lineszBasicTest.test_status_lines�s���-���$����"�"�4�(���
�
��������1��s�+��������)�������%��������g�.�����
�
��(�������%��
�
��������$�4���$����"�"�4�(�����&�.�.��
�
�;rc�d�tjd�}|jt|�d�y)Nr�zBadStatusLine("''"))rr�r��repr)r�excs  r�test_bad_status_reprzBasicTest.test_bad_status_repr�s'���"�"�2�&������c��$=�>rc���d}t|�}tj|�}|j�|j	|jd�d�|j
|j��|j	|jd�d�|j|j��|j
|j�|j�|j|j�y�N�*HTTP/1.1 200 Ok
Content-Length: 4

Textr��Te�xt�rrr�r�r�rLr�r�r�r�r*r�s    r�test_partial_readszBasicTest.test_partial_reads�s���B���$����"�"�4�(���
�
��������1��u�-��������)�������1��u�-�����
�
��(�������%��
�
��������$rc���d}t|�}tj|�}|j�|j	|j�d�|j
|j��|j	|j�d�|j|j��|j
|j�|j�|j|j�y)Nz4HTTP/1.1 200 Ok
Content-Length: 13

Text
AnothersText
sAnother)rrr�r�r�rPr�r�rLr�r�r*r�s    r�test_mixed_readszBasicTest.test_mixed_readss���N���$����"�"�4�(���
�
���������+�6��������)��������j�1�����
�
��(�������%��
�
��������$rc�~�d}t|�}tj|�}|j�t	d�}|j|�}|j
|d�|j
t|�d�|j|j��|j|�}|j
|d�|j
t|�d�|j|j��|j|j�|j�|j|j�yr��
rrr�r��	bytearray�readintor�r�r�r�r�r�r*�rr�r�r��brNs      r�test_partial_readintosz BasicTest.test_partial_readintoss���B���$����"�"�4�(���
�
���a�L���M�M�!�������A������q��5�)��������)��M�M�!�������A������q��5�)�����
�
��(�������%��
�
��������$rc�t�d}t|�}tj|�}|j�|j	|jd�d�|j
|j��|j|j�|j�|j
|j�y)Nr��
r��rrr�r�r�rLr�r�r�r�r*r�s    r�test_partial_reads_past_endz%BasicTest.test_partial_reads_past_end)s��A���$����"�"�4�(���
�
��������2���0�����
�
��(�������%��
�
��������$rc���d}t|�}tj|�}|j�t	d�}|j|�}|j
|d�|j
t|�ddd�|j|j��|j|j�|j�|j|j�y)Nr�r��r�)
rrr�r�r�r�r�r�r�r�r�r�r*r�s      r�test_partial_readintos_past_endz)BasicTest.test_partial_readintos_past_end5s���A���$����"�"�4�(���
�
���b�M���M�M�!�������A������q��"�1��w�/�����
�
��(�������%��
�
��������$rc�6�d}t|�}tj|�}|j�|j	|jd�d�|j
|j��|j	|jd�d�|j	|jd�d�|j|j��|j
|j�|j�|j|j�y)Nr�r�r�r�r!rr�r�s    r�$test_partial_reads_no_content_lengthz.BasicTest.test_partial_reads_no_content_lengthDs���-���$����"�"�4�(���
�
��������1��u�-��������)�������1��u�-�������1��s�+�����
�
��(�������%��
�
��������$rc�8�d}t|�}tj|�}|j�t	d�}|j|�}|j
|d�|j
t|�d�|j|j��|j|�}|j
|d�|j
t|�d�|j|�}|j
|d�|j|j��y)Nr�r�r�r�r)rrr�r�r�r�r�r�r�r�r�r�s      r�(test_partial_readintos_no_content_lengthz2BasicTest.test_partial_readintos_no_content_lengthTs���-���$����"�"�4�(���
�
���a�L���M�M�!�������A������q��5�)��������)��M�M�!�������A������q��5�)��M�M�!�������A������
�
��(rc��d}t|�}tj|�}|j�|j	|jd�d�|j
|j��|j	|jd�d�|j	|jd�d�|j|j��y)N�+HTTP/1.1 200 Ok
Content-Length: 10

Textr�r�r�r!r)	rrr�r�r�rLr�r�r�r�s    r�"test_partial_reads_incomplete_bodyz,BasicTest.test_partial_reads_incomplete_bodygs���C���$����"�"�4�(���
�
��������1��u�-��������)�������1��u�-�������1��s�+�����
�
��(rc���d}t|�}tj|�}|j�t	d�}|j|�}|j
|d�|j
t|�d�|j|j��|j|�}|j
|d�|j
t|�d�|j|�}|j
|d�|j|j��|j|j�|j�|j|j�y)Nr�r�r�r�rr�r�s      r�&test_partial_readintos_incomplete_bodyz0BasicTest.test_partial_readintos_incomplete_bodyts	��C���$����"�"�4�(���
�
���a�L���M�M�!�������A������q��5�)��������)��M�M�!�������A������q��5�)��M�M�!�������A������
�
��(�������%��
�
��������$rc� �dD]1}|jtjtj|��3dD]S\}}}tj|�}|j	||j
�|j	||j��Uy)N�zwww.python.org:abczuser:password@www.python.org)�z[fe80::207:e9ff:fe9b]:8000�fe80::207:e9ff:fe9bi@)zwww.python.org:80�www.python.org�P)�www.python.org:r�r�)r�r�r�)�[fe80::207:e9ff:fe9b]r�r�)�[fe80::207:e9ff:fe9b]:r�r�)r�r�
InvalidURLr�r�rr�r�hp�h�p�cs     r�test_host_portzBasicTest.test_host_port�s|��I�B����f�/�/��1F�1F��K�I�P�H�B��1��%�%�b�)�A����Q����'����Q����'�Prc��d}d}t|�}tj|�}|j�|j	d�}|j||�y)Nz�HTTP/1.1 200 OK
Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"

No body
zrCustomer="WILE_E_COYOTE"; Version="1"; Path="/acme", Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"z
Set-Cookie)rrr�r�r�r�)rr�hdr�sr%�cookiess      r�test_response_headerszBasicTest.test_response_headers�sT����O��
�t�������"��	���	��+�+�l�+������#�&rc��tdt�}tj|d��}|j	�|j�r|j
d�yy)N�*HTTP/1.1 200 OK
Content-Length: 14432

r��r��)Did not expect response from HEAD request)rrIrr�r�rL�fail�rr�r�s   r�test_read_headzBasicTest.test_read_head�sP���
�
�	��
�"�"�4��7���
�
���9�9�;��I�I�A�B�rc��tdt�}tj|d��}|j	�td�}|j
|�dk7r|jd�|jt|�d�y)Nr�r�r��rr��)
rrIrr�r�r�r�r�r�r�)rr�r�r�s    r�test_readinto_headzBasicTest.test_readinto_head�sp���
�
�	��
�"�"�4��7���
�
���a�L���=�=���q� ��I�I�A�B�����q��9�-rc��djd�ttjdz�D��dz}d|z}t	|�}tj
|�}|j
tjd|j�y)Nrc3�&K�|]	}d|z���y�w)z
Header%d: fooNr2)�.0�is  r�	<genexpr>z2BasicTest.test_too_many_headers.<locals>.<genexpr>�s����F�'D�!�.��1�'D�s�r!zHTTP/1.1 200 OK
zgot more than \d+ headers)	r�r�r�_MAXHEADERSrr�r��
HTTPExceptionr�)rr�rr�r%s     r�test_too_many_headerszBasicTest.test_too_many_headers�s}���+�+�F�',�V�-?�-?�!�-C�'D�F�F�HN�O��%��/���t�������"�����v�3�3�;�Q�W�W�	Frc	�R�d}ttd�5}tjd�}t	|�}||_|j
dd|�|j|jj|�|jdt|��d|���ddd�y#1swYyxYw)Ns_GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

r&rWr�r�z != )�open�__file__rr�rr�r�r�rr�ro�rr�r�r�r�s     r�test_send_filezBasicTest.test_send_file�s�����
�(�D�
!�T��(�(��7�D��d�#�D��D�I��L�L����-��O�O�D�I�I�0�0��:��Y�Y�~��H�
�.��=:�
;�"�
!�
!�s�BB�B&c���d}tjd�}td�}||_|j	|�|j||j�d|_|j	tjd|��|j||j�d|_|j	tj|��|j||j�y)Ns"this is a test this is only a testrWrr�)
rr�rr��sendr�r�arrayr<r=r�s    r�	test_sendzBasicTest.test_send�s���8���$�$�]�3���$�����	��	�	�(������4�9�9�-���	��	�	�%�+�+�c�8�,�-�����4�9�9�-���	��	�	�"�*�*�X�&�'�����4�9�9�-rc���d��G�fd�dtj�}d}tjd�}t	d�}||_|j
|��|j|j|�y)Nc3�$K�d��d��d��y�w)Nr�data_twor2r2rrrz/BasicTest.test_send_updating_file.<locals>.data�s�����L��J�����c�*��eZdZdZW��Zdd�Zy)�7BasicTest.test_send_updating_file.<locals>.UpdatingFiler%c�,�t|j�Sr1)�next�d)r�	blocksizes  rrLz<BasicTest.test_send_updating_file.<locals>.UpdatingFile.read�s���D�F�F�|�#rNrR)r9r:r;r+rrL)rs�r�UpdatingFiler�s����D���A�
$rrsdatarWr�)	r<�
TextIOBaserr�rr�r	r�r)rrr�r�r�rs     @r�test_send_updating_filez!BasicTest.test_send_updating_file�sa���	�
	$�2�=�=�	$����$�$�]�3���"�~����	��	�	�,�.�!�������H�-rc���d}d�}tjd�}td�}||_|j	dd|�ddi�|j|j|�y)	NsbGET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Content-Length: 11

onetwothreec3�$K�d��d��d��y�w)Nsonestwosthreer2r2rrr�z&BasicTest.test_send_iter.<locals>.bodys�����L��L��N�rrWr�r�r�r��11)rr�rr�r�r�rrs     r�test_send_iterzBasicTest.test_send_iters^��&��	�
�$�$�]�3���"�~����	����U�F�D�F�-=�t�,D�E�������H�-rc�X�	d}tjd|��}td�}||_d|zdz}|j	ddtj|�dd	i�|j|jd
�|jjdd�d}|j||�y)
N�rW�r�a�br�rr��9r��

r!)rr�rr�r�r<r=r�rrrn)rrr�r�r�r�s      r�test_blocksize_requestz BasicTest.test_blocksize_requests���F��	��$�$�]�i�H���$�����	��)�#�d�*�����U�C����H�!5�8H�#�7N�O�����+�+�Q�/��y�y���{�A�.�q�1������x�(rc�$�	d}tjd|��}td�}||_d|zdz}|j	tj|��|j|jd�|j|j|�y)NrrWrr r!r�)
rr�rr�r	r<r=r�rr)rrr�r�r�s     r�test_blocksize_sendzBasicTest.test_blocksize_sends{��C��	��$�$�]�i�H���$�����	��)�#�d�*���	�	�"�*�*�X�&�'�����+�+�Q�/�������H�-rc���tjd�}td�|_|j	t
�5|j
dd|�ddd�y#1swYyxYw)NrWr�r~�test)rr�rr�r��	TypeErrorr�r�s  r�test_send_type_errorzBasicTest.test_send_type_error*sG���$�$�]�3���r�N��	�
�
�
�y�
)��L�L����.�*�
)�
)�s�A�A!c�X�t}tttztz�}tj|d��}|j�|j|j�|�|j�tdd�D]�}tttztz�}tj|d��}|j�|j|j|�|j|�z|j�z|�|j���dD]m}tt|z�}tj|d��}|j�	|j�|jd�|j��oy#t
j$rj}|j|j|�dt|�z}|jt!|�|�|jt#|�|�Yd}~��d}~wwxYw#|j�wxYw)Nr�r�r!��r�zfoo
�IncompleteRead expected�IncompleteRead(%d bytes read))�chunked_expectedr�
chunked_start�
last_chunk�chunked_endrr�r�r�rLr*r�r��IncompleteRead�partialror�r)rr�r�r�rN�xr��expected_messages        r�test_chunkedzBasicTest.test_chunked1s���#���-�*�4�{�B�C���"�"�4��6���
�
���������h�/��
�
���q�"��A��m�j�8�;�F�G�D��&�&�t�E�:�D��J�J�L����T�Y�Y�q�\�D�I�I�a�L�8�4�9�9�;�F��Q��J�J�L��!�A��m�a�/�0�D��&�&�t�E�:�D��J�J�L�

��	�	���	�	�3�4��
�
��!���(�(�
;�� � ����H�5�#B�S��]�#R� �� � ��a��*:�;�� � ��Q��)9�:�:��	
;���
�
��s1�#F�3H�H�*A H�
H�H�H�H)c��t}t|�}td�}ttt
ztz�}tj|d��}|j�|j|�}|j|d||�|j||�|j�tdd�D]�}ttt
ztz�}tj|d��}|j�t|�}|j|d|�}||j||||z�z
}||j||d�z
}|j|d||�|j||�|j���dD]n}	tt|	z�}tj|d��}|j�	|j|�}|jd�|j��py#tj $rj}|j|j"|�d	t|�z}
|jt%|�|
�|jt'|�|
�Yd}~��d}~wwxYw#|j�wxYw)
Nr�r�r�r!r,rr-r.r/)r0ror�rr1r2r3rr�r�r�r�r*r��
memoryviewr�r4r5r�r)rr��	nexpectedr�r�r�rN�mr�r6r7s           r�test_readinto_chunkedzBasicTest.test_readinto_chunkedQs��#����M�	��c�N���-�*�4�{�B�C���"�"�4��6���
�
���M�M�!�������:�I���1�����I�&��
�
���q�"��A��m�j�8�;�F�G�D��&�&�t�E�:�D��J�J�L��1�
�A��
�
�a��!�f�%�A�
����q��1�q�5�z�*�*�A�
����q���u�%�%�A����Q�z�	�]�H�5����Q�	�*��J�J�L��!�A��m�a�/�0�D��&�&�t�E�:�D��J�J�L�

��M�M�!�$���	�	�3�4��
�
��!���(�(�
;�� � ����H�5�#B�S��]�#R� �� � ��a��*:�;�� � ��Q��)9�:�:��	
;���
�
��s1�G9�I9�9I6�A I1�,I9�1I6�6I9�9Jc��d}t|tztz�}tj|d��}|j�|j
|j�d�|j
|jd�|j
|jd�|j|j��|j|j�|j�|j|j�y)N�EHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
r�r�rr3rG)rr2r3rr�r�r�rL�status�reasonr�r�r�r�r*)rr1r�r�s    r�test_chunked_headzBasicTest.test_chunked_head|s���
�	��-�*�4�{�B�C���"�"�4��7���
�
���������c�*�������c�*�������d�+�����
�
��(�������%��
�
��������$rc�T�d}t|tztz�}tj|d��}|j�t
d�}|j|�}|j|d�|jt|�d�|j|jd�|j|jd�|j|j��|j|j�|j!�|j|j�y)	Nr?r�r�r�rr�r3rG)rr2r3rr�r�r�r�r�r�r@rAr�r�r�r�r*)rr1r�r�r�rNs      r�test_readinto_chunked_headz$BasicTest.test_readinto_chunked_head�s���
�	��-�*�4�{�B�C���"�"�4��7���
�
���a�L���M�M�!�������A������q��9�-�������c�*�������d�+�����
�
��(�������%��
�
��������$rc���td�}tj|d��}|j�|j	|j�d�|j
|j��y)Nz.HTTP/1.1 200 OK
Content-Length: -1

Hello
r�r��Hello
)rrr�r�r�rLr�r�r�s   r�test_negative_content_lengthz&BasicTest.test_negative_content_length�sS���D�F���"�"�4��6���
�
���������l�3�����
�
��(rc���td�}tj|d��}|j�	|j	�|jd�y#tj$r{}|j|jd�|jt|�d�|jt|�d�|j|j��Yd}~yd}~wwxYw)Nz.HTTP/1.1 200 OK
Content-Length: 10

Hello
r�r�r.rFz-IncompleteRead(7 bytes read, 3 more expected))
rrr�r�rLr�r4r�r5r�rr�r�)rr�r�r�s    r�test_incomplete_readzBasicTest.test_incomplete_read�s����R�S���"�"�4��6���
�
��
	1��I�I�K�
�I�I�/�0���$�$�	-����Q�Y�Y��5����T�!�W�L�
N����S��V�L�
N��O�O�D�M�M�O�,�,��
	-�s�A�C$�)A1C�C$c�"��tdd�}tjd��|�_|j	t
�fd���j
�}|jd|j�|jd|jd��y)NzgHTTP/1.0 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Basic realm="example"
sContent-LengthrWc�*���jddd�S)Nr��/urlr�)r�)r�s�r�<lambda>z&BasicTest.test_epipe.<locals>.<lambda>�s���$�,�,�u�f�f�"ErrVzBasic realm="example"zwww-authenticate)
r?rr�r�r�rD�getresponser�r@r�)rr�r�r�s   @r�
test_epipezBasicTest.test_epipe�s�����
<�
�	��
�$�$�]�3����	����'�E�	G����!������d�k�k�*����2����(:�;�	=rc���dddzzdz}tjt|��}|jtjtj
f|j�y)N�HTTP/1.1 200 Okr�r)rr�rr��LineTooLongr�r��rr�r�s   r�test_overflowing_status_linez&BasicTest.test_overflowing_status_line�sO�� �3��;�.��7���"�"�:�d�#3�4�����6�-�-�v�/C�/C�D�d�j�j�Qrc��dddzzdz}tjt|��}|jtj|j
�y)NzHTTP/1.1 200 OK
X-Foo: barr%rR�

)rr�rr�rSr�rTs   r�test_overflowing_header_linez&BasicTest.test_overflowing_header_line�sQ��
���;�
'�)3�
4�	
��"�"�:�d�#3�4�����&�,�,�d�j�j�9rc�f�ddz}tjt|��}|jtj�5}|j�ddd�|j
dtj��|j
dt|j��y#1swY�TxYw)NzHTTP/1.1 100 OK
r
i�zgot more than r�)	rr�rr�rr�r�r�	exception)rr�r��cms    r�'test_overflowing_header_limit_after_100z1BasicTest.test_overflowing_header_limit_after_100�s���
��
�	
��"�"�:�d�#3�4��
�
�
�v�3�3�
4���J�J�L�5�	
�
�
�&��B�L�L�(9�:��
�
�i��R�\�\�!2�3�5�
4�s�B'�'B0c���dddzzdz}tjt|��}|j�|j	tj
|j�y)Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

rrRza
hello world
0

)rr�rr�r�rSrLrTs   r�test_overflowing_chunked_linez'BasicTest.test_overflowing_chunked_line�s\��
1��E�k�
��
�	
��"�"�:�d�#3�4���
�
�����&�,�,�d�i�i�8rc�r�d}t|�}tj|�}|j�|j	|j�d�|j
|j��|j|j�|j�|j
|j�y)NrQrr�r�s    r�test_early_eofzBasicTest.test_early_eof�s}�� ���$����"�"�4�(���
�
���������c�*�����
�
��(�������%��
�
��������$rc���tjd�}d�G�fd�dtj�}||_t	d�|_|j
dd�|jtj|j�|j�j�|j|j
j�y)NrWc���eZdZ�fd�Zy)�+BasicTest.test_error_leak.<locals>.Responsec�P��|�tjj|g|��i|��yr1)rr�r)rrbrc�responses   �rrz4BasicTest.test_error_leak.<locals>.Response.__init__s&������#�#�,�,�T�>�C�>�2�>rN)r9r:r;r)res�r�Responsercs���
?rrfzInvalid status liner�r)
rr�r��response_classrr�r�r�r�rNr�r�r)rr�rfres   @r�test_error_leakzBasicTest.test_error_leaks�����$�$�]�3����	?�v�*�*�	?�
'����4�5��	����U�C� ����&�.�.��0@�0@�A�������(�����	�	�-�-�.rc��d}tdz}tt|ztztz�}tj|d��}|j�|j|j�|�|j�y)Nz3;foo=bar
abc
sabcr�r�)r0rr1�last_chunk_extendedr3rr�r�r�rLr*)r�extrar�r�r�s     r�test_chunked_extensionz BasicTest.test_chunked_extensionse��+��#�f�,���-�%�/�2E�E��S�T���"�"�4��6���
�
���������h�/��
�
�rc���	t}tttz�}t	j
|d��}|j
�|j|j�|�|j�y�Nr�r�)
r0rr1r2rr�r�r�rLr*�rr�r�r�s    r�test_chunked_missing_endz"BasicTest.test_chunked_missing_endsS��G�#���-�*�4�5���"�"�4��6���
�
���������h�/��
�
�rc�\�	t}tttztzt
z�}t
j|d��}|j�|j|j�|�|j|jj�d�|j�y)Nr�r�r)
r0rr1r2rr3rr�r�r�rLr(r*ros    r�test_chunked_trailerszBasicTest.test_chunked_trailers&sx��4�#���-�*�4�x�?�+�M�N���"�"�4��6���
�
���������h�/���������)�3�/��
�
�rc��	t}d}tttztzt
z|z�}t
j|d��}|j�|j|j�|�|j|jj�|jd��|j�y)N�	extradatar�r�r)r0rr1r2rr3rr�r�r�rLr(rr*)rr�rtr�r�s     r�test_chunked_synczBasicTest.test_chunked_sync1s���R�#���	��-�*�4�x�?�+�M�PY�Y�Z���"�"�4��6���
�
���������h�/���������)�9�+;�+;�G�+D�E��
�
�rc�2�	d}d}td|z|z�}tj|d��}|j�|j	|j�|�|j	|jj�|�|j�y)N�	extradata�
Hello123
�'HTTP/1.1 200 OK
Content-Length: 10

r�r�)rrr�r�r�rLr(r*�rrtr�r�r�s     r�test_content_length_syncz"BasicTest.test_content_length_sync=sz��P� �	�"���J�X�U�Xa�a�b���"�"�4��6���
�
���������h�/���������)�9�5��
�
�rc�4�d}d}td|z|z�}tj|d��}|j�|j	|jd�|g�|j	|jj�|�|j�y�Nrwrxryr�r�i�)	rrr�r�r��	readlinesr(rLr*rzs     r�test_readlines_content_lengthz'BasicTest.test_readlines_content_lengthIs|�� �	�"���J�X�U�Xa�a�b���"�"�4��6���
�
���������-��z�:���������)�9�5��
�
�rc�2�d}d}td|z|z�}tj|d��}|j�|j	|jd�|�|j	|jj�|�|j�yr})	rrr�r�r��read1r(rLr*rzs     r�test_read1_content_lengthz#BasicTest.test_read1_content_lengthTsz�� �	�"���J�X�U�Xa�a�b���"�"�4��6���
�
��������D�)�8�4���������)�9�5��
�
�rc�t�d}d}td|z|z�}tj|d��}|j�|j	|jd�|�|j	|jd�d�|j	|jj�|�|j�y)Nrwrxryr�r�r�r)	rrr�r�r�rPr(rLr*rzs     r�"test_readline_bound_content_lengthz,BasicTest.test_readline_bound_content_length_s��� �	�"���J�X�U�Xa�a�b���"�"�4��6���
�
��������r�*�H�5�������r�*�C�0���������)�9�5��
�
�rc�~�d}d}td|dzz|z�}tj|d��}|j�|j	|jd�|dz�|j	|j
�|�|j	|jj
�|�|j�y)	Nrwrxs'HTTP/1.1 200 OK
Content-Length: 30

r�r�r��r�)	rrr�r�r�r�rLr(r*rzs     r�test_read1_bound_content_lengthz)BasicTest.test_read1_bound_content_lengthks��� �	�"���J�X�VW�Z�W�Zc�c�d���"�"�4��6���
�
��������B���!��4��������h�/���������)�9�5��
�
�rc�z���tjtdf��|j�j�d���fd�}tj|��}|j�|j|jtd��tj�j��}|jdd�|j�}	|j|j tj"�tj|j%���}	|j'd�|j)�	|j	�|j	�|j�|j�d�y#|j)�wxYw#|j	�|j	�wxYw)	Nrc�0���j�\}}|5|jd�5}	|j�}|jd�sn�#|j	d�|j��ddd�ddd�y#1swY�xYw#1swYyxYw)Nr&rs'HTTP/1.1 200 Connection established

)�acceptr-rP�rstripr#rL)r��address�readerr�result�servs    ��r�
run_serverz2BasicTest.test_response_fileno.<locals>.run_server}st���"�k�k�m�O�T�7��t�}�}�T�*�f��!�?�?�,�D��;�;�w�/������K�L������+���*�*����s#�B�AB�/B�B		�B�B)�targetr!r�z
dummy:1234)�filenos
proxied data
)�socket�
create_server�HOST�
addCleanupr*�	threading�Thread�startr��floatrr��getsocknamer�rNr�r@rGr�r#�detach)rr��threadr�rer�r�r�s      @@r�test_response_filenozBasicTest.test_response_filenows2����#�#�T�1�I�.������
�
�#���
	'��!�!��4������������U�1�X�.��$�$�d�&6�&6�&8�9�����Y��-��#�#�%��		����X�_�_�f�i�i�8��
�
�X�_�_�%6�7�A�
��	�	�+�,����
��N�N���J�J�L����
�����!2�3�����
���N�N���J�J�L�s%�AF�F�/F�F�F�"F:c��	Gd�dtj�}|d�}td�|_|j	dd�y)Nc��eZdZd�Zy)�RBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnectionc��yr1r2�rr�s  r�_validate_pathzaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_path����rN)r9r:r;r�r2rr�UnsafeHTTPConnectionr�����
rr�rWr�r�z/�rr�rr�r��rr�r�s   r�*test_putrequest_override_domain_validationz4BasicTest.test_putrequest_override_domain_validation�s>��	�	�6�#8�#8�	�$�M�2���r�N��	�����w�'rc��Gd�dtj�}|d�}td�|_|j	ddd��y)	Nc��eZdZd�Zy)�PBasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnectionc��yr1r2r�s  r�_validate_hostz_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_host�r�rN)r9r:r;r�r2rrr�r��r�rr�z
example.com
r�r�rr!)�	skip_hostr�r�s   r�(test_putrequest_override_host_validationz2BasicTest.test_putrequest_override_host_validation�s@��	�6�#8�#8�	�$�$5�6���r�N��	�	
����s�a��0rc��	Gd�dtj�}|d�}td�|_|j	dd�y)Nc��eZdZd�Zy)�IBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnectionc�$�|jd�S)N�utf-8)r)r�str_urls  r�_encode_requestzYBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnection._encode_request�s���~�~�g�.�.rN)r9r:r;r�r2rrr�r��s��
/rr�rWr�r�u/☃r�r�s   r�!test_putrequest_override_encodingz+BasicTest.test_putrequest_override_encoding�s>��	�
	/�6�#8�#8�	/�$�M�2���r�N��	�����v�&rN)8r9r:r;r$r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr$r&r*r8r=rBrDrGrIrOrUrXr\r^r`rhrlrprrrur{rr�r�r�r�r�r�r�r2rrrrs��a�b>�H.�9�$<�*?�
%�
%�%�(
%�
%�%� )�&)�%�,(�"'�$C�
.�F�;�.�.�*.� 
)�	.�/��@)�V%�(%�.)�1� 
=�"R�
:�4�9�
%�/� ��	�
�
�	�	�
�
�#4�J(�	1�'rrc��eZdZ	dZeej	d�djd�ZdZd�Zd�Z	d�Z
d	�Zdd
�Zd�Z
d�Zd
�Zd�Zd�Zy)�ExtendedReadTestzOHTTP/1.1 200 OK

hello world!
and now 
for something completely different
foo�helloNr��HTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello worl
3
d!

9
and now 

23
for something completely different

3
foo
0

c���t|j�}tj|d��}|j	�tj|j�|_||_yrn)	rr�rr�r�r<�BufferedReader�fpr�r�s   r�setUpzExtendedReadTest.setUp�sH���$�*�*�%���"�"�4��6���
�
���#�#�D�G�G�,�����	rc���|j}|jj�d�fd�	}||j_g}	|jd�}|r�|jt	|�d�|j�}|jt	|�t	|��|j
|j|��|jt	|��}|j||�n!|j�}|j|�|j|�|sn��|jdj|�|j�y)Nc�2���|�}|dk\r|d|S|ddS)Nrr�r2)rNr��oldpeeks  �r�mypeekz*ExtendedReadTest.test_peek.<locals>.mypeek�s)�����
�A��A�v���!�u���S�b�6�Mrr�rrrR)r�r��peek�
assertGreaterror�r�r�rLr�r�rtr��lines_expected)rr�r��allr��p2rr�s       @r�	test_peekzExtendedReadTest.test_peek�s����y�y���'�'�,�,��	�
���������	�	�!��A���"�"�3�q�6�1�-��Y�Y�[���'�'��B���Q��8�����
�
�a� 0�1��y�y��R��)��� � ��r�*��y�y�{��� � ��&��J�J�t����!�"	
������#���(;�(;�<rc�|�|j}|j|jj|j�yr1)r��_verify_readlinerPr�)rr�s  r�
test_readlinezExtendedReadTest.test_readline	s+���y�y�����d�i�i�0�0�$�2E�2E�Frc�h�|j|jj|jd��y)NrS)�limit)r�r�rPr�r/s r�test_readline_without_limitz,ExtendedReadTest.test_readline_without_limit
s'�����d�i�i�0�0�$�2E�2E�R��Prc�B�g}	||�}|r3|dk7r.t|�dkr |j|jd��|j|�|sn�R|j	dj|�|�|j|jj��y)N�foor��
r)ror�r�rtr�r�r�r�)rrPr�r�r�rs      rr�z!ExtendedReadTest._verify_readlines�������E�?�D������t�9�q�=��O�O�D�M�M�%�$8�9��J�J�t�����	
������#���1�����	�	�*�*�,�-rc�����j���fd�}t|�}�j|j�j�y)Nc�`���jd�}�jt|�d�|S)Nr�)r�r�ro)�resr�rs ��rr%z&ExtendedReadTest.test_read1.<locals>.r s)����*�*�Q�-�C�� � ��S��1�-��Jr)r��	Readlinerr�rPr�)rr%�	readlinerr�s`  @r�
test_read1zExtendedReadTest.test_read1s8����y�y��	��a�L�	����i�0�0�$�2E�2E�Frc��|j}g}	|j�}|sn|j|��%|jdj	|�|j
�|j
|j��y�Nr)r�r�rtr�r�r�r�r��rr�r�rs    r�test_read1_unboundedz%ExtendedReadTest.test_read1_unbounded'sg���y�y������:�:�<�D����J�J�t��	�
	
������#���(;�(;�<�����
�
��(rc�8�|j}g}	|jd�}|sn-|jt|�d�|j	|��A|jdj
|�|j�|j|j��y)Nr�r)
r�r�r�rortr�r�r�r�r�r�s    r�test_read1_boundedz#ExtendedReadTest.test_read1_bounded2s}���y�y������:�:�b�>�D���� � ��T��B�/��J�J�t���	
������#���(;�(;�<�����
�
��(rc��|j|jjd�d�|j|jj	��y)Nrr)r�r�r�r�r�r/s r�test_read1_0zExtendedReadTest.test_read1_0>s:�����������+�S�1�������+�+�-�.rc�p�|jjd�}|jdt|��y�Nr)r�r�r�ro)rr�s  r�test_peek_0zExtendedReadTest.test_peek_0Bs(���I�I�N�N�1������Q��A��'r)r�)r9r:r;r��findrr��
lines_chunkedr�r�r�r�r�r�r�r�r�r�r2rrr�r��ss���	�
��5�:�:�g�.�/�0�7�7��@�N�
	��"�=�>G�Q�.�G�	)�
)�/�(rr�c�n�eZdZejjdd�\ZZedee��d�zezZy)�"ExtendedReadTestContentLengthKnownrWr!z
Content-Length: N)	r9r:r;r�r�rn�_header�_bodyror2rrr�r�Gs;��%�+�+�1�1�*�a�@�N�G�U��,�S��Z�L��A�A�E�I�Err�c��eZdZ	dZy)�ExtendedReadTestChunkedr�N)r9r:r;r�r2rrr�r�Ls���
	�
rr�c��eZdZ	d�Zd�Zy)r�c� �||_d|_yr�)�readfunc�	remainder)rr�s  rrzReadliner.__init__fs�� ��
���rc�t�g}d}|j}		|jd�}|dk7rn@|t|�z|k\r||z
dz
}|j|�|j	�}|sd}n�W|dz
}|j|d|�||d|_dj|�S#dj|�|_�xYw)Nrr�rSr!r)r�r�rortr�r�)rr�r�datalenrLrs      rrPzReadliner.readlinejs��������~�~��	���i�i��&���"�9���S��Y�&�%�/��'�/�A�-�C����D�!��}�}�����C���
�1�H�C��K�K��T�c�
�#�!�#�$�Z�D�N��8�8�D�>�!��	� �X�X�d�^�D�N��s�BB�B7N)r9r:r;rrPr2rrr�r�bs����rr�c��eZdZd�Zd�Zd�Zy)�OfflineTestc�
�dh}ddh}tt�D]J}|jd�s||vr�tt|�}t|dd�dk(s�:|j	|��L|jtj|�y)N�	responses�HTTPMessage�
parse_headersr�r:zhttp.client)r#rr�r��add�assertCountEqual�__all__)rr��denylistr��
module_objects     r�test_allzOfflineTest.test_all�sx���=��"�?�3����K�D����s�#�t�x�'7��#�F�D�1�M��}�l�D�9�]�J����T�"� �	
���f�n�n�h�7rc�f�|jtjtjd�y)NrY)r�rr�rwr/s r�test_responseszOfflineTest.test_responses�s#������)�)�&�*:�*:�;�[�Irc��gd�}|D]<}|j|��5|jtt|��ddd��>y#1swY�IxYw)N):r^r_r`rGrbrcrdrerfrgrhrjrkrlrmrnrorprqrsrtrurvrwrxryrzr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rar�)�constant)r�r��hasattrr)rr��consts   r�test_client_constantsz!OfflineTest.test_client_constants�sF��;
��x�E����u��-������� 6�7�.�-��-�-�s� A�A	N)r9r:r;r�rrr2rrr�r��s��8�J�@8rr�c�`�eZdZd�Zd�Zd�Zejee	d�d�d��Z
y)�SourceAddressTestc�.�tjtjtj�|_t	j
|j�|_t	j�|_|jj�d|_
yr1)r��AF_INET�SOCK_STREAMr�r�	bind_portr�find_unused_port�source_port�listenr�r/s rr�zSourceAddressTest.setUp�s\���M�M�&�.�.�&�2D�2D�E��	�!�+�+�D�I�I�6��	�(�9�9�;����	�	������	rc��|jr!|jj�d|_|jj�d|_yr1)r�r*r�r/s r�tearDownzSourceAddressTest.tearDown�s3���9�9��I�I�O�O���D�I��	�	������	rc�(�tjt|jd|jf��|_|j
j
�|j|j
jj�d|j�y)Nr���source_addressr!)
rr�r�rrr�r`r�r�r�r/s r�testHTTPConnectionSourceAddressz1SourceAddressTest.testHTTPConnectionSourceAddress�sf���)�)�$��	�	� "�D�$4�$4�5�7��	��	�	������������3�3�5�a�8�$�:J�:J�Kr�HTTPSConnectionz'http.client.HTTPSConnection not definedc�r�tjt|jd|jf��|_y)Nr�r)rrr�rrr�r/s r� testHTTPSConnectionSourceAddressz2SourceAddressTest.testHTTPSConnectionSourceAddress�s,���*�*�4���� "�D�$4�$4�5�7��	rN)r9r:r;r�rr�unittest�skipIfrrrr2rrrr�sC����L��X�_�_���):�;�;�>�@�7�@�7rrc�"�eZdZdZd�Zd�Zd�Zy)�TimeoutTestNc��tjtjtj�|_t	j
|j�t_|jj�yr1)	r�r
rr�rrr�PORTrr/s rr�zTimeoutTest.setUp�sE���M�M�&�.�.�&�2D�2D�E��	�(�2�2�4�9�9�=����	�	���rc�F�|jj�d|_yr1)r�r*r/s rrzTimeoutTest.tearDowns���	�	������	rc�X�|jtj��tjd�	t	j
ttj�}|j�tjd�|j|jj�d�|j�|jtj��tjd�	t	j
ttjd��}|j�tjd�|j|jj�d�|j�t	j
ttjd��}|j�|j|jj�d�|j�y#tjd�wxYw#tjd�wxYw�N�)�timeout)�assertIsNoner��getdefaulttimeout�setdefaulttimeoutrr�r�rrr`r�r��
gettimeoutr*)r�httpConns  r�testTimeoutAttributez TimeoutTest.testTimeoutAttributes���
	
���&�2�2�4�5�� � ��$�	+��,�,�T�;�3C�3C�D�H������$�$�T�*�������1�1�3�R�8�����	
���&�2�2�4�5�� � ��$�	+��,�,�T�;�3C�3C�6:�<�H������$�$�T�*�������1�1�3�T�:������(�(��{�/?�/?��L������������1�1�3�R�8������)
�$�$�T�*��
�$�$�T�*�s�8G8�::H�8H�H))r9r:r;rr�rr)r2rrrr�s���D��
�rrc��eZdZd�Zd�Zd�Zy)�PersistenceTestc��d}|D�]"\}}}|j||��5dj||�}t|�}|j|j�|jdd�|j
�5}|j|jdu|�|j�ddd�|j|jdu|�|j|jd�|jdd�|j|j|rdnd�ddd���%y#1swY��xYw#1swY��=xYw)	N))�1.0r�F)r-zConnection: keep-alive
T)�1.1r�T)r.zConnection: close
F)r-zConnection: keep-ALIVE
T)r.zConnection: cloSE
F)�versionr�z4HTTP/{} 200 OK
{}Content-Length: 12

Dummy body
r�z/open-connectionr!z/subsequent-requestr�)
r�r�rUr$r�r�rNr�rLrX)r�testsr/r��reuser�r�res        r�test_reuse_reconnectz$PersistenceTest.test_reuse_reconnect(s��
��',�"�G�V�U����g�f��=�%�
�&��&�)�
�0��4���!�!�$�)�)�,����U�$6�7��%�%�'�8��$�$�T�Y�Y�$�%6�E�	�B��M�M�O�(�� � ����d�!2��I�>�� � ��!1�!1�1�5����U�$9�:�� � ��!1�!1��1�1�E�#>�=�',�(�'��>�=�s%�AD8�;0D,�+A5D8�,D5�1D8�8E	c���d�}tjtjf|tff}|D]�\}}|j|��5t
d|�}|jdd�|j||j�|j|j�|jdd�|j|jd�ddd���y#1swY��xYw)Nc�r��	tj|���fd�}|�_tj��S)Nc�f��tjj�|�}|dk(r
t��|Sr�)r<r=r��ConnectionResetError)�bufferr�streams  �rr�zNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readintoKs.����z�z�*�*�6�6�:���1�9�.�0�0��r)r<r=r�r�)rr�r8s  @r�make_reset_readerz<PersistenceTest.test_disconnected.<locals>.make_reset_readerHs3���E��Z�Z��%�F�
�
'�F�O��$�$�V�,�,r)rZrr�z
/eof-response�
/reconnectr�)r<r=r�RemoteDisconnectedr6r�rUr�r�rNr$r�r�rX)rr9r0�stream_factoryrZr�s      r�test_disconnectedz!PersistenceTest.test_disconnectedFs���		-��Z�Z��2�2�3�
� 4�5�
��*/�%�N�I����	��2�/��^�D�����U�O�4��!�!�)�T�-=�-=�>��!�!�$�)�)�,����U�L�1�� � ��!1�!1�1�5�3�2�*/�2�2�s
�BC�C	c�,�td�}|jddddi��|jtj|j
�|j
|j�|jdd�|j|jd�y)	NsHTTP/1.1 100 Continue

r�r�Expectz100-continue�r�r:r�)
rUr�r�rr;rNr$r�r�rXr�s  r�test_100_closezPersistenceTest.test_100_closeas|��'�
�
��
	
���U�C�(�N�)C��D����&�3�3�T�5E�5E�F����$�)�)�$����U�L�)�����)�)�1�-rN)r9r:r;r2r=rAr2rrr+r+&s��F�<6�6
.rr+c���eZdZd�Zd�Zd�Zd�Zd�Zejd��Z
d�Zejd�d	��Z
d
�Zd�Zd�Zej$eed
�d�d��Zd�Zy)�	HTTPSTestc�H�ttd�s|jd�yy)Nrzssl support required)rr�skipTestr/s rr�zHTTPSTest.setUpps���v�0�1��M�M�0�1�2rc�"�ddlm}|||��S)Nr)�make_https_server)�certfile)�test.ssl_serversrG)rrHrGs   r�make_serverzHTTPSTest.make_serverts��6� ���9�9rc��tjttjd��}|j|jd�yr!)rrr�rrr�r#)rr�s  r�test_attributeszHTTPSTest.test_attributesxs0���"�"�4��)9�)9�2�F��������B�'rc��ddl}tjd�tjd�5tjdd�}|j|j�5}|jdd�ddd�|jjjd�ddd�y#1swY�8xYw#1swYyxYw)Nr�network�self-signed.pythontest.net�r�r�CERTIFICATE_VERIFY_FAILED)
�sslr�requiresr�transient_internetrrr��SSLErrorr�r�rZrA)rrRr��exc_infos    r�test_networkedzHTTPSTest.test_networked}s��������#�
�
-�
-�.J�
K��&�&�'C�S�I�A��"�"�3�<�<�0�H��	�	�%��%�1����X�/�/�6�6�8S�T�	L�
K�0�0��L�
K�s#�2B7�!B+�4.B7�+B4	�0B7�7Cc��ddl}tjd�tjd�5|j�}t
jdd|��}|jdd�|j�}|j�|jd|jd	��|j�ddd�y#1swYyxYw)
NrrNrOrP��contextr�r�nginx�server)
rRrrSrrT�_create_unverified_contextrrr�rNr*r�r�)rrRrZr�r�s     r�test_networked_noverificationz'HTTPSTest.test_networked_noverification�s��������#�
�
-�
-�.J�
K��4�4�6�G��&�&�'C�S�/6�8�A�
�I�I�e�S�!��=�=�?�D�
�G�G�I��M�M�'�4�>�>�(�#;�<��J�J�L�L�
K�
K�s�BC�C
c�x�tjd�tjd�5t	j
dd�}|j
dd�|j�}|jd�}|j�|j�|jd|�ddd�y#1swYyxYw)NrNr�rPr�rzcontent-typez	text/html)rrSrrTrrr�rNr�r*r�)rr�r��content_types    r�&test_networked_trusted_by_default_certz0HTTPSTest.test_networked_trusted_by_default_cert�s���	����#�
�
-�
-�.>�
?��&�&�'7��=�A�
�I�I�e�S�!��=�=�?�D��>�>�.�9�L��J�J�L�
�G�G�I��M�M�+�|�4�@�
?�
?�s�A<B0�0B9c	��ddl}tjd�d}tj|�5|j|j�}|j|j|j�|j|jd�|jt�	tj|d|��}|jdd�|j!�}|j/d
�}|j1�|j1�|j3d|�ddd�y#|j"$rC}t%|�}t'j(d	|�rt+j,d
|�d|�d����d}~wwxYw#1swYyxYw)NrrNrOTrPrYr�rz(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.r\r[)rRrrSrrT�
SSLContext�PROTOCOL_TLS_CLIENTr��verify_mode�
CERT_REQUIRED�check_hostname�load_verify_locations� CERT_selfsigned_pythontestdotnetrrr�rNrUr�re�searchr�SkipTestr�r*r�)	rrR�selfsigned_pythontestdotnetrZr�r��ssl_err�ssl_err_str�
server_strings	         r�test_networked_good_certz"HTTPSTest.test_networked_good_cert�s^�������#�&B�#�
�
-�
-�.I�
J��n�n�S�%<�%<�=�G����W�0�0�#�2C�2C�D����W�3�3�T�:��)�)�*J�K�
��*�*�+F��3:�<���	�	�%��%��}�}���!�N�N�8�4�M��J�J�L�
�G�G�I��M�M�'�=�1�5K�
J���<�<�
�!�'�l���9�9�0�+�>�"�+�+��{�m�,�9�:�;B�B�C�C���
��K�
J�s1�A3F�%:D+�AF�+E=�:>E8�8E=�=F�F	�walltimec���ddl}tjd�tjd�5|j|j�}|jt�tjdd|��}|j|j�5}|jdd�ddd�|jjj d�ddd�y#1swY�8xYw#1swYyxYw)	NrrNrOrPrYr�rrQ)rRrrSrrTrcrdrh�CERT_localhostrrr�rUr�r�rZrA)rrRrZr�rVs     r�test_networked_bad_certz!HTTPSTest.test_networked_bad_cert�s���	�����#�
�
-�
-�.J�
K��n�n�S�%<�%<�=�G��)�)�.�9��&�&�'C�S�RY�Z�A��"�"�3�<�<�0�H��	�	�%��%�1����X�/�/�6�6�8S�T�
L�
K�1�0��	L�
K�s$�A$C)�C�&.C)�C&	�"C)�)C2c�F�ddl}|jt�}tjd|j
�}|j
|j�5}|jdd�ddd�|jjjd�y#1swY�0xYw)Nr�	localhostr�rrQ)rRrJrtrrrr�rUr�r�rZrA)rrRr\r�rVs     r�test_local_unknown_certz!HTTPSTest.test_local_unknown_cert�sx����!�!�.�1���"�"�;����<��
�
�
�s�|�|�
,��
�I�I�e�S�!�-�����+�+�2�2�4O�P�-�
,�s�B�B c���ddl}|jt�}|j|j�}|jt�t
jd|j|��}|j|j�|jdd�|j�}|j|j�|j|jd�y)NrrwrYr��/nonexistentr!)rRrJrtrcrdrhrrrr�r*r�rNr�r@�rrRr\rZr�r�s      r�test_local_good_hostnamez"HTTPSTest.test_local_good_hostname�s�����!�!�.�1���.�.��!8�!8�9���%�%�n�5��"�"�;����W�M�������� �	�	�	�%��(��}�}�������
�
�#�������c�*rc�B�ddl}|jt�}|j|j�}|jt�t
jd|j|��}|j|j�5|jdd�ddd�d|_t
jd|j|��}|j|j�5|jdd�ddd�d|_t
jd|j|��}|jdd�|j�}|j�|j�|j|j d	�y#1swY��xYw#1swY��xYw)
NrrwrYr�rTFrzr!)rRrJ�CERT_fakehostnamercrdrhrrrr��CertificateErrorr�rgrNr*r�r@r{s      r�test_local_bad_hostnamez!HTTPSTest.test_local_bad_hostname�s4����!�!�"3�4���.�.��!8�!8�9���%�%�&7�8��"�"�;����W�M��
�
�
�s�3�3�
4�
�I�I�e�S�!�5�"&����"�"�;����W�M��
�
�
�s�3�3�
4�
�I�I�e�S�!�5�"'����"�"�;����W�M��	�	�	�%��(��}�}����
�
��	���	�������c�*�!5�
4��5�
4�s�F	�&F�	F�Frz)http.client.HTTPSConnection not availablec� �dD]1}|jtjtj|��3dD]S\}}}tj|�}|j	||j
�|j	||j��Uy)Nr�)r�)zwww.python.org:443r�rP)r�r�rP)r�r�rP)r�r�rP)r�r�rP)r�rr�rr�rrr�s     rr�zHTTPSTest.test_host_port�sz��
I�B����f�/�/��1G�1G��L�I�#�H�B��1��&�&�r�*�A����Q����'����Q����'�#rc��ddl}|js|jd�tjdd�}|j|jj�|j|j�}|j|j�tjdd|��}|j|j|�|j|jj�|j|jt��}d|_tjdd|��}|j|jj�y)NrzTLS 1.3 support requiredrwrPrY)�	cert_fileT)
rR�HAS_TLSv1_3rErrr��_context�post_handshake_authrcrdr��assertIsrt)rrRr�rZs    r�test_tls13_phazHTTPSTest.test_tls13_phas��������M�M�4�5��"�"�;��4������
�
�6�6�7��.�.��!8�!8�9������4�4�5��"�"�;��W�E���
�
�a�j�j�'�*�������7�7�8��.�.��!8�!8�N�.�S��&*��#��"�"�;��W�E������
�
�6�6�7rN)r9r:r;r�rJrLrWr^r�system_must_validate_certrarq�requires_resourcerurxr|r�rrrrr�r�r2rrrCrCns���2�:�(�
U��
�&�&�
5�'�
5�2�B�W���z�*�
U�+�
U�Q�+�+�2�X�_�_���):�;�;�@�B�(�B�(�$8rrCc�D�eZdZ	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�RequestBodyTestc��tjd�|_td�x|j_|_|j|j_y)NrWr�)rr�r�rr�r/s rr�zRequestBodyTest.setUp*s9���)�)�-�8��	�%/��^�3��	�	��������	�	�rc��tj|jj�}|j	�tj|�}||fSr1)r<r=r�rrPrr��r�f�messages   r�get_headers_and_fpz"RequestBodyTest.get_headers_and_fp/s;���J�J�t�y�y�~�~�&��	�
�
���&�&�q�)����z�rc��ddgdfdf}|D]�\}}|j|�5tjd�|_t	d�x|j_|_|jj
dd|�|j�\}}|jd	|�|jd
|�|j|jd�d�|j||j��ddd���y#1swY��xYw)
Nr��bar�3
foo
3
bar
0

))r�r�r�rWr�r�rLzContent-Typer�rr)r�rr�r�rr�r�r�rr��getrL)rr�r�r�r�r�s      r�test_list_bodyzRequestBodyTest.test_list_body5s���
�f�
�C�D�D�
��$�N�D�(����d�#�"�1�1�-�@��	�-7��^�;��	�	�����	�	�!�!�%���6��0�0�2���Q�� � ���5�� � �!1�3�7�� � ����)<�!=�y�I�� � ��1�6�6�8�4�$�#�$�#�#�s�CC>�>D	c��|jjdddddi�|j�\}}|jd|j	d��|jdt|j
���y)Nr�rLr�r��42rr�)r�r�r�r�r�rorL�rr�r�s   r�test_manual_content_lengthz*RequestBodyTest.test_manual_content_lengthIsj��	
�	�	���%���+�T�2�	4��,�,�.�
�������w�{�{�+;�<�=�����C�����M�*rc�d�|jjddd�|j�\}}|jd|j	��|j|j
��|jd|jd��|jd|j��y)Nr�rLr��
text/plain�4rsbody�	r�r�r�r��get_content_typer$�get_charsetr�rLr�s   r�test_ascii_bodyzRequestBodyTest.test_ascii_bodyRs����	�	���%���0��,�,�.�
�������w�'?�'?�'A�B����'�-�-�/�0�����g�k�k�*:�;�<�����!�&�&�(�+rc�d�|jjddd�|j�\}}|jd|j	��|j|j
��|jd|jd��|jd|j��y)Nr�rLubodyÁr��5r�body�r�r�s   r�test_latin1_bodyz RequestBodyTest.test_latin1_bodyZs����	�	���%���4��,�,�.�
�������w�'?�'?�'A�B����'�-�-�/�0�����g�k�k�*:�;�<�����a�f�f�h�/rc�d�|jjddd�|j�\}}|jd|j	��|j|j
��|jd|jd��|jd|j��y)Nr�rLr�r�r�rr�r�s   r�test_bytes_bodyzRequestBodyTest.test_bytes_bodybs����	�	���%���5��,�,�.�
�������w�'?�'?�'A�B����'�-�-�/�0�����g�k�k�*:�;�<�����a�f�f�h�/rc���|jtjtj�t	tjdd��5}|jd�ddd�t	tjd��5}|jjdd|�|j�\}}|jd|j��|j|j��|j|jd��|jd	|jd
��|jd|j��ddd�y#1swY��xYw#1swYyxYw)N�wr�)�encodingr�r�rLr�rrztransfer-encodings4
body
0

)r�r�unlink�TESTFNr�writer�r�r�r�r�r$r�r�rLr�s   r�test_text_file_bodyz#RequestBodyTest.test_text_file_bodyjs
�����	�(�(�)�*:�*:�;�
�)�"�"�C�'�
:�a�
�G�G�F�O�;�
�)�"�"�W�
5���I�I���e�V�Q�/��0�0�2�J�G�Q����\�7�+C�+C�+E�F����g�1�1�3�4�
���g�k�k�*:�;�<����Y����4G�(H�I����6�����A�6�
5�;�
:��
5�
5�s�E�CE&�E#�&E/c���|jtjtj�t	tjd�5}|jd�ddd�t	tjd�5}|jjdd|�|j�\}}|jd|j��|j|j��|jd|jd��|jd	|�|jd
|j��ddd�y#1swY��xYw#1swYyxYw)N�wbr�r&r�rLr�rrr�s5
body�
0

)r�rr�r�rr�r�r�r�r�r�r$r�r�rrLr�s   r�test_binary_file_bodyz%RequestBodyTest.test_binary_file_bodyys�����	�(�(�)�*:�*:�;�
�)�"�"�D�
)�Q�
�G�G�K� �*�
�)�"�"�D�
)�Q��I�I���e�V�Q�/��0�0�2�J�G�Q����\�7�+C�+C�+E�F����g�1�1�3�4����Y����4G�(H�I����-�w�7����:�A�F�F�H�E�*�
)�*�
)��
)�
)�s�	E	�=CE�	E�EN)r9r:r;r�r�r�r�r�r�r�r�r�r2rrr�r�'s4��=�#�
�5�(+�,�0�0�
B�Frr�c�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�HTTPResponseTestc��d}t|�}tj|�|_|jj	�y)NzXHTTP/1.1 200 Ok
My-Header: first-value
My-Header:                 second-value

Text)rrr�r�r�)rr�r�s   rr�zHTTPResponseTest.setUp�s3��*���$����'�'��-��	��	�	���rc��|jjd�}|j|d�|jjdd�}|j|d�y)Nz	My-Headerzfirst-value, second-valuezsome default�r�r�r��rr�s  r�test_getting_headerz$HTTPResponseTest.test_getting_header�sN�����$�$�[�1������!<�=����$�$�[�.�A������!<�=rc�`�|jjdd�}|j|d�y)N�No-Such-Headerz
default-valuer�r�s  r�3test_getting_nonexistent_header_with_string_defaultzDHTTPResponseTest.test_getting_nonexistent_header_with_string_default�s)�����$�$�%5��G�������1rc��|jjdddg�}|j|d�|jjdd�}|j|d�y)Nr��defaultr�zdefault, values)r�r�r�r�s  r�5test_getting_nonexistent_header_with_iterable_defaultzFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_default�sX�����$�$�%5�	�8�7L�M������!2�3����$�$�%5�7L�M������!2�3rc�^�|jjd�}|j|d�y)Nr�r�r�s  r�/test_getting_nonexistent_header_without_defaultz@HTTPResponseTest.test_getting_nonexistent_header_without_default�s'�����$�$�%5�6�������&rc�b�|jjdd��}|j|d�y)Nr�r�)r�r�r�s  r�test_getting_header_defaultintz/HTTPResponseTest.test_getting_header_defaultint�s,�����$�$�%5�b�$�A�������$rN)	r9r:r;r�r�r�r�r�r�r2rrr�r��s ���>�2�4�'�%rr�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�TunnelTestsc���d}d|_tj|_tj|j�|_|j
|�|j
_y)Nz:HTTP/1.1 200 OK

HTTP/1.1 200 OK
Content-Length: 42

z	proxy.com)rr�	HTTP_PORTrr�r�r\)r�
response_texts  rr�zTunnelTests.setUp�sO��
)�	�
 ��	��$�$��	��)�)�$�)�)�4��	�'+�'>�'>�}�'M��	�	�$rc�8�|jj�yr1)r�r*r/s rrzTunnelTests.tearDown�s���	�	���rc���d�fd�	}|S)Nc�,��t�|d|d��S)Nrr!�rr�r)r�r#rr�s   �rr[z9TunnelTests._create_connection.<locals>.create_connection�s����m�'�!�*�7�1�:�N�Nr�NNr2)rr�r[s ` rr\zTunnelTests._create_connection�s���	O� � rc��d}d}ddi}|j�}d||fz|d<|jj|||��|jjdd	d
�|j	|jj
j|j�|j	|jj
j|j�|j	|jj|�|j	|jj|�|j	|jj|�y)N�destination.com�"�
User-Agent�!Mozilla/5.0 (compatible, MSIE 11)�%s:%dr{�rr�r�rr�)�copyr��
set_tunnelr�r�r�rr�_tunnel_host�_tunnel_port�_tunnel_headers)r�tunnel_host�tunnel_port�tunnel_headers�tunnel_headers_afters     r�2test_set_tunnel_host_port_headers_add_host_missingz>TunnelTests.test_set_tunnel_host_port_headers_add_host_missing�s��'����&�(K�L��-�2�2�4��'.�+�{�1K�'K��V�$��	�	���[�{�%3�	�	5��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8�������/�/��=�������/�/��=�������2�2�4H�Irc�b�d}d}dd||fzd�}|jj|||��|jjddd	�|j|jjj
|j
�|j|jjj|j�|j|jj|�|j|jj|�|j|jj|�y)
Nr�r�r�r��r�r{r�r�rr��
r�r�r�r�r�rrr�r�r��rr�r�r�s    r�4test_set_tunnel_host_port_headers_set_host_identicalz@TunnelTests.test_set_tunnel_host_port_headers_set_host_identical�s���'����(K�")�[�+�,F�"F�H���	�	���[�{�%3�	�	5��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8�������/�/��=�������/�/��=�������2�2�N�Crc�^�d}d}dddzd�}|jj|||��|jjdd	d
�|j|jjj
|j
�|j|jjj|j�|j|jj|�|j|jj|�|j|jj|�y)Nr�r�r�r�)rWihr�r�r�rr�r�r�s    r�4test_set_tunnel_host_port_headers_set_host_differentz@TunnelTests.test_set_tunnel_host_port_headers_set_host_different�s���'����(K�")�,A�"A�C���	�	���[�{�%3�	�	5��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8�������/�/��=�������/�/��=�������2�2�N�Crc��|jj�|jt|jjd�y)Nr�)r�r`r��RuntimeErrorr�r/s r�&test_disallow_set_tunnel_after_connectz2TunnelTests.test_disallow_set_tunnel_after_connect�s1���	�	�������,��	�	�(<�(<�+�	-rc�r�dtjd�}|jj|dj	d��|jjddd�|j
|jjj|j�|j
|jjj|j�|jd|z|jjj�|jd	|z|jjj�y�
N�destination.com��host�portr�rr�rr��?CONNECT %(host)s:%(port)d HTTP/1.1
Host: %(host)s:%(port)d

�!HEAD / HTTP/1.1
Host: %(host)s
�rr�r�r�rpr�r�r�rrr�r�rrs  r�test_connect_with_tunnelz$TunnelTests.test_connect_with_tunnel�����'��%�%�
��	
�	�	���Q�w�Z�.�.�w�7�8��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8��
�
�9�;<�=��i�i�n�n�)�)�	+�	
�
�
�>��B��i�i�n�n�)�)�	+rc�|�dtjd�}|jj|dj	d�|d��|jjddd	�|j
|jjj|j�|j
|jjj|j�|jd
|z|jjj�|jd|z|jjj�y)Nr�r�r�rr��rr�rr�r�r�r�r�s  r�*test_connect_with_tunnel_with_default_portz6TunnelTests.test_connect_with_tunnel_with_default_port�s���'��%�%�
��	
�	�	���Q�w�Z�.�.�w�7�a��j��I��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8��
�
�9�;<�=��i�i�n�n�)�)�	+�	
�
�
�>��B��i�i�n�n�)�)�	+rc�`�ddd�}|jj|djd�|d��|jjdd	d
�|j	|jj
j|j�|j	|jj
j|j�|jd|z|jj
j�|jd|z|jj
j�y)
Nr�r�r�r�rr�r�r�rr�r�s*HEAD / HTTP/1.1
Host: %(host)s:%(port)d
)
r�r�rpr�r�r�rrr�rr�s  r�.test_connect_with_tunnel_with_nonstandard_portz:TunnelTests.test_connect_with_tunnel_with_nonstandard_port
	s���'��
��	
�	�	���Q�w�Z�.�.�w�7�a��j��I��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8��
�
�9�;<�=��i�i�n�n�)�)�	+�	
�
�
�G�!�K��i�i�n�n�)�)�	+rc��ddtjd�}|jj|dj	d�d|dj	d�i��|jjd	d
d�|j
|jjj|j�|j
|jjj|j�|jd|z|jjj�|jd
|z|jjj�y)Nr�sexample.com:9876)r��tunnel_host_headerr�r�rr�r�r@r�rr�sDCONNECT %(host)s:%(port)d HTTP/1.1
HOST: %(tunnel_host_header)s

r�r�r�s  r�3test_connect_with_tunnel_with_different_host_headerz?TunnelTests.test_connect_with_tunnel_with_different_host_header	s��'�#6��%�%�
��
	
�	�	���
�g�J���g�&��Q�4�5�<�<�W�E�F�	�	H�	
�	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�d�i�i�8��
�
�>�@A�B��i�i�n�n�)�)�	+�	
�
�
�>��B��i�i�n�n�)�)�	+rc�r�dtjd�}|jj|dj	d��|jjddd�|j
|jjj|j�|j
|jjj|j�|jd|z|jjj�|jd	|z|jjj�yr�r�r�s  r�'test_connect_with_tunnel_different_hostz3TunnelTests.test_connect_with_tunnel_different_host1	r�rc��d}d|jd�tjfz}d||fz}|jj	|�|jjddd�|j
|jjj|j�|j
|jjjtj�|j||jjj�y)Nu	δπθ.grs%s:%d�idnas!CONNECT %s HTTP/1.1
Host: %s

r�rr�)rrr�r�r�r�r�r�rrr�r)r�dest�	dest_portr�s    r�test_connect_with_tunnel_idnaz)TunnelTests.test_connect_with_tunnel_idna@	s���&������F� 3�V�5E�5E�F�F�	�=��y�A"�"���	�	���T�"��	�	���&�#�r�*���������,�,�d�i�i�8���������,�,�f�.>�.>�?��
�
�h��	�	��� 3� 3�4rc�F�	tjj|jd�5}|jj	d�|jj�|jj
dd�ddd�j�|jt|j�dd|j����|jddd}|jd	|�|j|jd
�d|����y#1swY��xYw)Nr	r�r�rr!z!unexpected number of send calls: )r�rsCONNECT destination.comr#zunexpected proxy data sent )r�patch�objectr�r�r`r��
assert_calledr�ro�
mock_callsr�r�r�)r�	mock_send�proxy_setup_data_sents   r�0test_tunnel_connect_single_send_connection_setupz<TunnelTests.test_tunnel_connect_single_send_connection_setupK	s��F�
�Z�Z�
�
�t�y�y�&�
1�Y��I�I� � �!2�3��I�I�����I�I���e�S�)�2�	���!�����I�(�(�)�1�7�	�8L�8L�7M�N�	�	P�!*� 4� 4�Q� 7�� :�1� =���
�
�0�2G�H����%�.�.�{�;�1�2G�1J�K�	�	M�2�
1�s�AD�D c�r�dtjd�}|jj|dj	d��|jjddd�|j
|jjj|j�|j
|jjj|j�|jd|z|jjj�|jd	|z|jjj�y)
Nr�r�r�rr�rr�r�s PUT / HTTP/1.1
Host: %(host)s
r�r�s  r�test_connect_put_requestz$TunnelTests.test_connect_put_request\	s���'��%�%�
��	
�	�	���Q�w�Z�.�.�w�7�8��	�	���%��b�)���������,�,�d�i�i�8���������,�,�d�i�i�8��
�
�9�;<�=��i�i�n�n�)�)�	+�	
�
�
�=��A��i�i�n�n�)�)�	+rc�&�|jjdd�|jjddd�|j|jjj
|j
�|j|jjjtj�|jd|jjj�|jd|jjj�y)Nz
[1:2:3::4]i�r�rr��CONNECT [1:2:3::4]:1234�Host: [1:2:3::4]:1234�r�r�r�r�r�rrrr�r�rr/s r�test_connect_put_request_ipv6z)TunnelTests.test_connect_put_request_ipv6k	s����	�	���\�4�0��	�	���%��b�)���������,�,�d�i�i�8���������,�,�f�.>�.>�?��
�
�0�$�)�)�.�.�2E�2E�F��
�
�.��	�	���0C�0C�Drc�$�|jjd�|jjddd�|j|jjj
|j
�|j|jjjtj�|jd|jjj�|jd|jjj�y)Nz[1:2:3::4]:1234r�rr�rrrr/s r�"test_connect_put_request_ipv6_portz.TunnelTests.test_connect_put_request_ipv6_ports	s����	�	���.�/��	�	���%��b�)���������,�,�d�i�i�8���������,�,�f�.>�.>�?��
�
�0�$�)�)�.�.�2E�2E�F��
�
�.��	�	���0C�0C�Drc���d}dj|�}|jjd�|j|�|j_|jj	d�tj�5}|jjddd�ddd�j�j�}|jdj|�|�y#1swY�IxYw)	Nz
X-Dummy: 1zHTTP/1.0 200 OK
{}

r!r�r�rr�z
header: {})r�r��set_debuglevelr\r�rr�r�r�r�r�)r�expected_headerr�r�r�s     r�test_tunnel_debuglogz TunnelTests.test_tunnel_debuglog{	s���&��7�>�>��O�
��	�	� � ��#�'+�'>�'>�}�'M��	�	�$��	�	���.�/�
�
$�
$�
&�&��I�I���e�S�"�-�'����!�,�,�.���
�
�l�)�)�/�:�E�B�'�
&�s�>C$�$C-c�l�d}djdj|��}|j|�|j_|jj	d�|jjddd�|jj
�}|j||j��y)N�zX-Dummy�1�HTTP/1.0 200 OK
{0}

�:r�r�rr�)	r�r�r\r�r�r��get_proxy_response_headersr��items�rrr�r�s    r�test_proxy_response_headersz'TunnelTests.test_proxy_response_headers�	s���*��
� �&����/�!:�;�	�
(,�'>�'>�}�'M��	�	�$��	�	���.�/��	�	���%��b�)��)�)�6�6�8���
�
�o�w�}�}��7rc��d}djdj|��}|j|�|j_|jj	ddd�|jj�}|j
|�y)Nrrrr�rr�)r�r�r\r�r�rr$r!s    r�test_no_proxy_response_headersz*TunnelTests.test_no_proxy_response_headers�	ss��*��
� �&����/�!:�;�	�
(,�'>�'>�}�'M��	�	�$��	�	���%��b�)��)�)�6�6�8�����'�"rc�6��d�d�fd�	}||j_|jjd�d}	|jjddd�|j|�|j
�j�y#t$r}|}Yd}~�=d}~wwxYw)Nc�0��td|d|d����S)NzHTTP/1.1 404 NOT FOUND

rr!r�r�)r�r#rr�s   �rr\z8TunnelTests.test_tunnel_leak.<locals>._create_connection�	s%����0��Q�Z��Q�Z��D�
�Krr�r�rr�r�)r�r\r�r�rDr�r�r)rr\r��er�s    @r�test_tunnel_leakzTunnelTests.test_tunnel_leak�	s������	�(:��	�	�$��	�	���.�/���	��I�I���f�c�2�.�	
���S�!�����(�(�)��	�	��C��	�s�B�	B�B�BN)r9r:r;r�rr\r�r�r�r�r�r�r�r�r�rrrrrrr"r$r(r2rrr�r��ss��	N��!�

J�D�D�-�
+�
+�
+�$+�$
+�	5�M�"
+�E�E�C�8�#�*rr��__main__r�)�	verbosity)=r�rE�httprrr<r��osr
rjr�r�rr�TestCaser(r�test.supportrr�requires_working_socket�path�dirnamer�herer�rtr~rir1r0�chunk_extensionr2rjrr3r�rr?r=rIr�rUrfr�r�rr�r�r�r�r�rrr+rCr�r�r�r9�mainr2rr�<module>r5s!����#�	��	��	�
���������"�&�����t�,�	�w�w���x� �������d�J�
�>���G�G�L�L��z�>�B��#%�7�7�<�<��*�7�$� �	-��N����
�
��O�+�f�4��-��������
�
�B

�*�

��2�:�:��$2�v�4�4�2�"z;�(�z;�z5�h�5�,}�8�}�@d'��d'�NA(�x�A(�HJ�)9�J�
�.��,��DR8�(�R8�j7��7�>+�(�+�\E.�h�E.�Pv8��v8�r]F�h�]F�@!%�x�!%�FN*�(�N*�b�z���H�M�M�A��r

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