Sindbad~EG File Manager

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

a

��g8�@s4ddlZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlm
Z
ejZddlmZddlmZej�e�Zej�ed�Zej�ed�Zej�ed�Zd	Zd
ZdZdZd
edZdZ dZ!ej"Z"Gdd�d�Z#Gdd�de#�Z$Gdd�dej%�Z&Gdd�dej'�Z(Gdd�de�Z)Gdd�de�Z*Gdd�de�Z+Gdd�de�Z,Gd d!�d!e�Z-Gd"d#�d#e-�Z.Gd$d%�d%�Z/Gd&d'�d'e�Z0Gd(d)�d)e�Z1Gd*d+�d+e�Z2Gd,d-�d-e�Z3Gd.d/�d/e�Z4Gd0d1�d1e�Z5Gd2d3�d3e�Z6Gd4d5�d5e�Z7e8d6k�r0ej9d7d8�dS)9�N)�client�
HTTPStatus)�mock)�support)�
socket_helperzkeycert.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@sHeZdZejddfdd�Zdd�Zddd�Zdd	�Zd
d�Z	dd
�Z
dS)�
FakeSocketNcCsBt|t�r|�d�}||_||_d|_d|_d|_||_||_	dS)N�ascii�rF)
�
isinstance�str�encode�text�	fileclass�data�
sendall_calls�file_closed�host�port)�selfrrrr�r�-/usr/local/lib/python3.9/test/test_httplib.py�__init__2s

zFakeSocket.__init__cCs |jd7_|j|7_dS)N�)rr�rrrrr�sendall=szFakeSocket.sendallcCs6|dkr|dkrt���|�|j�|_|j|j_|jS)N�r�rb)rZUnimplementedFileModerr�file�
file_close�close)r�mode�bufsizerrr�makefileAs

zFakeSocket.makefilecCs
d|_dS)NT)r�rrrrr IszFakeSocket.file_closecCsdS�Nrr%rrrr!LszFakeSocket.closecCsdSr&r)r�levelZoptname�valuerrr�
setsockoptOszFakeSocket.setsockopt)N)�__name__�
__module__�__qualname__�io�BytesIOrrr$r r!r)rrrrr	1s
r	c@s$eZdZdd�Zdd�Zdd�ZdS)�EPipeSocketcCst�||�||_dSr&)r	r�pipe_trigger)rrr0rrrrTszEPipeSocket.__init__cCs(|j|vrttjd��|j|7_dS)NZgotcha)r0�OSError�errno�EPIPErrrrrrYs
zEPipeSocket.sendallcCsdSr&rr%rrrr!^szEPipeSocket.closeN)r*r+r,rrr!rrrrr/Rsr/c@s$eZdZdZddd�Zd	dd�ZdS)
�NoEOFBytesIOz�Like BytesIO, but raises AssertionError on EOF.

    This is used below to test that http.client doesn't try to read
    more from the underlying file than it should.
    ���cCs"tj�||�}|dkrtd��|S�Nrzcaller tried to read past EOF)r-r.�read�AssertionError)r�nrrrrr7gszNoEOFBytesIO.readNcCs"tj�||�}|dkrtd��|Sr6)r-r.�readliner8)r�lengthrrrrr:mszNoEOFBytesIO.readline)r5)N)r*r+r,�__doc__r7r:rrrrr4as
r4cs4eZdZdZ�fdd�Z�fdd�Zdd�Z�ZS)�FakeSocketHTTPConnectionz@HTTPConnection subclass using FakeSocket; counts connect() callscs$d|_t��d�||_|j|_dS)Nr�example.com)�connections�superr�fake_socket_args�create_connection�_create_connection)r�args��	__class__rrrvsz!FakeSocketHTTPConnection.__init__cs|jd7_t���S)z.Count the number of times connect() is invokedr)r?r@�connectr%rErrrG|sz FakeSocketHTTPConnection.connectcOs
t|j�Sr&)r	rA�r�pos�kwrrrrB�sz*FakeSocketHTTPConnection.create_connection)r*r+r,r<rrGrB�
__classcell__rrrErr=ssr=c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�HeaderTestscCs�Gdd�dt�}dD]n}dD]d}t�d�}td�|_|�|_d}i}|rXtt|��||<|�dd	||�|�	|jj
|��d
�qqdS)Nc@seZdZdd�Zdd�ZdS)z;HeaderTests.test_auto_headers.<locals>.HeaderCountingBuffercSs
i|_dSr&)�countr%rrrr�szDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__cSsX|�d�}t|�dkrH|d�d���}|j�|d�|j|d7<t�||�dS)N�:rrr
)�split�len�decode�lowerrM�
setdefault�list�append)r�item�kvZlcKeyrrrrU�s
zBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.appendN�r*r+r,rrUrrrr�HeaderCountingBuffer�srY)TF)�Content-lengthZHostzAccept-encodingr>ZblahblahblahZspamspamspam�POST�/r)rTr�HTTPConnectionr	�sock�_bufferr
rP�request�assertEqualrMrR)rrYZexplicit_header�header�conn�body�headersrrr�test_auto_headers�s

zHeaderTests.test_auto_headerscCsfGdd�dt�}d}d}t�||�D]J\}}t�d�}td�|_|�|_|�|d|�|�	|jj
dd�|��q$d	}|D]F}t�d�}td�|_|�|_|�|dd�|�	|jj
dd
�|��qx|D]F}t�d�}td�|_|�|_|�|dd�|�	|jj
dd�|��q�t�||�D]H}t�d�}td�|_|�|_|�|dd�|�	|jj
d
d�|���qdS)Nc@seZdZdd�Zdd�ZdS)z?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckercSst�|�d|_dSr&)rTr�content_lengthr%rrrr�s
zHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__cSsF|�dd�}t|�dkr6|d��dkr6|d��|_t�||�dS)NrNrrscontent-length)rOrPrR�striprgrTrU)rrVrWrrrrU�szFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.appendNrXrrrr�ContentLengthChecker�sri)N�)�PUTr[ZPATCHr>r\�0z%Header Content-Length incorrect on {})�GET�CONNECTZDELETE�HEADZOPTIONSZTRACEz.Header Content-Length set for empty body on {}rj� �1)
rT�	itertools�productrr]r	r^r_r`rarg�format�chain)rriZbodiesZmethods_with_body�methodrdrcZmethods_without_bodyrrr�test_content_length_0�sP

�

�

�

�z!HeaderTests.test_content_length_0cCs�t�d�}td�|_|�dd�|�dd�|�d|j�|�dd�|�d	|j�|�d
d�|�d|j�|�d
d�|�d|j�|�ddd�|�d|j�|�dd�|�d|j�|�dd�|�d|j�|�dd�|�d|j�|�dd�|�d|j�|�d d!�|�d"|j�|�d#d$�|�d%|j�|�d&d$�|�d'|j�|�d(d$�|�d)|j�|�d*d$�|�d+|j�dS),Nr>rmr\rZ�*sContent-length: 42ZFooz bar s
Foo:  bar ZBarz	baz	s
Bar: 	baz	Z
AuthorizationzBearer mytokensAuthorization: Bearer mytokenZ
IterHeaderZIterAZIterBsIterHeader: IterA
	IterBZLatinHeader��sLatinHeader: �Z
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 Spacer(sKey Space: valuez	KeySpace sKeySpace : valuesNonbreak�SpacesNonbreak�Space: values�NonbreakSpaces�NonbreakSpace: value)rr]r	r^�
putrequest�	putheader�assertInr_�rrcrrr�test_putheader�s>

zHeaderTests.test_putheadercCsxd}t�d�}td�}||_|�dd�|�|j�|��d}t�d�}td�}||_|�dd�|�|j�|��dS)NsCGET /foo HTTP/1.1
Host: [2001::]:81
Accept-Encoding: identity

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

z
[2001:102A::])rr]r	r^r`�
assertTruer�
startswith�r�expectedrcr^rrr�test_ipv6host_headers

