Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.23.97.32
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_httplib.cpython-310.pyc
o

`b�<�@sPddlZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlm
Z
ejZddlmZddlmZddlmZddlmZej�e�Zej�ed�Zej�ed	�Zej�ed
�ZdZdZd
ZdZ dedZ!dZ"dZ#ej$Z$Gdd�d�Z%Gdd�de%�Z&Gdd�dej'�Z(Gdd�dej)�Z*Gdd�de�Z+Gdd�de�Z,Gdd�de�Z-Gd d!�d!e�Z.Gd"d#�d#e�Z/Gd$d%�d%e/�Z0Gd&d'�d'�Z1Gd(d)�d)e�Z2Gd*d+�d+e�Z3Gd,d-�d-e�Z4Gd.d/�d/e�Z5Gd0d1�d1e�Z6Gd2d3�d3e�Z7Gd4d5�d5e�Z8Gd6d7�d7e�Z9e:d8k�r&ej;d9d:�dSdS);�N)�client�
HTTPStatus)�mock)�support)�	os_helper)�
socket_helper)�warnings_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/python-3.10/lib/python3.10/test/test_httplib.py�__init__5s


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

zFakeSocket.makefilecCs
d|_dS)NT)r�rrrrr"L�
zFakeSocket.file_closecC�dS�Nrr'rrrr#O�zFakeSocket.closecCr)r*r)r�levelZoptname�valuerrr�
setsockoptRr+zFakeSocket.setsockoptr*)�__name__�
__module__�__qualname__�io�BytesIOrrr&r"r#r.rrrrr4s
rc@�$eZdZdd�Zdd�Zdd�ZdS)�EPipeSocketcCst�||�||_dSr*)rr�pipe_trigger)rrr6rrrrWs
zEPipeSocket.__init__cCs(|j|vrttjd��|j|7_dS)NZgotcha)r6�OSError�errno�EPIPErrrrrr\s
zEPipeSocket.sendallcCr)r*rr'rrrr#ar+zEPipeSocket.closeN)r/r0r1rrr#rrrrr5Usr5c@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.
    ���cC�"tj�||�}|dkrtd��|S�Nr
zcaller tried to read past EOF)r2r3�read�AssertionError)r�nrrrrr>j�zNoEOFBytesIO.readNcCr<r=)r2r3�readliner?)r�lengthrrrrrBprAzNoEOFBytesIO.readline�r;r*)r/r0r1�__doc__r>rBrrrrr:ds
r:cs4eZdZdZ�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__rrrysz!FakeSocketHTTPConnection.__init__cs|jd7_t���S)z.Count the number of times connect() is invokedr)rHrI�connectr'rNrrrPs
z FakeSocketHTTPConnection.connectcOs
t|j�Sr*)rrJ�r�pos�kwrrrrK�r(z*FakeSocketHTTPConnection.create_connection)r/r0r1rErrPrK�
__classcell__rrrNrrFvs
rFc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�HeaderTestscCs�Gdd�dt�}dD]7}dD]2}t�d�}td�|_|�|_d}i}|r,tt|��||<|�dd	||�|�	|jj
|��d
�qq
dS)Nc@�eZdZdd�Zdd�ZdS)z;HeaderTests.test_auto_headers.<locals>.HeaderCountingBuffercSs
i|_dSr*)�countr'rrrr�r(zDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__cSsX|�d�}t|�dkr$|d�d���}|j�|d�|j|d7<t�||�dS)N�:rrr)�split�len�decode�lowerrW�
setdefault�list�append)r�item�kvZlcKeyrrrr_�s
zBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.appendN�r/r0r1rr_rrrr�HeaderCountingBuffer�src)TF)�Content-lengthZHostzAccept-encodingrGZblahblahblahZspamspamspam�POST�/r)r^r�HTTPConnectionr�sock�_bufferrrZ�request�assertEqualrWr\)rrcZexplicit_header�header�conn�body�headersrrr�test_auto_headers�s

��zHeaderTests.test_auto_headerscCsdGdd�dt�}d}d}t�||�D]%\}}t�d�}td�|_|�|_|�|d|�|�	|jj
dd�|��qd	}|D]#}t�d�}td�|_|�|_|�|dd�|�	|jj
dd
�|��q<|D]#}t�d�}td�|_|�|_|�|dd�|�	|jj
dd�|��qbt�||�D]#}t�d�}td�|_|�|_|�|dd�|�	|jj
d
d�|��q�dS)Nc@rV)z?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckercSst�|�d|_dSr*)r^r�content_lengthr'rrrr��

zHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__cSsF|�dd�}t|�dkr|d��dkr|d��|_t�||�dS)NrXrrscontent-length)rYrZr\�striprqr^r_)rr`rarrrr_�szFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.appendNrbrrrr�ContentLengthChecker�srt)N�)�PUTreZPATCHrGrf�0z%Header Content-Length incorrect on {})�GET�CONNECTZDELETE�HEADZOPTIONSZTRACEz.Header Content-Length set for empty body on {}ru� �1)
r^�	itertools�productrrgrrhrirjrkrq�format�chain)rrtZbodiesZmethods_with_body�methodrnrmZmethods_without_bodyrrr�test_content_length_0�sR

�

�

�

��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),NrGrxrfrd�*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)rrgrrh�
putrequest�	putheader�assertInri�rrmrrr�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::]:81rurx�/foosEGET /foo HTTP/1.1
Host: [2001:102A::]
Accept-Encoding: identity

z
[2001:102A::])rrgrrhrj�
assertTruer�
startswith�r�expectedrmrhrrr�test_ipv6host_header	s

z HeaderTests.test_ipv6host_headercCsFd}t|�}t�|�}|��|�|�d�d�|�|�d�d�dS)Nz4HTTP/1.1 200 OK
First: val
: nval
Second: val