z HeaderTests.test_ipv6host_headercCsFd}t|�}t�|�}|��|�|�d�d�|�|�d�d�dS)Nz4HTTP/1.1 200 OK
First: val
: nval
Second: val

ZFirst�valZSecond)r	r�HTTPResponse�beginra�	getheader�rrdr^�resprrr�!test_malformed_headers_coped_withs
z-HeaderTests.test_malformed_headers_coped_withcCs,dttdd��dttdd��d}t|�}t�|�}|��|�|�d�d	�|�|jdd	�|�|�d
�d�|�|jd
d�d�	t
ttdd���}|�|�d
�|�|�|jd
|�|�|�d��|�
d|j�|�d�|jdfD]0}|�|�d��|�
d|�|�|�d��q�dS)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!#$%&'*+-.^_`|~r(rjZVCHARzobs-textzobs-foldrz folded with spacezfolded with tab)�bytes�ranger	rr�r�rar��msg�join�map�chrZassertIsNotNoner|r�r��endswith)rrdr^r�ZvcharZfoldedrrr�test_parse_all_octets#s4�����
z!HeaderTests.test_parse_all_octetsc
Cs�t�d�}td�|_|�dd�d}|D]n\}}|�||f��H|�td��|�||�Wd�n1sn0YWd�q(1s�0Yq(dS)Nr>rjrmr\))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]r	r^rz�subTest�assertRaisesRegex�
ValueErrorr{)rrc�cases�namer(rrr�test_invalid_headersAs

z HeaderTests.test_invalid_headerscCs�d}t|�}tj|dd�}t���}|��Wd�n1s@0Y|����}|�|dd�|�|dd�|�|dd�|�|d	d
�dS)Ns9HTTP/1.1 200 OK
First: val
Second: val1
Second: val2
r)Z
debuglevelrzreply: 'HTTP/1.1 200 OK\r\n'zheader: First: val�zheader: Second: val1�zheader: Second: val2)	r	rr�r�captured_stdoutr��getvalue�
splitlinesra)rrdr^r��output�linesrrr�test_headers_debuglevel_s�
&z#HeaderTests.test_headers_debuglevelN)r*r+r,rfrwr~r�r�r�r�r�rrrrrL�sB"
rLc@seZdZdd�ZdS)�HttpMethodTestsc	Cs`d}|D]R}|�td��2t�d�}td�|_|j|dd�Wd�q1sP0YqdS)N)	zGET
zPOST
zPUT

z
POST
Valuez
POST
HOST:abczGET
rHost:abc
zPOST
Remainder:
z
GET
HOST:
z
PUTz'method can't contain control charactersr>r\)rv�url)r�r�rr]r	r^r`)r�methodsrvrcrrr�test_invalid_method_namesrs�

z)HttpMethodTests.test_invalid_method_namesN)r*r+r,r�rrrrr�qsr�c@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
dS)�TransferEncodingTestsIt's just a flesh woundcCsbt�d�}td�|_|�dd�|j|��dd�|�|jj�\}}}|�	|�}|�
||j�dS)Nr>rr[r\T)�encode_chunked)rr]r	r^rzZ
endheaders�
_make_body�_parse_requestr�_parse_chunkedra�
expected_body)rrc�_rdrrr�test_endheaders_chunked�s


z,TransferEncodingTest.test_endheaders_chunkedcCsvt�d�}td�|_|�dd|��ddi�|�|jj�\}}}|�ddd	�|�	�D��|�
|dd�|�
||j�t�d�}td�|_|�dd|j�d
�ddi�|�|jj�\}}}|�ddd	�|�	�D��|�
|dd�|�
||j�t�d�}td�|_|jddddid
|��d�|�|jj�\}}}|�ddd	�|D��|�
|dd�|�
|�
|�|j�dS)Nr>rr[r\�Transfer-Encoding�chunked�content-lengthcSsg|]}|���qSr�rR��.0�krrr�
<listcomp>�rz>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>�latin-1cSsg|]}|���qSrr�r�rrrr��rz
gzip, chunkedT)rer�rdcSsg|]}|���qSrr�r�rrrr��r)rr]r	r^r`r�r�r�assertNotIn�keysrar�rQr��rrcr�rerdrrr�test_explicit_headers�s<

�

�

�z*TransferEncodingTest.test_explicit_headerscCs�dD]�}t�d�}td�|_|�dd|j|d��|�|jj�\}}}|�|�}|�	||j
�|�	|dd�|�d	d
d�|D��qdS)N)FTr>rr[r\)�empty_linesr�r�r�cSsg|]}|���qSrr�r�rrrr��rz5TransferEncodingTest.test_request.<locals>.<listcomp>)rr]r	r^r`r�r�rr�rar�r�)rr�rcr�rerdrrr�test_request�s

�
z!TransferEncodingTest.test_requestcCslt�d�}td�|_|�ddd�|�|jj�\}}}|�|dd�|�dd	d
�|D��|�|d�dS)Nr>rr[r\rr�r�r�cSsg|]}|���qSrr�r�rrrr��rz8TransferEncodingTest.test_empty_body.<locals>.<listcomp>s0

)	rr]r	r^r`r�rrar�r�rrr�test_empty_body�s

z$TransferEncodingTest.test_empty_bodyFccsV|j�d�}t|�D]<\}}|r.|dr.dV|t|�dkrJ|dVq|VqdS)N� r�rr)r�rO�	enumeraterP)rr�r��idx�linerrrr��szTransferEncodingTest._make_bodycCs�|�d�}|d}i}d}|t|�krrt||�dkrr||�d�\}}|�d���}|�d���||<|d7}q||d�||dd��fS)N�
rrrNr�)rOrPrQrhr�)rrr�r`rer9�keyr�rrrr��s

z#TransferEncodingTest._parse_requestcCs�g}i}d}|�d�}|||d�\}}t|d�}|dkrF|d7}qx|�|t|��|�|�|d7}|t|�krqxqd�|�S)Nrr�r��rr)rO�intrarPrUr�)rrrd�trailersr9r��size�chunkrrrr��s


z#TransferEncodingTest._parse_chunkedN)F)r*r+r,r�r�r�r�r�r�r�r�rrrrr��s
&


r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2daS)b�	BasicTestcCs"|�hd�tttd���k�dS)N>r(�descriptionr��phrase�)r��set�dirrr%rrr�&test_dir_with_added_behavior_on_statussz0BasicTest.test_dir_with_added_behavior_on_statuscCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|j�|�|��d�|�	|���|�|j�|�
�|�	|j�d}t|�}t�|�}|�tj|j�dS)N�HTTP/1.1 200 Ok

TextrrsTextzHTTP/1.1 400.100 Not Ok

Text)
r	rr�r�rar7�assertFalse�isclosed�closedr�r!�assertRaises�
BadStatusLiner�rrr�test_status_liness 

zBasicTest.test_status_linescCst�d�}|�t|�d�dS)NrjzBadStatusLine("''"))rr�ra�repr)r�excrrr�test_bad_status_repr!s
zBasicTest.test_bad_status_reprcCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS�Nz*HTTP/1.1 200 Ok
Content-Length: 4

Textr��Te�xt�r	rr�r�rar7r�r�r�r�r!r�rrr�test_partial_reads%s
zBasicTest.test_partial_readscCs~d}t|�}t�|�}|��|�|��d�|�|���|�|��d�|�	|���|�|j
�|��|�	|j
�dS)Nz4HTTP/1.1 200 Ok
Content-Length: 13

Text
AnothersText
sAnother)r	rr�r�rar:r�r�r7r�r�r!r�rrr�test_mixed_reads4s
zBasicTest.test_mixed_readscCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�
|�	��|�|j�|��|�
|j�dSr��
r	rr�r��	bytearray�readintorar�r�r�r�r�r!�rrdr^r��br9rrr�test_partial_readintosCs 


z BasicTest.test_partial_readintoscCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS)Nr�r�r�r�rrr�r�rrr�$test_partial_reads_no_content_lengthWs
z.BasicTest.test_partial_reads_no_content_lengthcCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�|�}|�|d�|�
|�	��dS)Nr�r�r�r�r)r	rr�r�r�r�rar�r�r�r�r�rrr�(test_partial_readintos_no_content_lengthgs



z2BasicTest.test_partial_readintos_no_content_lengthcCstd}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|�d�d�|�|���dS)N�+HTTP/1.1 200 Ok
Content-Length: 10

Textr�r�r�rr)	r	rr�r�rar7r�r�r�r�rrr�"test_partial_reads_incomplete_bodyzs
z,BasicTest.test_partial_reads_incomplete_bodycCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�|�}|�|d�|�
|�	��|�|j�|��|�
|j�dS)Nr�r�r�r�rr�r�rrr�&test_partial_readintos_incomplete_body�s$



z0BasicTest.test_partial_readintos_incomplete_bodycCsVdD]}|�tjtj|�qdD]0\}}}t�|�}|�||j�|�||j�q dS)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]rarr�rZhp�h�p�crrr�test_host_port�s
zBasicTest.test_host_portcCs<d}d}t|�}t�|�}|��|�d�}|�||�dS)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)r	rr�r�r�ra)rrZhdr�srZcookiesrrr�test_response_headers�s

zBasicTest.test_response_headerscCs6tdt�}tj|dd�}|��|��r2|�d�dS)N�*HTTP/1.1 200 OK
Content-Length: 14432

ro�rv�)Did not expect response from HEAD request)r	r4rr�r�r7�fail�rr^r�rrr�test_read_head�s�zBasicTest.test_read_headcCsTtdt�}tj|dd�}|��td�}|�|�dkr@|�d�|�t	|�d�dS)Nrror�rr�)
r	r4rr�r�r�r�rrar�)rr^r�r�rrr�test_readinto_head�s�
zBasicTest.test_readinto_headcCsRd�dd�ttjd�D��d}d|}t|�}t�|�}|�tjd|j�dS)Nrcss|]}d|VqdS)z
Header%d: fooNr)r��irrr�	<genexpr>�s�z2BasicTest.test_too_many_headers.<locals>.<genexpr>rzHTTP/1.1 200 OK
zgot more than \d+ headers)	r�r�rZ_MAXHEADERSr	r�r��
HTTPExceptionr�)rrerrrrrr�test_too_many_headers�s
��
�zBasicTest.test_too_many_headersc	Cs�d}ttd��`}t�d�}t|�}||_|�dd|�|�|j�	|�d|jdt
|��|f�Wd�n1st0YdS)Ns_GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

rr>rmrz%r != %r)�open�__file__rr]r	r^r`r�rr�rP�rr�rdrcr^rrr�test_send_file�s
�zBasicTest.test_send_filecCs�d}t�d�}td�}||_|�|�|�||j�d|_|�t�d|��|�||j�d|_|�t�	|��|�||j�dS)Ns"this is a test this is only a testr>rr�)
rr]r	r^�sendrar�arrayr-r.r�rrr�	test_send�s

zBasicTest.test_sendcsXdd��G�fdd�dtj�}d}t�d�}td�}||_|�|��|�|j|�dS)NcssdVdVdVdS)NrZdata_tworrrrrrsz/BasicTest.test_send_updating_file.<locals>.datacs eZdZdZ��Zddd�ZdS)z7BasicTest.test_send_updating_file.<locals>.UpdatingFilerr5cSs
t|j�Sr&)�next�d)r�	blocksizerrrr7
sz<BasicTest.test_send_updating_file.<locals>.UpdatingFile.readN)r5)r*r+r,r"rr7r�rrr�UpdatingFilesrsdatar>rj)	r-�
TextIOBaserr]r	r^rrar)rrr�rcr^rrr�test_send_updating_files
z!BasicTest.test_send_updating_filecCsLd}dd�}t�d�}td�}||_|�dd|�dd	i�|�|j|�dS)
NsbGET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Content-Length: 11