ZFirst�valZSecond)rr�HTTPResponse�beginrk�	getheader�rrnrh�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]}|�|�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-Lengthr	z!#$%&'*+-.^_`|~r-ruZVCHARzobs-textzobs-foldrz folded with spacezfolded with tab)�bytes�rangerrr�r�rkr��msg�join�map�chrZassertIsNotNoner�r�r��endswith)rrnrhr�ZvcharZfoldedrrr�test_parse_all_octets&s6�����
�z!HeaderTests.test_parse_all_octetsc
Cs�t�d�}td�|_|�dd�d}|D]7\}}|�||f��$|�td��|�||�Wd�n1s7wYWd�n1sFwYqdS)NrGrurxrf))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)	rrgrrhr��subTest�assertRaisesRegex�
ValueErrorr�)rrm�cases�namer-rrr�test_invalid_headersDs

�����z HeaderTests.test_invalid_headerscCs�d}t|�}tj|dd�}t���}|��Wd�n1s wY|����}|�|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)	rrr�r�captured_stdoutr��getvalue�
splitlinesrk)rrnrhr��output�linesrrr�test_headers_debuglevelbs�

�z#HeaderTests.test_headers_debuglevelN)r/r0r1rpr�r�r�r�r�r�r�rrrrrU�sB"
rUc@�eZdZdd�ZdS)�HttpMethodTestsc	Cs`d}|D])}|�td��t�d�}td�|_|j|dd�Wd�n1s(wYqdS)N)	zGET
zPOST
zPUT

z
POST
Valuez
POST
HOST:abczGET
rHost:abc
zPOST
Remainder:
z
GET
HOST:
z
PUTz'method can't contain control charactersrGrf)r��url)r�r�rrgrrhrj)r�methodsr�rmrrr�test_invalid_method_namesus�

���z)HttpMethodTests.test_invalid_method_namesN)r/r0r1r�rrrrr�t�r�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)NrGr
rerfT)�encode_chunked)rrgrrhr�Z
endheaders�
_make_body�_parse_requestr�_parse_chunkedrk�
expected_body)rrm�_rnrrr�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)NrGr
rerf�Transfer-Encoding�chunked�content-lengthcS�g|]}|���qSr�r\��.0�krrr�
<listcomp>��z>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>�latin-1cSr�rr�r�rrrr��r�z
gzip, chunkedT)ror�rncSr�rr�r�rrrr��r�)rrgrrhrjr�r�r�assertNotIn�keysrkr�r[r��rrmr�rornrrr�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)FTrGr
rerf)�empty_linesr�r�r�cSr�rr�r�rrrr��r�z5TransferEncodingTest.test_request.<locals>.<listcomp>)rrgrrhrjr�r�rr�rkr�r�)rr�rmr�rornrrr�test_request�s

�
�z!TransferEncodingTest.test_requestcCslt�d�}td�|_|�ddd�|�|jj�\}}}|�|dd�|�dd	d
�|D��|�|d�dS)NrGr
rerfrr�r�r�cSr�rr�r�rrrr��r�z8TransferEncodingTest.test_empty_body.<locals>.<listcomp>s0

)	rrgrrhrjr�rrkr�r�rrr�test_empty_body�s

z$TransferEncodingTest.test_empty_bodyFccsX�|j�d�}t|�D]\}}|r|drdV|t|�dkr&|dVq|VqdS)N� r�r
r)r�rY�	enumeraterZ)rr�r��idx�linerrrr��s��zTransferEncodingTest._make_bodycCs�|�d�}|d}i}d}|t|�krFt||�dkrF||�d�\}}|�d���}|�d���||<|d7}|t|�krFt||�dks||d�||dd��fS)N�
rrrXr�)rYrZr[rsr�)rrr�rjror@�keyr�rrrr��s
�z#TransferEncodingTest._parse_requestcCs�g}i}d}|�d�}	|||d�\}}t|d�}|dkr$|d7}q=|�|t|��|�|�|d7}|t|�kr<q=qd�|�S)Nrr�Tr��rr
)rY�intrkrZr_r�)rrrn�trailersr@r��size�chunkrrrr��s"


�
z#TransferEncodingTest._parse_chunkedN)F)r/r0r1r�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`�Z2dadb�Z3dcdd�Z4deS)f�	BasicTestcCs"|�hd�tttd���k�dS)N>�phraser�r-�description�)r��set�dirrr'rrr�&test_dir_with_added_behavior_on_statuss"z0BasicTest.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

Textrr
�TextzHTTP/1.1 400.100 Not Ok

Text)
rrr�r�rkr>�assertFalse�isclosed�closedr�r#�assertRaises�
BadStatusLiner�rrr�test_status_liness 

zBasicTest.test_status_linescCst�d�}|�t|�d�dS)NruzBadStatusLine("''"))rr�rk�repr)r�excrrr�test_bad_status_repr$s
zBasicTest.test_bad_status_reprcCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS�N�*HTTP/1.1 200 Ok
Content-Length: 4

Textr��Te�xt�rrr�r�rkr>r�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)rrr�r�rkrBr�r�r>r�r�r#r�rrr�test_mixed_reads7s
zBasicTest.test_mixed_readscCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�
|�	��|�|j�|��|�
|j�dSr��
rrr�r��	bytearray�readintorkr�r�r�r�r�r#�rrnrhr��br@rrr�test_partial_readintosFs 


z BasicTest.test_partial_readintoscCsbd}t|�}t�|�}|��|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS)Nr��
r��rrr�r�rkr>r�r�r�r�r#r�rrr�test_partial_reads_past_endZs
z%BasicTest.test_partial_reads_past_endcCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�dd�d�|�|�	��|�
|j�|��|�|j�dS)Nr�r��r�)
rrr�r�r�r�rkr�r�r�r�r�r#r�rrr�test_partial_readintos_past_endfs