onetwothreecssdVdVdVdS)Nsonestwosthreerrrrrrdsz&BasicTest.test_send_iter.<locals>.bodyr>rjrmrr�Z11)rr]r	r^r`rarrrrr�test_send_iters
zBasicTest.test_send_itercCsvd}tjd|d�}td�}||_d|d}|�ddt�|�d	d
i�|�|jd�|j	�
dd
�d
}|�||�dS)z8Check that request() respects the configured block size.�r>�rN�a�brkr\r��9r��

r)rr]r	r^r`r-r.rarrrO)rrrcr^r�rdrrr�test_blocksize_request&sz BasicTest.test_blocksize_requestcCs\d}tjd|d�}td�}||_d|d}|�t�|��|�|jd�|�|j	|�dS)z5Check that send() respects the configured block size.rr>rNr r!r�)
rr]r	r^rr-r.rarr)rrrcr^r�rrr�test_blocksize_send2szBasicTest.test_blocksize_sendcCsPt�d�}td�|_|�t��|�dd|�Wd�n1sB0YdS)Nr>rjr[�test)rr]r	r^r��	TypeErrorr`r}rrr�test_send_type_error=s

zBasicTest.test_send_type_errorcCsft}tttt�}tj|dd�}|��|�|�	�|�|�
�tdd�D]V}tttt�}tj|dd�}|��|�|�	|�|�	|�|�	�|�|�
�qLdD]�}tt|�}tj|dd�}|��z�z|�	�Wnbtj�y>}zF|�|j
|�dt|�}|�t|�|�|�t|�|�WYd}~nd}~00|�d�W|�
�q�|�
�0q�dS)Nrmrr��rjzfoo
�IncompleteRead(%d bytes read)�IncompleteRead expected)�chunked_expectedr	�
chunked_start�
last_chunk�chunked_endrr�r�rar7r!r��IncompleteRead�partialrPr�r
r)rr�r^r�r9�xr�expected_messagerrr�test_chunkedDs2$
&zBasicTest.test_chunkedcCs�t}t|�}td�}tttt�}tj|dd�}|�	�|�
|�}|�|d|�|�|�||�|��t
dd�D]�}tttt�}tj|dd�}|�	�t|�}|�
|d|��}||�
||||��7}||�
||d��7}|�|d|�|�|�||�|��qvdD]�}	tt|	�}tj|dd�}|�	�z�z|�
|�}Wnbtj�y�}zF|�|j|�dt|�}
|�t|�|
�|�t|�|
�WYd}~nd}~00|�d	�W|��n
|��0�qdS)
Nr�rmrrr)rr*r+r,)r-rPr�r	r.r/r0rr�r�r�rar!r��
memoryviewr1r2r�r
r)rr�Z	nexpectedr�r^r�r9�mrr3r4rrr�test_readinto_chunkeddsD

&zBasicTest.test_readinto_chunkedcCs�d}t|tt�}tj|dd�}|��|�|��d�|�|jd�|�|j	d�|�
|���|�|j
�|��|�
|j
�dS)N�EHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
rorr���OK)r	r/r0rr�r�rar7�status�reasonr�r�r�r�r!)rr.r^r�rrr�test_chunked_head�s�zBasicTest.test_chunked_headcCs�d}t|tt�}tj|dd�}|��td�}|�|�}|�|d�|�t	|�d�|�|j
d�|�|jd�|�|�
��|�|j�|��|�|j�dS)	Nr9rorrrr	r:r;)r	r/r0rr�r�r�r�rar�r<r=r�r�r�r�r!)rr.r^r�r�r9rrr�test_readinto_chunked_head�s�
z$BasicTest.test_readinto_chunked_headcCs@td�}tj|dd�}|��|�|��d�|�|���dS)Nz.HTTP/1.1 200 OK
Content-Length: -1

Hello
rmr�Hello
)r	rr�r�rar7r�r�rrrr�test_negative_content_length�s�z&BasicTest.test_negative_content_lengthc
Cs�td�}tj|dd�}|��z|��Wnbtjy�}zH|�|jd�|�t|�d�|�t	|�d�|�
|���WYd}~nd}~00|�d�dS)Nz.HTTP/1.1 200 OK
Content-Length: 10

Hello
rmrr@z-IncompleteRead(7 bytes read, 3 more expected)r,)
r	rr�r�r7r1rar2r�r
r�r�r)rr^r�rrrr�test_incomplete_read�s
�
�$zBasicTest.test_incomplete_readcsZtdd�}t�d��|�_|�t�fdd�����}|�d|j�|�d|�	d��dS)	NzgHTTP/1.0 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Basic realm="example"
sContent-Lengthr>cs��ddd�S)Nrk�/urlrd)r`r�rcrr�<lambda>�rz&BasicTest.test_epipe.<locals>.<lambda>i�zBasic realm="example"zwww-authenticate)
r/rr]r^r�r1�getresponserar<r�rrrDr�
test_epipe�s�

��zBasicTest.test_epipecCs8dddd}t�t|��}|�tjtjf|j�dS)N�HTTP/1.1 200 Okr��r)rr�r	r��LineTooLongr�r��rrdr�rrr�test_overflowing_status_line�sz&BasicTest.test_overflowing_status_linecCs2dddd}t�t|��}|�tj|j�dS)NzHTTP/1.1 200 OK
X-Foo: barrrIz

)rr�r	r�rJr�rKrrr�test_overflowing_header_line�s���z&BasicTest.test_overflowing_header_linecCsrdd}t�t|��}|�tj��}|��Wd�n1s@0Y|�dt|j��|�dt|j��dS)NzHTTP/1.1 100 OK
r
i�zgot more than re)	rr�r	r�r
r�r|r
�	exception)rrdr��cmrrr�'test_overflowing_header_limit_after_100�s��&z1BasicTest.test_overflowing_header_limit_after_100cCs:dddd}t�t|��}|��|�tj|j�dS)Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

rrIza
hello world
0

)rr�r	r�r�rJr7rKrrr�test_overflowing_chunked_line�s���z'BasicTest.test_overflowing_chunked_linecCs`d}t|�}t�|�}|��|�|��d�|�|���|�|j	�|�
�|�|j	�dS)NrHr)r	rr�r�rar7r�r�r�r�r!r�rrr�test_early_eof
s
zBasicTest.test_early_eofcsnt�d�}d�G�fdd�dtj�}||_td�|_|�dd�|�tj|j	�|�
�j�|�
|jj�dS)Nr>cseZdZ�fdd�ZdS)z+BasicTest.test_error_leak.<locals>.Responsecs"|�tjj|g|�Ri|��dSr&)rr�rrH��responserrrsz4BasicTest.test_error_leak.<locals>.Response.__init__N)r*r+r,rrrSrr�ResponsesrUzInvalid status linermr\)
rr]r�Zresponse_classr	r^r`r�r�rFr�r�r)rrcrUrrSr�test_error_leaks

zBasicTest.test_error_leakcCsRd}td}tt|tt�}tj|dd�}|��|�|�	�|�|�
�dS)Nz3;foo=bar
abc
sabcrmr)r-r	r.�last_chunk_extendedr0rr�r�rar7r!)r�extrar�r^r�rrr�test_chunked_extension&sz BasicTest.test_chunked_extensioncCsBt}ttt�}tj|dd�}|��|�|��|�|�	�dS)z9some servers may serve up a short chunked encoding streamrmrN)
r-r	r.r/rr�r�rar7r!�rr�r^r�rrr�test_chunked_missing_end0sz"BasicTest.test_chunked_missing_endcCs\t}ttttt�}tj|dd�}|��|�	|�
�|�|�	|j�
�d�|��dS)z&See that trailers are read and ignoredrmrrN)
r-r	r.r/r�r0rr�r�rar7rr!rZrrr�test_chunked_trailers9szBasicTest.test_chunked_trailerscCsjt}d}ttttt|�}tj|dd�}|��|�	|�
�|�|�	|j�
�|�d��|�
�dS)zDCheck that we don't read past the end of the chunked-encoding stream�	extradatarmrr
N)r-r	r.r/r�r0rr�r�rar7rrr!)rr�r]r^r�rrr�test_chunked_syncDszBasicTest.test_chunked_synccCs\d}d}td||�}tj|dd�}|��|�|��|�|�|j��|�|��dS)zBCheck that we don't read past the end of the Content-Length stream�	extradata�
Hello123
�'HTTP/1.1 200 OK
Content-Length: 10

rmrN)r	rr�r�rar7rr!�rr]r�r^r�rrr�test_content_length_syncPsz"BasicTest.test_content_length_synccCs`d}d}td||�}tj|dd�}|��|�|�d�|g�|�|j��|�|��dS�Nr_r`rarmri�)	r	rr�r�ra�	readlinesrr7r!rbrrr�test_readlines_content_length\sz'BasicTest.test_readlines_content_lengthcCs^d}d}td||�}tj|dd�}|��|�|�d�|�|�|j��|�|��dSrd)	r	rr�r�ra�read1rr7r!rbrrr�test_read1_content_lengthgsz#BasicTest.test_read1_content_lengthcCspd}d}td||�}tj|dd�}|��|�|�d�|�|�|�d�d�|�|j��|�|��dS)Nr_r`rarmr�
r)	r	rr�r�rar:rr7r!rbrrr�"test_readline_bound_content_lengthrsz,BasicTest.test_readline_bound_content_lengthcCsvd}d}td|d|�}tj|dd�}|��|�|�d�|d�|�|��|�|�|j��|�|��dS)	Nr_r`s'HTTP/1.1 200 OK
Content-Length: 30

r�rmr�r�)	r	rr�r�rargr7rr!rbrrr�test_read1_bound_content_length~sz)BasicTest.test_read1_bound_content_lengthcs�t�tdf��|��j�d���fdd�}tj|d�}|��|�|jt	d��t
j����}|�
dd�|��}zV|�|jt
j�tj|��d�}z|�d	�W|��n
|��0W|��|��n|��|��0|��|��d	�dS)
Nrc	s����\}}|�b|�d��8}|��}|�d�sq4q|�d�|���Wd�n1sZ0YWd�n1sx0YdS)Nrr�s'HTTP/1.1 200 Connection established

)�acceptr$r:�rstriprr7)rc�address�readerr���result�servrr�
run_server�s

z2BasicTest.test_response_fileno.<locals>.run_server)�targetrrnz
dummy:1234)�filenos
proxied data
)�socket�
create_server�HOST�
addCleanupr!�	threading�Thread�startr��floatrr]�getsocknamer`rFrar<r;rvr�detach)rrt�threadrcrTrrrqr�test_response_fileno�s,
�
zBasicTest.test_response_filenocCs4Gdd�dtj�}|d�}td�|_|�dd�dS)zv
        It should be possible to override the default validation
        behavior in putrequest (bpo-38216).
        c@seZdZdd�ZdS)zRBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnectioncSsdSr&r�rr�rrr�_validate_path�szaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_pathN)r*r+r,r�rrrr�UnsafeHTTPConnection�sr�r>rjrmz/N�rr]r	r^rz�rr�rcrrr�*test_putrequest_override_domain_validation�s
z4BasicTest.test_putrequest_override_domain_validationcCs8Gdd�dtj�}|d�}td�|_|jdddd�dS)	Nc@seZdZdd�ZdS)zPBasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnectioncSsdSr&rr�rrr�_validate_host�sz_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_hostN)r*r+r,r�rrrrr��sr�z
example.com
rjrmr\r)Z	skip_hostr�r�rrr�(test_putrequest_override_host_validation�s
z2BasicTest.test_putrequest_override_host_validationcCs4Gdd�dtj�}|d�}td�|_|�dd�dS)z�
        It should be possible to override the default encoding
        to transmit bytes in another encoding even if invalid
        (bpo-36274).
        c@seZdZdd�ZdS)zIBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnectioncSs
|�d�S)Nzutf-8)r)rZstr_urlrrr�_encode_request�szYBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnection._encode_requestN)r*r+r,r�rrrrr��sr�r>rjrmu/☃Nr�r�rrr�!test_putrequest_override_encoding�s
z+BasicTest.test_putrequest_override_encodingN)3r*r+r,r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrrr$r%r(r5r8r>r?rArBrGrLrMrPrQrRrVrYr[r\r^rcrfrhrjrlr�r�r�r�rrrrr�s`

	 +


	%
r�c@sxeZdZdZdZee�d�d��d�ZdZdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�ExtendedReadTestz*
    Test peek(), read1(), readline()
    zOHTTP/1.1 200 OK

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

a
hello worl
3
d!

9
and now 

23
for something completely different

3
foo
0

cCs8t|j�}tj|dd�}|��t�|j�|_||_dS)Nrmr)	r	r�rr�r�r-�BufferedReader�fpr�rrrr�setUp�s

zExtendedReadTest.setUpcs�|j}|jj�d�fdd�	}||j_g}|�d�}|r�|�t|�d�|��}|�t|�t|��|�|�|��|�t|��}|�	||�n|��}|�
|�|�|�|s(q�q(|�	d�|�|j
�dS)Nr5cs(�|�}|dkr|d|�S|dd�S)Nrrir)r9r��Zoldpeekrr�mypeeksz*ExtendedReadTest.test_peek.<locals>.mypeekr�rr)r5)r�r��peek�
assertGreaterrPZassertGreaterEqualr�r�r7rar�rUr��lines_expected)rr�r��allr�Zp2rrr�r�	test_peek�s&


zExtendedReadTest.test_peekcCs|j}|�|jj|j�dSr&)r��_verify_readliner:r�)rr�rrr�
test_readlineszExtendedReadTest.test_readlinecCs\g}|d�}|r4|dkr4t|�dkr4|�|�d��|�|�|sqFq|�d�|�|�dS)Nr�foo�
r)rPr�r�rUrar�)rr:r�r�r�rrrr� s
z!ExtendedReadTest._verify_readlinecs0�j���fdd�}t|�}��|j�j�dS)Ncs��d�}��t|�d�|S)N�)rg�assertLessEqualrP)�res�r�rrrr/s
z&ExtendedReadTest.test_read1.<locals>.r)r��	Readlinerr�r:r�)rrZ	readlinerrr�r�
test_read1-szExtendedReadTest.test_read1cCs<|j}g}|��}|sq$|�|�q
|�d�|�|j�dS�Nr)r�rgrUrar�r��rr�r�rrrr�test_read1_unbounded6sz%ExtendedReadTest.test_read1_unboundedcCsN|j}g}|�d�}|sq6|�t|�d�|�|�q
|�d�|�|j�dS)Nrir)r�rgr�rPrUrar�r�r�rrr�test_read1_bounded@s
z#ExtendedReadTest.test_read1_boundedcCs|�|j�d�d�dS)Nrr)rar�rgr%rrr�test_read1_0KszExtendedReadTest.test_read1_0cCs |j�d�}|�dt|��dS�Nr)r�r�r�rP)rr�rrr�test_peek_0NszExtendedReadTest.test_peek_0)r*r+r,r<r��findrr�Z
lines_chunkedr�r�r�r�r�r�r�r�r�rrrrr��s��	
	
r�c@seZdZdZdZdS)�ExtendedReadTestChunkedz:
    Test peek(), read1(), readline() in chunked mode
    r�N)r*r+r,r<r�rrrrr�Ss�r�c@s eZdZdZdd�Zdd�ZdS)r�zT
    a simple readline class that uses an arbitrary read function and buffering
    cCs||_d|_dSr�)�readfunc�	remainder)rr�rrrrmszReadliner.__init__cCs�g}d}|j}z�|�d�}|dkr$q^|t|�|kr@||d}|�|�|��}|sd}q^q|d7}|�|d|��||d�|_d�|�WSd�|�|_�Yn0dS)Nrr�r5rr)r�r�rPrUr�r�)r�limitrZdatalenr7r�rrrr:qs*