z)BasicTest.test_partial_readintos_past_endcCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS)Nr�r�r�r�rr
r�r�rrr�$test_partial_reads_no_content_lengthus
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)rrr�r�r�r�rkr�r�r�r�r�rrr�(test_partial_readintos_no_content_length�s



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
)	rrr�r�rkr>r�r�r�r�rrr�"test_partial_reads_incomplete_body�s
z,BasicTest.test_partial_reads_incomplete_bodycCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�|�}|�|d�|�
|�	��|�|j�|��|�
|j�dS)Nrr�r�r�rr�r�rrr�&test_partial_readintos_incomplete_body�s$



z0BasicTest.test_partial_readintos_incomplete_bodycC�VdD]}|�tjtj|�qdD]\}}}t�|�}|�||j�|�||j�qdS)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]rr
)�[fe80::207:e9ff:fe9b]:rr
)r�r�
InvalidURLrgrkrr�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)rrr�r�r�rk)rrZhdr�srZcookiesrrr�test_response_headers�s

zBasicTest.test_response_headerscCs:tdt�}tj|dd�}|��|��r|�d�dSdS)N�*HTTP/1.1 200 OK
Content-Length: 14432

rz�r��)Did not expect response from HEAD request)rr:rr�r�r>�fail�rrhr�rrr�test_read_head�s��zBasicTest.test_read_headcCsTtdt�}tj|dd�}|��td�}|�|�dkr |�d�|�t	|�d�dS)Nrrzr�rr�)
rr:rr�r�r�r�rrkr�)rrhr�r�rrr�test_readinto_head�s�
zBasicTest.test_readinto_headcCsRd�dd�ttjd�D��d}d|}t|�}t�|�}|�tjd|j�dS)Nr
css�|]}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_MAXHEADERSrr�r��
HTTPExceptionr�)rrorrrrrr�test_too_many_headers�s
��
�zBasicTest.test_too_many_headersc	Cs�d}ttd��1}t�d�}t|�}||_|�dd|�|�|j�	|�d|jdt
|��|f�Wd�dS1s;wYdS)Ns_GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

r rGrxr�z%r != %r)�open�__file__rrgrrhrjr�rr�rZ�rr�rnrmrhrrr�test_send_files
�"�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 testrGr
r�)
rrgrrh�sendrkr�arrayr2r3r�rrr�	test_sends

zBasicTest.test_sendcsXdd��G�fdd�dtj�}d}t�d�}td�}||_|�|��|�|j|�dS)Ncss�dVdVdVdS)NrZdata_tworrrrrr ��
z/BasicTest.test_send_updating_file.<locals>.datacs eZdZdZ��Zddd�ZdS)z7BasicTest.test_send_updating_file.<locals>.UpdatingFilerr;cSs
t|j�Sr*)�next�d)r�	blocksizerrrr>(r(z<BasicTest.test_send_updating_file.<locals>.UpdatingFile.readNrD)r/r0r1r$r/r>r�rrr�UpdatingFile%sr2sdatarGru)	r2�
TextIOBaserrgrrhr*rkr)rr2r�rmrhrr1r�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

onetwothreecss�dVdVdVdS)Nsonestwosthreerrrrrrn9r-z&BasicTest.test_send_iter.<locals>.bodyrGrurxr�r�Z11)rrgrrhrjrkrr(rrr�test_send_iter4s
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.�rG�r0N�a�brvrfr��9r��

r)rrgrrhrjr2r3rkrrrY)rr0rmrhr�rnrrr�test_blocksize_requestDsz BasicTest.test_blocksize_requestcCs\d}tjd|d�}td�}||_d|d}|�t�|��|�|jd�|�|j	|�dS)z5Check that send() respects the configured block size.r6rGr7Nr8r9r�)
rrgrrhr*r2r3rkrr)rr0rmrhr�rrr�test_blocksize_sendPszBasicTest.test_blocksize_sendcCsRt�d�}td�|_|�t��|�dd|�Wd�dS1s"wYdS)NrGrure�test)rrgrrhr��	TypeErrorrjr�rrr�test_send_type_error[s


"�zBasicTest.test_send_type_errorcCsbt}tttt�}tj|dd�}|��|�|�	�|�|�
�tdd�D]+}tttt�}tj|dd�}|��|�|�	|�|�	|�|�	�|�|�
�q&dD]Z}tt|�}tj|dd�}|��zBz|�	�Wn0tjy�}z#|�|j
|�dt|�}|�t|�|�|�t|�|�WYd}~n
d}~ww|�d�W|�
�qT|�
�wdS)Nrxrr��ruzfoo
�IncompleteRead(%d bytes read)�IncompleteRead expected)�chunked_expectedr�
chunked_start�
last_chunk�chunked_endrr�r�rkr>r#r��IncompleteRead�partialrZr�rr)rr�rhr�r@�xr"�expected_messagerrr�test_chunkedbs:$
��
��zBasicTest.test_chunkedcCs�t}t|�}td�}tttt�}tj|dd�}|�	�|�
|�}|�|d|�|�|�||�|��t
dd�D]N}tttt�}tj|dd�}|�	�t|�}|�
|d|��}||�
||||��7}||�
||d��7}|�|d|�|�|�||�|��q;dD][}	tt|	�}tj|dd�}|�	�zCz|�
|�}Wn0tjy�}z#|�|j|�dt|�}
|�t|�|
�|�t|�|
�WYd}~n
d}~ww|�d	�W|��q�|��wdS)
Nr�rxrrrArrBrCrD)rErZr�rrFrGrHrr�r�r�rkr#r��
memoryviewrIrJr�rr)rr�Z	nexpectedr�rhr�r@�mr"rKrLrrr�test_readinto_chunked�sL