zReadliner.readlineN)r*r+r,r<rr:rrrrr�isr�c@s$eZdZdd�Zdd�Zdd�ZdS)�OfflineTestcCsfdh}ddh}tt�D]<}|�d�s||vr.qtt|�}t|dd�dkr|�|�q|�tj|�dS)N�	responsesZHTTPMessage�
parse_headersr�r+zhttp.client)r�rr��getattr�addZassertCountEqual�__all__)rr�Z	blacklistr�Z
module_objectrrr�test_all�s
zOfflineTest.test_allcCs|�tjtjd�dS)Nz	Not Found)rarr��	NOT_FOUNDr%rrr�test_responses�szOfflineTest.test_responsesc	CsRgd�}|D]@}|j|d�� |�tt|��Wd�q1sB0YqdS)N):ZCONTINUEZSWITCHING_PROTOCOLSZ
PROCESSINGr;ZCREATEDZACCEPTEDZNON_AUTHORITATIVE_INFORMATIONZ
NO_CONTENTZ
RESET_CONTENTZPARTIAL_CONTENTZMULTI_STATUSZIM_USEDZMULTIPLE_CHOICESZMOVED_PERMANENTLYZFOUNDZ	SEE_OTHERZNOT_MODIFIEDZ	USE_PROXYZTEMPORARY_REDIRECTZBAD_REQUESTZUNAUTHORIZEDZPAYMENT_REQUIREDZ	FORBIDDENr�ZMETHOD_NOT_ALLOWEDZNOT_ACCEPTABLEZPROXY_AUTHENTICATION_REQUIREDZREQUEST_TIMEOUTZCONFLICTZGONEZLENGTH_REQUIREDZPRECONDITION_FAILEDZREQUEST_ENTITY_TOO_LARGEZREQUEST_URI_TOO_LONGZUNSUPPORTED_MEDIA_TYPEZREQUESTED_RANGE_NOT_SATISFIABLEZEXPECTATION_FAILEDZIM_A_TEAPOTZMISDIRECTED_REQUESTZUNPROCESSABLE_ENTITYZLOCKEDZFAILED_DEPENDENCYZUPGRADE_REQUIREDZPRECONDITION_REQUIREDZTOO_MANY_REQUESTSZREQUEST_HEADER_FIELDS_TOO_LARGEZUNAVAILABLE_FOR_LEGAL_REASONSZINTERNAL_SERVER_ERRORZNOT_IMPLEMENTEDZBAD_GATEWAYZSERVICE_UNAVAILABLEZGATEWAY_TIMEOUTZHTTP_VERSION_NOT_SUPPORTEDZINSUFFICIENT_STORAGEZNOT_EXTENDEDZNETWORK_AUTHENTICATION_REQUIREDZEARLY_HINTSZ	TOO_EARLY)Zconstant)r�r��hasattrr)rr��constrrr�test_client_constants�s<z!OfflineTest.test_client_constantsN)r*r+r,r�r�r�rrrrr��sr�c@s@eZdZdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
dS)�SourceAddressTestcCs>t�tjtj�|_t�|j�|_t��|_|j�	�d|_
dSr&)rw�AF_INET�SOCK_STREAMrsr�	bind_portrZfind_unused_port�source_port�listenrcr%rrrr��s


zSourceAddressTest.setUpcCs*|jr|j��d|_|j��d|_dSr&)rcr!rsr%rrr�tearDown�s


zSourceAddressTest.tearDowncCsBtjt|jd|jfd�|_|j��|�|jj�	�d|j�dS)Nrj��source_addressr)
rr]ryrr�rcrGrar^rr%rrr�testHTTPConnectionSourceAddress�s

�
z1SourceAddressTest.testHTTPConnectionSourceAddress�HTTPSConnectionz'http.client.HTTPSConnection not definedcCstjt|jd|jfd�|_dS)Nrjr�)rr�ryrr�rcr%rrr� testHTTPSConnectionSourceAddress�s
�z2SourceAddressTest.testHTTPSConnectionSourceAddressN)r*r+r,r�r�r��unittest�skipIfr�rr�rrrrr��s�r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)�TimeoutTestNcCs.t�tjtj�|_t�|j�t_|j��dSr&)	rwr�r�rsrr�r��PORTr�r%rrrr�szTimeoutTest.setUpcCs|j��d|_dSr&)rsr!r%rrrr�s
zTimeoutTest.tearDownc	Cs|�t���t�d�z$t�ttj�}|�	�Wt�d�nt�d�0|�
|j��d�|�
�|�t���t�d�z(tjttjdd�}|�	�Wt�d�nt�d�0|�
|j��d�|�
�tjttjdd�}|�	�|�
|j��d�|�
�dS�N�)�timeout)�assertIsNonerw�getdefaulttimeout�setdefaulttimeoutrr]ryr�r�rGrar^�
gettimeoutr!)rZhttpConnrrr�testTimeoutAttributes,



�
z TimeoutTest.testTimeoutAttribute)r*r+r,r�r�r�r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�PersistenceTestc
Cs�d}|D]�\}}}|j||d���d�||�}t|�}|�|j�|�dd�|���,}|�|jdu|�|��Wd�n1s�0Y|�|jdu|�|�|j	d�|�dd�|�|j	|r�dnd�Wd�q1s�0YqdS)	N))�1.0rjF)r�zConnection: keep-alive
T)�1.1rjT)r�zConnection: close
F)r�zConnection: keep-ALIVE
T)r�zConnection: cloSE
F)�versionrbz4HTTP/{} 200 OK
{}Content-Length: 12

Dummy body
rmz/open-connectionrz/subsequent-requestr�)
r�rtr=r�r^r`rFrar7r?)r�testsr�rbZreuser�rcrTrrr�test_reuse_reconnect/s"��
&z$PersistenceTest.test_reuse_reconnectc	Cs�dd�}tjtjf|tff}|D]~\}}|j|d��Ztd|�}|�dd�|�||j	�|�
|j�|�dd�|�|j
d�Wd�q 1s�0Yq dS)	Ncs&t�|���fdd�}|�_t���S)z3Return BufferedReader that raises ECONNRESET at EOFcs tj��|�}|dkrt��|Sr�)r-r.r��ConnectionResetError)�bufferr���streamrrr�RszNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readinto)r-r.r�r�)rr�rr�r�make_reset_readerOs
z<PersistenceTest.test_disconnected.<locals>.make_reset_reader)rNrrmz
/eof-response�
/reconnectr�)r-r.r�RemoteDisconnectedr�r�r=r`r�rFr�r^rar?)rr�r�Zstream_factoryrNrcrrr�test_disconnectedMs
�
z!PersistenceTest.test_disconnectedcCsVtd�}|jddddid�|�tj|j�|�|j�|�dd�|�|j	d�dS)	NsHTTP/1.1 100 Continue