��
��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
rzrr
���OK)rrGrHrr�r�rkr>�status�reasonr�r�r�r�r#)rrFrhr�rrr�test_chunked_head�s�zBasicTest.test_chunked_headcCs�d}t|tt�}tj|dd�}|��td�}|�|�}|�|d�|�t	|�d�|�|j
d�|�|jd�|�|�
��|�|j�|��|�|j�dS)	NrQrzrrrr rRrS)rrGrHrr�r�r�r�rkr�rTrUr�r�r�r�r#)rrFrhr�r�r@rrr�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
rxr�Hello
)rrr�r�rkr>r�r�rrrr�test_negative_content_length�s�z&BasicTest.test_negative_content_lengthc
Cs�td�}tj|dd�}|��z|��Wn2tjyG}z%|�|jd�|�t|�d�|�t	|�d�|�
|���WYd}~dSd}~ww|�d�dS)Nz.HTTP/1.1 200 OK
Content-Length: 10

Hello
rxrrXz-IncompleteRead(7 bytes read, 3 more expected)rD)
rrr�r�r>rIrkrJr�rr�r�r)rrhr�r"rrr�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-LengthrGcs��ddd�S)Nrv�/urlrn)rjr�rmrr�<lambda>�sz&BasicTest.test_epipe.<locals>.<lambda>i�zBasic realm="example"zwww-authenticate)
r5rrgrhr�r7�getresponserkrTr�rrr\r�
test_epipe�s�

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

)rr�rr�rbr�rcrrr�test_overflowing_header_lines���z&BasicTest.test_overflowing_header_linecCsrdd}t�t|��}|�tj��}|��Wd�n1s wY|�dt|j��|�dt|j��dS)NzHTTP/1.1 100 OK
r
i�zgot more than ro)	rr�rr�r$r�r�r�	exception)rrnr��cmrrr�'test_overflowing_header_limit_after_100s��
�z1BasicTest.test_overflowing_header_limit_after_100cCs:dddd}t�t|��}|��|�tj|j�dS)Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

r	raza
hello world
0

)rr�rr�r�rbr>rcrrr�test_overflowing_chunked_lines���z'BasicTest.test_overflowing_chunked_linecCs`d}t|�}t�|�}|��|�|��d�|�|���|�|j	�|�
�|�|j	�dS)Nr`r
r�r�rrr�test_early_eof(s
zBasicTest.test_early_eofcsnt�d�}d�G�fdd�dtj�}||_td�|_|�dd�|�tj|j	�|�
�j�|�
|jj�dS)NrGcseZdZ�fdd�ZdS)z+BasicTest.test_error_leak.<locals>.Responsecs"|�tjj|g|�Ri|��dSr*)rr�rrQ��responserrr9sz4BasicTest.test_error_leak.<locals>.Response.__init__N)r/r0r1rrrkrr�Response8srmzInvalid status linerxrf)
rrgr�Zresponse_classrrhrjr�r�r^r�r�r)rrmrmrrkr�test_error_leak4s

zBasicTest.test_error_leakcCsRd}td}tt|tt�}tj|dd�}|��|�|�	�|�|�
�dS)Nz3;foo=bar
abc
sabcrxr)rErrF�last_chunk_extendedrHrr�r�rkr>r#)r�extrar�rhr�rrr�test_chunked_extensionDsz BasicTest.test_chunked_extensioncCsBt}ttt�}tj|dd�}|��|�|��|�|�	�dS)z9some servers may serve up a short chunked encoding streamrxrN)
rErrFrGrr�r�rkr>r#�rr�rhr�rrr�test_chunked_missing_endNsz"BasicTest.test_chunked_missing_endcCs\t}ttttt�}tj|dd�}|��|�	|�
�|�|�	|j�
�d�|��dS)z&See that trailers are read and ignoredrxrr
N)
rErrFrGr�rHrr�r�rkr>r!r#rrrrr�test_chunked_trailersWszBasicTest.test_chunked_trailerscCsjt}d}ttttt|�}tj|dd�}|��|�	|�
�|�|�	|j�
�|�d��|�
�dS)zDCheck that we don't read past the end of the chunked-encoding stream�	extradatarxrrN)rErrFrGr�rHrr�r�rkr>r!rr#)rr�rurhr�rrr�test_chunked_syncbszBasicTest.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

rxrN)rrr�r�rkr>r!r#�rrur�rhr�rrr�test_content_length_syncnsz"BasicTest.test_content_length_synccCs`d}d}td||�}tj|dd�}|��|�|�d�|g�|�|j��|�|��dS�Nrwrxryrxri�)	rrr�r�rk�	readlinesr!r>r#rzrrr�test_readlines_content_lengthzsz'BasicTest.test_readlines_content_lengthcCs^d}d}td||�}tj|dd�}|��|�|�d�|�|�|j��|�|��dSr|)	rrr�r�rk�read1r!r>r#rzrrr�test_read1_content_length�sz#BasicTest.test_read1_content_lengthcCspd}d}td||�}tj|dd�}|��|�|�d�|�|�|�d�d�|�|j��|�|��dS)Nrwrxryrxrr�r
)	rrr�r�rkrBr!r>r#rzrrr�"test_readline_bound_content_length�sz,BasicTest.test_readline_bound_content_lengthcCsvd}d}td|d|�}tj|dd�}|��|�|�d�|d�|�|��|�|�|j��|�|��dS)	Nrwrxs'HTTP/1.1 200 OK
Content-Length: 30