rmr\ZExpectz100-continue)rer�r�)
r=r`r�rr�rFr�r^rar?r}rrr�test_100_closehs�zPersistenceTest.test_100_closeN)r*r+r,r�r�r�rrrrr�-sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�Ze�eed�d�dd��Zdd�ZdS)�	HTTPSTestcCsttd�s|�d�dS)Nr�zssl support required)r�r�skipTestr%rrrr�ws
zHTTPSTest.setUpcCsddlm}|||d�S)Nr)�make_https_server)�certfile)Ztest.ssl_serversr�)rr�r�rrr�make_server{szHTTPSTest.make_servercCs$tjttjdd�}|�|jd�dSr�)rr�ryr�r�rar�)rr�rrr�test_attributesszHTTPSTest.test_attributesc	Cs�ddl}t�d�t�d��dt�dd�}|�|j��}|�	dd�Wd�n1sX0Y|�
|jjd�Wd�n1s�0YdS)Nr�network�self-signed.pythontest.net�rmr\�CERTIFICATE_VERIFY_FAILED)
�sslr�requiresr�transient_internetrr�r��SSLErrorr`rarNr=)rr�r��exc_inforrr�test_networked�s
*zHTTPSTest.test_networkedcCs�ddl}t�d�t�d��^|��}tjdd|d�}|�dd�|�	�}|�
�|�d|�d	��|�
�Wd�n1s�0YdS)
Nrr�r�r���contextrmr\�nginx�server)
r�rr�rr�Z_create_unverified_contextrr�r`rFr!r|r�)rr�r�r�r�rrr�test_networked_noverification�s
�z'HTTPSTest.test_networked_noverificationcCs~t�d�t�d��Vt�dd�}|�dd�|��}|�d�}|�	�|�	�|�
d|�Wd�n1sp0YdS)Nr�r�r�rmr\zcontent-typez	text/html)rr�rr�rr�r`rFr�r!r|)rr�r�Zcontent_typerrr�&test_networked_trusted_by_default_cert�s

z0HTTPSTest.test_networked_trusted_by_default_certc	Csddl}t�d�d}t�|���|�|j�}|�|j|j	�|�|j
d�|�t�z(t
j|d|d�}|�dd�|��}WnT|jy�}z:t|�}t�d	|�r�t�d
|�d|�d����WYd}~n
d}~00|�d
�}|��|��|�d|�Wd�n1�s0YdS)Nrr�r�Tr�r�rmr\z(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.r�r�)r�rr�rr��
SSLContext�PROTOCOL_TLS_CLIENTraZverify_modeZ
CERT_REQUIRED�check_hostname�load_verify_locations� CERT_selfsigned_pythontestdotnetrr�r`rFr�r
�re�searchr�ZSkipTestr�r!r|)	rr�Zselfsigned_pythontestdotnetr�r�r�Zssl_errZssl_err_strZ
server_stringrrr�test_networked_good_cert�s6

���
z"HTTPSTest.test_networked_good_certc	Cs�ddl}t�d�t�d��~|�|j�}|�t�t	j
dd|d�}|�|j��}|�
dd�Wd�n1sr0Y|�|jjd�Wd�n1s�0YdS)	Nrr�r�r�r�rmr\r�)r�rr�rr�r�r�r��CERT_localhostrr�r�r�r`rarNr=)rr�r�r�r�rrr�test_networked_bad_cert�s

*z!HTTPSTest.test_networked_bad_certcCslddl}|�t�}t�d|j�}|�|j��}|�dd�Wd�n1sN0Y|�	|j
jd�dS)Nr�	localhostrmr\r�)r�r�rrr�rr�r�r`rarNr=)rr�r�r�r�rrr�test_local_unknown_cert�s
*z!HTTPSTest.test_local_unknown_certcCsxddl}|�t�}|�|j�}|�t�tjd|j|d�}|�	|j
�|�dd�|��}|�	|j
�|�
|jd�dS)Nrrr�rm�/nonexistentr�)r�r�rr�r�r�rr�rrzr!r`rFrar<�rr�r�r�r�r�rrr�test_local_good_hostname�s

z"HTTPSTest.test_local_good_hostnamecCs4ddl}|�t�}|�|j�}|�t�tjd|j|d�}|�	|j
��|�dd�Wd�n1sh0Yt�
dtf��$tjd|j|dd�}Wd�n1s�0Y|�	|j
��|�dd�Wd�n1s�0Yd	|_t�
dtf��$tjd|j|d	d�}Wd�n1�s,0Y|�dd
�|��}|��|��|�|jd�d	|_tjd|j|d�}|�dd
�|��}|�|jd�|��|��t�
dtf��$tjd|j|dd�}Wd�n1�s�0Y|�	|j
��|�dd�Wd�n1�s&0YdS)Nrrr�rmr\rjT)r�r�Frr�)r�r��CERT_fakehostnamer�r�r�rr�rr�ZCertificateErrorr`rZcheck_warnings�DeprecationWarningr�rFr!rar<rrrr�test_local_bad_hostname�sH

*
�$*
�&
�&z!HTTPSTest.test_local_bad_hostnamer�z)http.client.HTTPSConnection not availablecCsVdD]}|�tjtj|�qdD]0\}}}t�|�}|�||j�|�||j�q dS)Nr�)r�)zwww.python.org:443r�r�)r�r�r�)r�r�r�)r�r�r�)r�r�r�)r�rr�r�rarrr�rrrr�s
zHTTPSTest.test_host_portcCs�ddl}|js|�d�t�dd�}|�|jj�|�|j	�}|�
|j�tjdd|d�}|�|j|�|�
|jj�t�
��0t�ddt�tjdd|td�}Wd�n1s�0Y|�|jj�dS)	NrzTLS 1.3 support requiredrr�r��ignorez5key_file, cert_file and check_hostname are deprecated)r�Z	cert_file)r�ZHAS_TLSv1_3r�rr�r�Z_contextZpost_handshake_authr�r�r�ZassertIs�warnings�catch_warnings�filterwarningsrr)rr�r�r�rrr�test_tls13_pha*s$

�
�$zHTTPSTest.test_tls13_phaN)r*r+r,r�r�r�r�r�rZsystem_must_validate_certr�r�rrrr	r�r�r�rr�rrrrrr�us"

!	
*�
r�c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�RequestBodyTestz3Test cases where a request includes a message body.cCs,t�d�|_td�|j_|_|j|j_dS)Nr>rj)rr]rcr	r^r%rrrr�CszRequestBodyTest.setUpcCs(t�|jj�}|��t�|�}||fSr&)r-r.r^rr:rr��r�f�messagerrr�get_headers_and_fpHs
z"RequestBodyTest.get_headers_and_fpc	Cs�ddgdfdf}|D]�\}}|�|���t�d�|_td�|j_|_|j�dd|�|��\}}|�d	|�|�d
|�|�	|�
d�d�|�	||���Wd�q1s�0YqdS)
Nr��bar�3
foo
3
bar
0

))r�rrr>rjrkrCzContent-Typer�r�r�)r�rr]rcr	r^r`rr�ra�getr7)rr�rdr�r�rrrr�test_list_bodyNs
�zRequestBodyTest.test_list_bodycCsL|j�dddddi�|��\}}|�d|�d��|�dt|����dS)NrkrCrdr�Z42r�r�)rcr`rrarrPr7�rrrrrr�test_manual_content_lengthbs�z*RequestBodyTest.test_manual_content_lengthcCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)NrkrCrd�
text/plain�4r�sbody�	rcr`rra�get_content_typer��get_charsetrr7rrrr�test_ascii_bodykszRequestBodyTest.test_ascii_bodycCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)NrkrCubodyÁr�5r��body�rrrrr�test_latin1_bodyssz RequestBodyTest.test_latin1_bodycCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)NrkrCr!rr r�rrrrr�test_bytes_body{szRequestBodyTest.test_bytes_bodycCs�|�tjtj�ttjd��}|�d�Wd�n1s<0Yttj��|}|j�dd|�|��\}}|�	d|�
��|�|���|�|�
d��|�	d|�
d��|�	d	|���Wd�n1s�0YdS)
N�wrdrkrCrr�r�ztransfer-encodings4
body
0

)rzr�unlink�TESTFNr�writercr`rrarr�rrr7rrrr�test_text_file_body�s(z#RequestBodyTest.test_text_file_bodycCs�|�tjtj�ttjd��}|�d�Wd�n1s<0Yttjd��x}|j�dd|�|��\}}|�	d|�
��|�|���|�	d|�
d��|�d	|�|�	d
|���Wd�n1s�0YdS)N�wbr!rrkrCrr�r�r�s5
body�
0

)rzrr%r&rr'rcr`rrarr�rrr�r7rrrr�test_binary_file_body�s(z%RequestBodyTest.test_binary_file_bodyN)
r*r+r,r<r�rrrrr"r#r(r*rrrrr@s	rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�HTTPResponseTestcCs&d}t|�}t�|�|_|j��dS)NzXHTTP/1.1 200 Ok
My-Header: first-value
My-Header:                 second-value