r�rxr�r�)	rrr�r�rkrr>r!r#rzrrr�test_read1_bound_content_length�sz)BasicTest.test_read1_bound_content_lengthcs�t�tdf��|��j�d���fdd�}tj|d�}|��|�|jt	d��t
j����}|�
dd�|��}z+|�|jt
j�tj|��d�}z|�d	�W|��n|��wW|��|��n	|��|��w|��|��d	�dS)
Nrc	s����\}}|�;|�d��}	|��}|�d�sqq|�d�|���Wd�n1s.wYWd�dSWd�dS1sFwYdS)Nr Tr�s'HTTP/1.1 200 Connection established

)�acceptr&rB�rstriprr>)rm�address�readerr���result�servrr�
run_server�s
�

P�z2BasicTest.test_response_fileno.<locals>.run_server)�targetrryz
dummy:1234)�filenos
proxied data
)�socket�
create_server�HOST�
addCleanupr#�	threading�Thread�startr��floatrrg�getsocknamerjr^rkrTrSr�r�detach)rr��threadrmrlrrr�r�test_response_fileno�s,
�
zBasicTest.test_response_filenocC�4Gdd�dtj�}|d�}td�|_|�dd�dS)zv
        It should be possible to override the default validation
        behavior in putrequest (bpo-38216).
        c@r�)zRBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnectioncSr)r*r�rr�rrr�_validate_path�r+zaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_pathN)r/r0r1r�rrrr�UnsafeHTTPConnection�r�r�rGrurxz/N�rrgrrhr��rr�rmrrr�*test_putrequest_override_domain_validation�s
z4BasicTest.test_putrequest_override_domain_validationcCs8Gdd�dtj�}|d�}td�|_|jdddd�dS)	Nc@r�)zPBasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnectioncSr)r*rr�rrr�_validate_host�r+z_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_hostN)r/r0r1r�rrrrr��r�r�z
example.com
rurxrfr)Z	skip_hostr�r�rrr�(test_putrequest_override_host_validation�s
z2BasicTest.test_putrequest_override_host_validationcCr�)z�
        It should be possible to override the default encoding
        to transmit bytes in another encoding even if invalid
        (bpo-36274).
        c@r�)zIBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnectioncSs
|�d�S)N�utf-8)r)rZstr_urlrrr�_encode_request�r(zYBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnection._encode_requestN)r/r0r1r�rrrrr��r�r�rGrurxu/☃Nr�r�rrr�!test_putrequest_override_encoding�s
z+BasicTest.test_putrequest_override_encodingN)5r/r0r1r�r�r�r�r�r�rrrrrrrrrr!r%r)r,r4r5r<r=r@rMrPrVrWrYrZr_rdrerhrirjrnrqrsrtrvr{r~r�r�r�r�r�r�r�rrrrr�
sf

	 +


	%
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)Nrxr)	rr�rr�r�r2�BufferedReader�fpr�rrrr�setUps


zExtendedReadTest.setUpcs�|j}|jj�d�fdd�	}||j_g}	|�d�}|rH|�t|�d�|��}|�t|�t|��|�|�|��|�t|��}|�	||�n	|��}|�
|�|�|�|sYqZq|�	d�|�|j
�dS)	Nr;cs(�|�}|dkr|d|�S|dd�S)Nrr�r)r@r�Zoldpeekrr�mypeeksz*ExtendedReadTest.test_peek.<locals>.mypeekTr�rr
rD)r�r��peek�
assertGreaterrZZassertGreaterEqualr�r�r>rkr�r_r��lines_expected)rr�r��allrZp2r.rr�r�	test_peeks*


�zExtendedReadTest.test_peekcCs|j}|�|jj|j�dSr*)r��_verify_readlinerBr�)rr�rrr�
test_readline:szExtendedReadTest.test_readlinecCs^g}	|d�}|r|dkrt|�dkr|�|�d��|�|�|s#q$q|�d�|�|�dS)NTr�foo�
r
)rZr�r�r_rkr�)rrBr�r�r�rrrr�>s
�	z!ExtendedReadTest._verify_readlinecs0�j���fdd�}t|�}��|j�j�dS)Ncs��d�}��t|�d�|S)Nr)r�assertLessEqualrZ)�res�r�rrrrMs
z&ExtendedReadTest.test_read1.<locals>.r)r��	Readlinerr�rBr�)rrZ	readlinerrr�r�
test_read1KszExtendedReadTest.test_read1cCs>|j}g}	|��}|s
q|�|�q|�d�|�|j�dS)NTr
)r�rr_rkr�r��rr�r�rrrr�test_read1_unboundedTs
�z%ExtendedReadTest.test_read1_unboundedcCsP|j}g}	|�d�}|sq|�t|�d�|�|�q|�d�|�|j�dS)NTr�r
)r�rr�rZr_rkr�r�r�rrr�test_read1_bounded^s

�z#ExtendedReadTest.test_read1_boundedcCs|�|j�d�d�dS)Nrr
)rkr�rr'rrr�test_read1_0i�zExtendedReadTest.test_read1_0cCs |j�d�}|�dt|��dS�Nr)r�r�r�rZ)rrrrr�test_peek_0lszExtendedReadTest.test_peek_0)r/r0r1rEr��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/r0r1rEr�rrrrr�qs�r�c@s eZdZdZdd�Zdd�ZdS)r�zT
    a simple readline class that uses an arbitrary read function and buffering
    cCs||_d|_dS)Nr
)�readfunc�	remainder)rr�rrrr�s
zReadliner.__init__cCs�g}d}|j}zB	|�d�}|dkrq0|t|�|kr!||d}|�|�|��}|s/d}q0q	|d7}|�|d|��||d�|_d�|�WSd�|�|_�)NrTr�r;rr
)r�r�rZr_r�r�)r�limitrZdatalenr>r�rrrrB�s.

�zReadliner.readlineN)r/r0r1rErrBrrrrr��sr�c@r4)�OfflineTestcCsfdh}ddh}tt�D]}|�d�s||vrqtt|�}t|dd�dkr)|�|�q|�tj|�dS)N�	responsesZHTTPMessage�
parse_headersr�r0zhttp.client)r�rr��getattr�addZassertCountEqual�__all__)rr�Zdenylistr�Z
module_objectrrr�test_all�s

�zOfflineTest.test_allcCs|�tjtjd�dS)Nz	Not Found)rkrr��	NOT_FOUNDr'rrr�test_responses�r�zOfflineTest.test_responsesc	CsRgd�}|D] }|j|d��|�tt|��Wd�n1s!wYqdS)N):ZCONTINUEZSWITCHING_PROTOCOLSZ
PROCESSINGrSZCREATEDZACCEPTEDZNON_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/r0r1r�r�r�rrrrr��sr�c@s@eZdZdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
dS)�SourceAddressTestcCs>t�tjtj�|_t�|j�|_t��|_|j�	�d|_
dSr*)r��AF_INET�SOCK_STREAMr�r�	bind_portrZfind_unused_port�source_port�listenrmr'rrrr��s



zSourceAddressTest.setUpcCs*|jr|j��d|_|j��d|_dSr*)rmr#r�r'rrr�tearDowns



zSourceAddressTest.tearDowncCsBtjt|jd|jfd�|_|j��|�|jj�	�d|j�dS)Nru��source_addressr)
rrgr�rr�rmrPrkrhr�r'rrr�testHTTPConnectionSourceAddress
s

�
z1SourceAddressTest.testHTTPConnectionSourceAddress�HTTPSConnectionz'http.client.HTTPSConnection not definedcCstjt|jd|jfd�|_dS)Nrur�)rr�r�rr�rmr'rrr� testHTTPSConnectionSourceAddresss
�z2SourceAddressTest.testHTTPSConnectionSourceAddressN)r/r0r1r�r�r��unittest�skipIfr�rr�rrrrr��s�r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)�TimeoutTestNcCs.t�tjtj�|_t�|j�t_|j��dSr*)	r�r�r�r�rr�r��PORTr�r'rrrr� szTimeoutTest.setUpcCs|j��d|_dSr*)r�r#r'rrrr�%rrzTimeoutTest.tearDownc	Cs|�t���t�d�zt�ttj�}|�	�Wt�d�nt�d�w|�
|j��d�|�
�|�t���t�d�ztjttjdd�}|�	�Wt�d�nt�d�w|�
|j��d�|�
�tjttjdd�}|�	�|�
|j��d�|�
�dS�N�)�timeout)�assertIsNoner��getdefaulttimeout�setdefaulttimeoutrrgr�r�r�rPrkrh�
gettimeoutr#)rZhttpConnrrr�testTimeoutAttribute)s,



�
z TimeoutTest.testTimeoutAttribute)r/r0r1r�r�r�r�rrrrr�s
r�c@r4)�PersistenceTestc
Cs�d}|D]v\}}}|j||d��bd�||�}t|�}|�|j�|�dd�|���}|�|jdu|�|��Wd�n1sDwY|�|jdu|�|�|j	d�|�dd�|�|j	|rhdnd�Wd�n1suwYqdS)	N))�1.0ruF)r�zConnection: keep-alive
T)�1.1ruT)r�zConnection: close
F)r�zConnection: keep-ALIVE
T)r�zConnection: cloSE
F)�versionrlz4HTTP/{} 200 OK
{}Content-Length: 12

Dummy body
rxz/open-connectionrz/subsequent-requestr�)
r�rrFr�rhrjr^rkr>rH)r�testsr�rlZreuser�rmrlrrr�test_reuse_reconnectMs(�

����z$PersistenceTest.test_reuse_reconnectc	Cs�dd�}tjtjf|tff}|D]?\}}|j|d��-td|�}|�dd�|�||j	�|�
|j�|�dd�|�|j
d�Wd�n1sJwYqdS)	Ncs&t�|���fdd�}|�_t���S)z3Return BufferedReader that raises ECONNRESET at EOFcs tj��|�}|dkrt��|Sr�)r2r3r��ConnectionResetError)�bufferr���streamrrr�pszNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readinto)r2r3r�r�)rr�rr�r�make_reset_readerms

z<PersistenceTest.test_disconnected.<locals>.make_reset_reader)rfr
rxz
/eof-response�
/reconnectr�)r2r3r�RemoteDisconnectedr�r�rFrjr�r^r�rhrkrH)rr�r�Zstream_factoryrfrmrrr�test_disconnectedks
�
���z!PersistenceTest.test_disconnectedcCsVtd�}|jddddid�|�tj|j�|�|j�|�dd�|�|j	d�dS)	NsHTTP/1.1 100 Continue

rxrfZExpectz100-continue)ror�r�)
rFrjr�rr�r^r�rhrkrHr�rrr�test_100_close�s�zPersistenceTest.test_100_closeN)r/r0r1r�r�r�rrrrr�Ksr�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�dSdS)Nr�zssl support required)r�r�skipTestr'rrrr��s
�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�r�r�r�rkr�)rrrrr�test_attributes�szHTTPSTest.test_attributesc	Cs�ddl}t�d�t�d��3t�dd�}|�|j��}|�	dd�Wd�n1s,wY|�
|jjd�Wd�dS1sDwYdS)Nr�network�self-signed.pythontest.net�rxrf�CERTIFICATE_VERIFY_FAILED)
�sslr�requiresr�transient_internetrr�r��SSLErrorrjrkrfrU)rrr�exc_inforrr�test_networked�s
�"�zHTTPSTest.test_networkedcCs�ddl}t�d�t�d��0|��}tjdd|d�}|�dd�|�	�}|�
�|�d|�d	��|�
�Wd�dS1sAwYdS)
Nrrrr��contextrxrf�nginx�server)
rrrrrZ_create_unverified_contextrr�rjr^r#r�r�)rrrrr�rrr�test_networked_noverification�s
�
"�z'HTTPSTest.test_networked_noverificationcCs�t�d�t�d��,t�dd�}|�dd�|��}|�d�}|�	�|�	�|�
d|�Wd�dS1s9wYdS)Nrrrrxrfzcontent-typez	text/html)rrrrrr�rjr^r�r#r�)rrr�Zcontent_typerrr�&test_networked_trusted_by_default_cert�s