Text)r	rr�r�r�)rrdr^rrrr��szHTTPResponseTest.setUpcCs6|j�d�}|�|d�|j�dd�}|�|d�dS)Nz	My-Headerzfirst-value, second-valuezsome default�r�r�ra�rrbrrr�test_getting_header�sz$HTTPResponseTest.test_getting_headercCs|j�dd�}|�|d�dS)N�No-Such-Headerz
default-valuer,r-rrr�3test_getting_nonexistent_header_with_string_default�szDHTTPResponseTest.test_getting_nonexistent_header_with_string_defaultcCs<|j�dddg�}|�|d�|j�dd�}|�|d�dS)Nr/�default�valueszdefault, values)r1r2r,r-rrr�5test_getting_nonexistent_header_with_iterable_default�szFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_defaultcCs|j�d�}|�|d�dS)Nr/r,r-rrr�/test_getting_nonexistent_header_without_default�sz@HTTPResponseTest.test_getting_nonexistent_header_without_defaultcCs |jjddd�}|�|d�dS)Nr/rx)r1r,r-rrr�test_getting_header_defaultint�sz/HTTPResponseTest.test_getting_header_defaultintN)	r*r+r,r�r.r0r3r4r5rrrrr+�sr+c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TunnelTestscCs*d}d|_t�|j�|_|�|�|j_dS)Nz:HTTP/1.0 200 OK

HTTP/1.1 200 OK
Content-Length: 42

z	proxy.com)rrr]rcrC)r�
response_textrrrr��s
�zTunnelTests.setUpcCs|j��dSr&)rcr!r%rrrr��szTunnelTests.tearDowncsd�fdd�	}|S)Ncst�|d|dd�S)Nrr)rr)r	)ror�r��r7rrrB�sz9TunnelTests._create_connection.<locals>.create_connection)NNr)rr7rBrr8rrC�szTunnelTests._create_connectioncCs�d}d}ddi}|jj|||d�|j�ddd�|�|jjj|j�|�|jjjtj�|�|jj	|�|�|jj
|�|�|jj|�dS)	N�destination.comi�"z
User-Agentz!Mozilla/5.0 (compatible, MSIE 11))rreror\rj)rc�
set_tunnelr`rar^rrr�	HTTP_PORTZ_tunnel_hostZ_tunnel_portZ_tunnel_headers)rZtunnel_hostZtunnel_portZtunnel_headersrrr�!test_set_tunnel_host_port_headers�s
�z-TunnelTests.test_set_tunnel_host_port_headerscCs |j��|�t|jjd�dS)Nr9)rcrGr��RuntimeErrorr:r%rrr�&test_disallow_set_tunnel_after_connect�s
�z2TunnelTests.test_disallow_set_tunnel_after_connectcCs�|j�d�|j�ddd�|�|jjj|j�|�|jjjtj�|�	d|jjj
�|�d|jjj
�|�	d|jjj
�|�d|jjj
�dS)	Nr9ror\rj�CONNECT destination.comsHost: destination.com:None�Host: destination.comsHost: proxy.com)rcr:r`rar^rrrr;r|rr�r%rrr�test_connect_with_tunnel�sz$TunnelTests.test_connect_with_tunnelcCs�tj�|jd��4}|j�d�|j��|j�dd�Wd�n1sJ0Y|��|jt	|j
�dd|j
��d�|j
d	dd	}|�d
|�|j|�
d�d|��d�dS)
z8Regresstion test for https://bugs.python.org/issue43332.rr9rmr\Nrz!unexpected number of send calls: )r�rr?r#zunexpected proxy data sent )rZpatch�objectrcr:rGr`Z
assert_calledr�rPZ
mock_callsr|r�r�)rZ	mock_sendZproxy_setup_data_sentrrr�0test_tunnel_connect_single_send_connection_setup�s
,

��z<TunnelTests.test_tunnel_connect_single_send_connection_setupcCsl|j�d�|j�ddd�|�|jjj|j�|�|jjjtj�|�	d|jjj
�|�	d|jjj
�dS)Nr9rkr\rjr?r@)rcr:r`rar^rrrr;r|rr%rrr�test_connect_put_requestsz$TunnelTests.test_connect_put_requestcCs�d}d�|�}|j�d�|�|�|j_|j�d�t��� }|j�ddd�Wd�n1sb0Y|���	�}|�
d�|�|�dS)	Nz
X-Dummy: 1zHTTP/1.0 200 OK
{}

rr9rkr\rjz
header: {})rtrcZset_debuglevelrCr:rr�r`r�r�r|)rZexpected_headerr7r�r�rrr�test_tunnel_debuglogs

.z TunnelTests.test_tunnel_debuglogN)r*r+r,r�r�rCr<r>rArCrDrErrrrr6�s


r6�__main__r�)�	verbosity):r2�httprrr-rr�osrr�rwr{rr�rZTestCaser&rZtest.supportr�path�dirnamer�herer�rrr�r.r-Zchunk_extensionr/rWr�r0ryr	r/r.r4r]r=rLr�r�r�r�r�r�r�r�r�r�r�rr+r6r*�mainrrrr�<module>sp�!nT}"U.HL`#Z


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