"�z0HTTPSTest.test_networked_trusted_by_default_certc	Csddl}t�d�d}t�|��o|�|j�}|�|j|j	�|�|j
d�|�t�zt
j|d|d�}|�dd�|��}Wn$|jyc}zt|�}t�d	|�r^t�d
|�d|�d����d}~ww|�d
�}|��|��|�d|�Wd�dS1s�wYdS)NrrrTrr
rxrfz(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.r
r)rrrrr�
SSLContext�PROTOCOL_TLS_CLIENTrkZverify_modeZ
CERT_REQUIRED�check_hostname�load_verify_locations� CERT_selfsigned_pythontestdotnetrr�rjr^rr�re�searchr�ZSkipTestr�r#r�)	rrZselfsigned_pythontestdotnetrrr�Zssl_errZssl_err_strZ
server_stringrrr�test_networked_good_cert�s<

�����

"�z"HTTPSTest.test_networked_good_certc	Cs�ddl}t�d�t�d��@|�|j�}|�t�t	j
dd|d�}|�|j��}|�
dd�Wd�n1s9wY|�|jjd�Wd�dS1sQwYdS)	Nrrrrr
rxrfr)rrrrrrrr�CERT_localhostrr�r�rrjrkrfrU)rrrrrrrr�test_networked_bad_cert�s

�"�z!HTTPSTest.test_networked_bad_certcCslddl}|�t�}t�d|j�}|�|j��}|�dd�Wd�n1s'wY|�	|j
jd�dS)Nr�	localhostrxrfr)rr�rrr�rr�rrjrkrfrU)rrr
rrrrr�test_local_unknown_cert�s
�z!HTTPSTest.test_local_unknown_certcCsxddl}|�t�}|�|j�}|�t�tjd|j|d�}|�	|j
�|�dd�|��}|�	|j
�|�
|jd�dS)Nrrr
rx�/nonexistentr�)rr�rrrrrr�rr�r#rjr^rkrT�rrr
rrr�rrr�test_local_good_hostname�s

z"HTTPSTest.test_local_good_hostnamecCs2ddl}|�t�}|�|j�}|�t�tjd|j|d�}|�	|j
��|�dd�Wd�n1s4wYt�
dtf��tjd|j|dd�}Wd�n1sUwY|�	|j
��|�dd�Wd�n1sqwYd	|_t�
dtf��tjd|j|d	d�}Wd�n1s�wY|�dd
�|��}|��|��|�|jd�d	|_tjd|j|d�}|�dd
�|��}|�|jd�|��|��t�
dtf��tjd|j|dd�}Wd�n1s�wY|�	|j
��|�dd�Wd�dS1�swYdS)Nrrr
rxrfruT)rrFrr�)rr��CERT_fakehostnamerrrrr�rr�ZCertificateErrorrjrZcheck_warnings�DeprecationWarningrr^r#rkrTrrrr�test_local_bad_hostname
sT

�
���
��
��$�z!HTTPSTest.test_local_bad_hostnamer�z)http.client.HTTPSConnection not availablecCr)Nr	)r
)zwww.python.org:443rr)rrr)rrr)rrr)rrr)r�rrr�rkrrrrrrr4s
�zHTTPSTest.test_host_portcCs�ddl}|js|�d�t�dd�}|�|jj�|�|j	�}|�
|j�tjdd|d�}|�|j|�|�
|jj�t�
��t�ddt�tjdd|td�}Wd�n1sZwY|�|jj�dS)	NrzTLS 1.3 support requiredrrr
�ignorez5key_file, cert_file and check_hostname are deprecated)rZ	cert_file)rZHAS_TLSv1_3r�rr�r�Z_contextZpost_handshake_authrrr�ZassertIs�warnings�catch_warnings�filterwarningsr r)rrrrrrr�test_tls13_phaHs&

�
��zHTTPSTest.test_tls13_phaN)r/r0r1r�r�r�r	rrZsystem_must_validate_certrrrrrr!r�r�r�rrr&rrrrr��s$

!	
*�
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)NrGru)rrgrmrrhr'rrrr�aszRequestBodyTest.setUpcCs(t�|jj�}|��t�|�}||fSr*)r2r3rhrrBrr��r�f�messagerrr�get_headers_and_fpfs
z"RequestBodyTest.get_headers_and_fpc	Cs�ddgdfdf}|D]S\}}|�|��Bt�d�|_td�|j_|_|j�dd|�|��\}}|�d	|�|�d
|�|�	|�
d�d�|�	||���Wd�n1sXwYq
dS)
Nr��bar�3
foo
3
bar
0

))r�r,r-rGrurvr[zContent-Typer�r�r�)r�rrgrmrrhrjr+r�rk�getr>)rr�rnr�r�r)rrr�test_list_bodyls 
����zRequestBodyTest.test_list_bodycCsL|j�dddddi�|��\}}|�d|�d��|�dt|����dS)Nrvr[rnr�Z42r�r)rmrjr+rkr.rZr>�rr*r)rrr�test_manual_content_length�s�z*RequestBodyTest.test_manual_content_lengthcC�`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)Nrvr[rn�
text/plain�4r�sbody�	rmrjr+rk�get_content_typer��get_charsetr.r>r0rrr�test_ascii_body��zRequestBodyTest.test_ascii_bodycCr2)Nrvr[ubodyÁr3�5r��body�r5r0rrr�test_latin1_body�r9z RequestBodyTest.test_latin1_bodycCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)Nrvr[r;r3r:r�r5r0rrr�test_bytes_body�r9zRequestBodyTest.test_bytes_bodycCs�|�tjtj�ttjddd��
}|�d�Wd�n1s wYttjdd��?}|j�dd|�|��\}}|�	d|�
��|�|���|�|�
d��|�	d	|�
d
��|�	d|���Wd�dS1snwYdS)N�wr�)�encodingrnrvr[r3r�r�ztransfer-encodings4
body
0

)r�r�unlink�TESTFNr&�writermrjr+rkr6r�r7r.r>r(rrr�test_text_file_body�s�"�z#RequestBodyTest.test_text_file_bodycCs�|�tjtj�ttjd��
}|�d�Wd�n1swYttjd��=}|j�dd|�|��\}}|�	d|�
��|�|���|�	d|�
d��|�d	|�|�	d
|���Wd�dS1siwYdS)N�wbr;r rvr[r3r�r�r�s5
body�
0

)r�rr@rAr&rBrmrjr+rkr6r�r7r.r�r>r(rrr�test_binary_file_body�s�"�z%RequestBodyTest.test_binary_file_bodyN)
r/r0r1rEr�r+r/r1r8r<r=rCrErrrrr'^s	r'c@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)rrr�r�r�)rrnrhrrrr��szHTTPResponseTest.setUpcCs6|j�d�}|�|d�|j�dd�}|�|d�dS)Nz	My-Headerzfirst-value, second-valuezsome default�r�r�rk�rrlrrr�test_getting_header�sz$HTTPResponseTest.test_getting_headercCs|j�dd�}|�|d�dS)N�No-Such-Headerz
default-valuerGrHrrr�3test_getting_nonexistent_header_with_string_default�szDHTTPResponseTest.test_getting_nonexistent_header_with_string_defaultcCs<|j�dddg�}|�|d�|j�dd�}|�|d�dS)NrJ�default�valueszdefault, values)rLrMrGrHrrr�5test_getting_nonexistent_header_with_iterable_default�szFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_defaultcCs|j�d�}|�|d�dS)NrJrGrHrrr�/test_getting_nonexistent_header_without_default�sz@HTTPResponseTest.test_getting_nonexistent_header_without_defaultcCs |jjddd�}|�|d�dS)NrJr�)rLrGrHrrr�test_getting_header_defaultint�sz/HTTPResponseTest.test_getting_header_defaultintN)	r/r0r1r�rIrKrNrOrPrrrrrF�srFc@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)rrrgrmrL)r�
response_textrrrr��s
�zTunnelTests.setUpcCs|j��dSr*)rmr#r'rrrr��szTunnelTests.tearDowncsd�fdd�	}|S)Ncst�|d|dd�S)Nrr)rr)r)r�r�r��rRrrrK�sz9TunnelTests._create_connection.<locals>.create_connection)NNr)rrRrKrrSrrL�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))rrorzrfru)rm�
set_tunnelrjrkrhrrr�	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)NrT)rmrPr��RuntimeErrorrUr'rrr�&test_disallow_set_tunnel_after_connects
�z2TunnelTests.test_disallow_set_tunnel_after_connectcCs�|j�d�|j�ddd�|�|jjj|j�|�|jjjtj�|�	d|jjj
�|�d|jjj
�|�	d|jjj
�|�d|jjj
�dS)	NrTrzrfru�CONNECT destination.comsHost: destination.com:None�Host: destination.comsHost: proxy.com)rmrUrjrkrhrrrrVr�rr�r'rrr�test_connect_with_tunnelsz$TunnelTests.test_connect_with_tunnelcCs�tj�|jd��}|j�d�|j��|j�dd�Wd�n1s%wY|��|jt	|j
�dd|j
��d�|j
d	dd	}|�d
|�|j|�
d�d|��d�dS)
z8Regresstion test for https://bugs.python.org/issue43332.r*rTrxrfNrz!unexpected number of send calls: )r�rrZr;zunexpected proxy data sent )rZpatch�objectrmrUrPrjZ
assert_calledr�rZZ
mock_callsr�r�r�)rZ	mock_sendZproxy_setup_data_sentrrr�0test_tunnel_connect_single_send_connection_setups 
�

�
�z<TunnelTests.test_tunnel_connect_single_send_connection_setupcCsl|j�d�|j�ddd�|�|jjj|j�|�|jjjtj�|�	d|jjj
�|�	d|jjj
�dS)NrTrvrfrurZr[)rmrUrjrkrhrrrrVr�rr'rrr�test_connect_put_request%sz$TunnelTests.test_connect_put_requestcCs�d}d�|�}|j�d�|�|�|j_|j�d�t���}|j�ddd�Wd�n1s1wY|���	�}|�
d�|�|�dS)	Nz
X-Dummy: 1zHTTP/1.0 200 OK
{}

rrTrvrfruz
header: {})rrmZset_debuglevelrLrUrr�rjr�r�r�)rZexpected_headerrRr�r�rrr�test_tunnel_debuglog-s

�z TunnelTests.test_tunnel_debuglogN)r/r0r1r�r�rLrWrYr\r^r_r`rrrrrQ�s


rQ�__main__r�)�	verbosity)<r8�httprrr2r}�osr+rr�r�r#r�rZTestCaser>rZtest.supportrrr�path�dirnamer'�herer�rrrrFrEZchunk_extensionrGror�rHr�rr5r3r:rgrFrUr�r�r�r�r�r�r�r�r�r�r�r'rFrQr/�mainrrrr�<module>sx�!no}"U.HL`#
Z�
© 2025 GrazzMean