HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_httplib.cpython-37.opt-1.pyc
B

��g�2�@sddlZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
e
jZddlm
Z
ej�e�Zej�ed�Zej�ed�Zej�ed�ZdZdZd	Zd
ZdedZd
ZdZe
jZGdd�d�ZGdd�de�ZGdd�dej �Z!Gdd�dej"�Z#Gdd�de�Z$Gdd�de�Z%Gdd�de�Z&Gdd�de�Z'Gdd�de�Z(Gd d!�d!e(�Z)Gd"d#�d#�Z*Gd$d%�d%e�Z+Gd&d'�d'e�Z,Gd(d)�d)e�Z-Gd*d+�d+e�Z.Gd,d-�d-e�Z/Gd.d/�d/e�Z0Gd0d1�d1e�Z1Gd2d3�d3e�Z2e3d4k�re
j4d5d6�dS)7�N)�client)�supportzkeycert.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
�0z
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)�selfrrrr�r�-/usr/local/lib/python3.7/test/test_httplib.py�__init__/s

zFakeSocket.__init__cCs |jd7_|j|7_dS)N�)rr
)rr
rrr�sendall:szFakeSocket.sendallcCs6|dkr|dkrt���|�|j�|_|j|j_|jS)N�r�rb)rZUnimplementedFileModerr�file�
file_close�close)r�mode�bufsizerrr�makefile>s

zFakeSocket.makefilecCs
d|_dS)NT)r)rrrrrFszFakeSocket.file_closecCsdS)Nr)rrrrrIszFakeSocket.closecCsdS)Nr)r�levelZoptname�valuerrr�
setsockoptLszFakeSocket.setsockopt)N)�__name__�
__module__�__qualname__�io�BytesIOrrrrrr"rrrrr.s
rc@s$eZdZdd�Zdd�Zdd�ZdS)�EPipeSocketcCst�||�||_dS)N)rr�pipe_trigger)rrr)rrrrQszEPipeSocket.__init__cCs(|j|krttjd��|j|7_dS)NZgotcha)r)�OSError�errnoZEPIPEr
)rr
rrrrVs
zEPipeSocket.sendallcCsdS)Nr)rrrrr[szEPipeSocket.closeN)r#r$r%rrrrrrrr(Osr(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�nr
rrrr.dszNoEOFBytesIO.readNcCs"tj�||�}|dkrtd��|S)Nrzcaller tried to read past EOF)r&r'�readliner/)r�lengthr
rrrr1jszNoEOFBytesIO.readline)r-)N)r#r$r%�__doc__r.r1rrrrr,^s
r,cs4eZdZdZ�fdd�Z�fdd�Zdd�Z�ZS)�FakeSocketHTTPConnectionz@HTTPConnection subclass using FakeSocket; counts connect() callscs$d|_t��d�||_|j|_dS)Nrzexample.com)�connections�superr�fake_socket_args�create_connection�_create_connection)r�args)�	__class__rrrssz!FakeSocketHTTPConnection.__init__cs|jd7_t���S)z.Count the number of times connect() is invokedr)r5r6�connect)r)r;rrr<ysz FakeSocketHTTPConnection.connectcOs
t|j�S)N)rr7)r�pos�kwrrrr8~sz*FakeSocketHTTPConnection.create_connection)r#r$r%r3rr<r8�
__classcell__rr)r;rr4psr4c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�HeaderTestscCs�Gdd�dt�}xzdD]r}xldD]d}t�d�}td�|_|�|_d}i}|r\tt|��||<|�dd	||�|�	|jj
|��d
�q WqWdS)Nc@seZdZdd�Zdd�ZdS)z;HeaderTests.test_auto_headers.<locals>.HeaderCountingBuffercSs
i|_dS)N)�count)rrrrr�szDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__cSsX|�d�}t|�dkrH|d�d���}|j�|d�|j|d7<t�||�dS)N�:rrr)�split�len�decode�lowerrA�
setdefault�list�append)r�item�kvZlcKeyrrrrI�s
zBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.appendN)r#r$r%rrIrrrr�HeaderCountingBuffer�srL)TF)zContent-lengthZHostzAccept-encodingzexample.comZblahblahblahZspamspamspam�POST�/r)rHr�HTTPConnectionr�sock�_bufferr	rD�request�assertEqualrArF)rrLZexplicit_header�header�conn�body�headersrrr�test_auto_headers�s



zHeaderTests.test_auto_headerscCsvGdd�dt�}d}d}xZt�||�D]J\}}t�d�}td�|_|�|_|�|d|�|�	|jj
dd�|��q&Wd	}xN|D]F}t�d�}td�|_|�|_|�|dd�|�	|jj
dd
�|��q~WxN|D]F}t�d�}td�|_|�|_|�|dd�|�	|jj
dd�|��q�WxXt�||�D]H}t�d�}td�|_|�|_|�|dd�|�	|jj
d
d�|���q&WdS)Nc@seZdZdd�Zdd�ZdS)z?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckercSst�|�d|_dS)N)rHr�content_length)rrrrr�s
zHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__cSsF|�dd�}t|�dkr6|d��dkr6|d��|_t�||�dS)NrBrrscontent-length)rCrDrF�striprYrHrI)rrJrKrrrrI�szFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.appendN)r#r$r%rrIrrrr�ContentLengthChecker�sr[)N�)�PUTrMZPATCHzexample.comrN�0z%Header Content-Length incorrect on {})�GET�CONNECTZDELETE�HEADZOPTIONSZTRACEz.Header Content-Length set for empty body on {}r\� �1)
rH�	itertools�productrrOrrPrQrRrSrY�format�chain)rr[ZbodiesZmethods_with_body�methodrVrUZmethods_without_bodyrrr�test_content_length_0�sH









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),Nzexample.comr_rNzContent-length�*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)rrOrrP�
putrequest�	putheader�assertInrQ)rrUrrr�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::]:81r\r_z/foosEGET /foo HTTP/1.1
Host: [2001:102A::]
Accept-Encoding: identity

z
[2001:102A::])rrOrrPrR�
assertTruer
�
startswith)r�expectedrUrPrrr�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)rr�HTTPResponse�beginrS�	getheader)rrVrP�resprrr�!test_malformed_headers_coped_withs
z-HeaderTests.test_malformed_headers_coped_withcCs0dttdd��dttdd��d}t|�}t�|�}|��|�|�d�d	�|�|jdd	�|�|�d
�d�|�|jd
d�d�	t
ttdd���}|�|�d
�|�|�|jd
|�|�|�d��|�
d|j�xH|�d�|jdfD]0}|�|�d��|�
d|�|�|�d��q�WdS)Ns0HTTP/1.1 200 OK
!#$%&'*+-.^_`|~: value
VCHAR: �!�s
obs-text: ��sM
obs-fold: text
 folded with space
	folded with tab
Content-Length: 0

zContent-Lengthrz!#$%&'*+-.^_`|~r!r\ZVCHARzobs-textzobs-foldrz folded with spacezfolded with tab)�bytes�rangerrrurvrSrw�msg�join�map�chrZassertIsNotNonernrprq�endswith)rrVrPrxZvcharZfoldedrrr�test_parse_all_octets s"(
z!HeaderTests.test_parse_all_octetscCsxt�d�}td�|_|�dd�d}xN|D]F\}}|�||f��*|�td��|�||�WdQRXWdQRXq*WdS)Nzexample.comr\r_rN))s
Invalid
Names
ValidValue)sInvalid
Names
ValidValue)sInvalid
Names
ValidValue)s

InvalidNames
ValidValue)s
InvalidNames
ValidValue)s
InvalidNames
ValidValue)s InvalidNames
ValidValue)s	InvalidNames
ValidValue)sInvalid:Names
ValidValue)s:InvalidNames
ValidValue)s	ValidNamesInvalid
Value)s	ValidNames
Invalid
Value)s	ValidNames
Invalid
Value)s	ValidNamesInvalidValue
)s	ValidNames
InvalidValue
)s	ValidNames
InvalidValue
zInvalid header)	rrOrrPrl�subTest�assertRaisesRegex�
ValueErrorrm)rrU�cases�namer!rrr�test_invalid_headers>s

z HeaderTests.test_invalid_headersc	Cs�d}t|�}tj|dd�}t���}|��WdQRX|����}|�|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)	rrrur�captured_stdoutrv�getvalue�
splitlinesrS)rrVrPrx�output�linesrrr�test_headers_debuglevel\s
z#HeaderTests.test_headers_debuglevelN)r#r$r%rXrirorsryr�r�r�rrrrr@�sB"
r@c@seZdZdd�ZdS)�HttpMethodTestsc
CsPd}xF|D]>}|�td��(t�d�}td�|_|j|dd�WdQRXq
WdS)N)	zGET
zPOST
zPUT

z
POST
Valuez
POST
HOST:abczGET
rHost:abc
zPOST
Remainder:
z
GET
HOST:
z
PUTz'method can't contain control characterszexample.comrN)rh�url)r�r�rrOrrPrR)r�methodsrhrUrrr�test_invalid_method_namesos



z)HttpMethodTests.test_invalid_method_namesN)r#r$r%r�rrrrr�nsr�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)Nzexample.comrrMrNT)�encode_chunked)rrOrrPrlZ
endheaders�
_make_body�_parse_requestr
�_parse_chunkedrS�
expected_body)rrU�_rVrrr�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)Nzexample.comrrMrNzTransfer-Encoding�chunkedzcontent-lengthcSsg|]}|���qSr)rF)�.0�krrr�
<listcomp>�sz>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>zlatin-1cSsg|]}|���qSr)rF)r�r�rrrr��sz
gzip, chunkedT)rWr�rVcSsg|]}|���qSr)rF)r�r�rrrr��s)rrOrrPrRr�r�r
�assertNotIn�keysrSr�rEr�)rrUr�rWrVrrr�test_explicit_headers�s6






z*TransferEncodingTest.test_explicit_headerscCs�x�dD]�}t�d�}td�|_|�dd|j|d��|�|jj�\}}}|�|�}|�	||j
�|�	|dd�|�d	d
d�|D��qWdS)N)FTzexample.comrrMrN)�empty_lineszTransfer-Encodingr�zcontent-lengthcSsg|]}|���qSr)rF)r�r�rrrr��sz5TransferEncodingTest.test_request.<locals>.<listcomp>)rrOrrPrRr�r�r
r�rSr�r�)rr�rUr�rWrVrrr�test_request�s



z!TransferEncodingTest.test_requestcCslt�d�}td�|_|�ddd�|�|jj�\}}}|�|dd�|�dd	d
�|D��|�|d�dS)Nzexample.comrrMrNrzTransfer-Encodingr�zcontent-lengthcSsg|]}|���qSr)rF)r�r�rrrr��sz8TransferEncodingTest.test_empty_body.<locals>.<listcomp>s0

)	rrOrrPrRr�r
rSr�)rrUr�rWrVrrr�test_empty_body�s

z$TransferEncodingTest.test_empty_bodyFccsZ|j�d�}xHt|�D]<\}}|r0|dr0dV|t|�dkrL|dVq|VqWdS)N� r�rr)r�rC�	enumeraterD)rr�r��idx�linerrrr��szTransferEncodingTest._make_bodycCs�|�d�}|d}i}d}xZ|t|�krtt||�dkrt||�d�\}}|�d���}|�d���||<|d7}qW||d�||dd��fS)Ns
rrrBzlatin-1)rCrDrErZr�)rr
r�rRrWr0�keyrtrrrr��s
z#TransferEncodingTest._parse_requestcCs�g}i}d}|�d�}xd|||d�\}}t|d�}|dkrH|d7}P|�|t|��|�|�|d7}|t|�krPqWd�|�S)Nrs
r��rr)rC�intrSrDrIr�)rr
rV�trailersr0r��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_S)`�	BasicTestcCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|j�|�|��d�|�	|���|�|j�|�
�|�	|j�d}t|�}t�|�}|�tj|j�dS)NzHTTP/1.1 200 Ok

TextrrsTextzHTTP/1.1 400.100 Not Ok

Text)
rrrurvrSr.�assertFalse�isclosed�closedrpr�assertRaises�
BadStatusLine)rrVrPrxrrr�test_status_liness 

zBasicTest.test_status_linescCst�d�}|�t|�d�dS)Nr\zBadStatusLine("''"))rr�rS�repr)r�excrrr�test_bad_status_reprs
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�sTesxt)rrrurvrSr.r�r�rpr�r)rrVrPrxrrr�test_partial_readss
zBasicTest.test_partial_readscCs~d}t|�}t�|�}|��|�|��d�|�|���|�|��d�|�	|���|�|j
�|��|�	|j
�dS)Nz4HTTP/1.1 200 Ok
Content-Length: 13

Text
AnothersText
sAnother)rrrurvrSr1r�r�r.rpr�r)rrVrPrxrrr�test_mixed_reads-s
zBasicTest.test_mixed_readscCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�
|�	��|�|j�|��|�
|j�dS)Nz*HTTP/1.1 200 Ok
Content-Length: 4

Textr�sTesxt)
rrrurv�	bytearray�readintorSr~r�r�rpr�r)rrVrPrx�br0rrr�test_partial_readintos<s 


z BasicTest.test_partial_readintoscCs�d}t|�}t�|�}|��|�|�d�d�|�|���|�|�d�d�|�|�d�d�|�|���|�|j	�|�
�|�|j	�dS)NzHTTP/1.1 200 Ok

Textr�sTesxtrr)rrrurvrSr.r�r�rpr�r)rrVrPrxrrr�$test_partial_reads_no_content_lengthPs
z.BasicTest.test_partial_reads_no_content_lengthcCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�|�}|�|d�|�
|�	��dS)NzHTTP/1.1 200 Ok

Textr�sTesxtr)rrrurvr�r�rSr~r�r�rp)rrVrPrxr�r0rrr�(test_partial_readintos_no_content_length`s

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

Textr�sTesxtrr)	rrrurvrSr.r�r�rp)rrVrPrxrrr�"test_partial_reads_incomplete_bodyss
z,BasicTest.test_partial_reads_incomplete_bodycCs�d}t|�}t�|�}|��td�}|�|�}|�|d�|�t|�d�|�|�	��|�|�}|�|d�|�t|�d�|�|�}|�|d�|�
|�	��|�|j�|��|�
|j�dS)Nz+HTTP/1.1 200 Ok
Content-Length: 10

Textr�sTesxtr)
rrrurvr�r�rSr~r�r�rpr�r)rrVrPrxr�r0rrr�&test_partial_readintos_incomplete_body�s$



z0BasicTest.test_partial_readintos_incomplete_bodycCs^xdD]}|�tjtj|�qWx8dD]0\}}}t�|�}|�||j�|�||j�q&WdS)N)zwww.python.org:abczuser:password@www.python.org))z[fe80::207:e9ff:fe9b]:8000zfe80::207:e9ff:fe9bi@)zwww.python.org:80zwww.python.org�P)zwww.python.org:zwww.python.orgr�)zwww.python.orgzwww.python.orgr�)z[fe80::207:e9ff:fe9b]zfe80::207:e9ff:fe9br�)z[fe80::207:e9ff:fe9b]:zfe80::207:e9ff:fe9br�)r�r�
InvalidURLrOrSrr)r�hp�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)rrrurvrwrS)rrZhdr�srZcookiesrrr�test_response_headers�s

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

ra)rhz)Did not expect response from HEAD request)rr,rrurvr.�fail)rrPrxrrr�test_read_head�szBasicTest.test_read_headcCsTtdt�}tj|dd�}|��td�}|�|�dkr@|�d�|�t	|�d�dS)Nz*HTTP/1.1 200 OK
Content-Length: 14432

ra)rh�rz)Did not expect response from HEAD requests)
rr,rrurvr�r�r�rSr~)rrPrxr�rrr�test_readinto_head�s
zBasicTest.test_readinto_headcCsRd�dd�ttjd�D��d}d|}t|�}t�|�}|�tjd|j�dS)Nz
css|]}d|VqdS)z
Header%d: fooNr)r��irrr�	<genexpr>�sz2BasicTest.test_too_many_headers.<locals>.<genexpr>rzHTTP/1.1 200 OK
zgot more than \d+ headers)	r�rrZ_MAXHEADERSrrur��
HTTPExceptionrv)rrWrr�rrrr�test_too_many_headers�s

zBasicTest.test_too_many_headersc	Csnd}ttd��V}t�d�}t|�}||_|�dd|�|�|j�	|�d|jdt
|��|f�WdQRXdS)Ns_GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

rzexample.comr_z/fooz%r != %r)�open�__file__rrOrrPrRrpr
rqrD)rrrrVrUrPrrr�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 testzexample.comrr�)
rrOrrP�sendrSr
�arrayr&r')rrrrUrPrrr�	test_send�s

zBasicTest.test_sendcsXdd��G�fdd�dtj�}d}t�d�}td�}||_|�|��|�|j|�dS)NcssdVdVdVdS)Nr
Zdata_tworrrrrr
�sz/BasicTest.test_send_updating_file.<locals>.datacs eZdZdZ��Zddd�ZdS)z7BasicTest.test_send_updating_file.<locals>.UpdatingFilerr-cSs
t|j�S)N)�next�d)r�	blocksizerrrr.sz<BasicTest.test_send_updating_file.<locals>.UpdatingFile.readN)r-)r#r$r%rr�r.r)r
rr�UpdatingFilesr�sdatazexample.comr\)	r&�
TextIOBaserrOrrPr�rSr
)rr�rrrUrPr)r
r�test_send_updating_file�s
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)NsonestwosthreerrrrrrVsz&BasicTest.test_send_iter.<locals>.bodyzexample.comr\r_z/foozContent-LengthZ11)rrOrrPrRrSr
)rrrrVrUrPrrr�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.�zexample.com)r�N�a�br]rNzContent-Length�9r�s

r)rrOrrPrRr&r'rSrr
rC)rr�rUrPrrrVrrr�test_blocksize_requestsz BasicTest.test_blocksize_requestcCs\d}tjd|d�}td�}||_d|d}|�t�|��|�|jd�|�|j	|�dS)z5Check that send() respects the configured block size.r�zexample.com)r�Nr�r�r�)
rrOrrPr�r&r'rSrr
)rr�rUrPrrrrr�test_blocksize_send+szBasicTest.test_blocksize_sendc	Cs<t�d�}td�|_|�t��|�dd|�WdQRXdS)Nzexample.comr\rM�test)rrOrrPr��	TypeErrorrR)rrUrrr�test_send_type_error6s

zBasicTest.test_send_type_errorcCsdt}tttt�}tj|dd�}|��|�|�	�|�|�
�xdtdd�D]V}tttt�}tj|dd�}|��|�|�	|�|�	|�|�	�|�|�
�qNWx�dD]�}tt|�}tj|dd�}|��z|y|�	�Wn`tjk
�rB}z>|�|j
|�dt|�}|�t|�|�|�t|�|�Wdd}~XYnX|�d�Wd|�
�Xq�WdS)Nr_)rhr�)r\zfoo
zIncompleteRead(%d bytes read)zIncompleteRead expected)�chunked_expectedr�
chunked_start�
last_chunk�chunked_endrrurvrSr.rr�IncompleteRead�partialrDr�r	r�)rrrrPrxr0�xr��expected_messagerrr�test_chunked=s2$
"zBasicTest.test_chunkedcCs�t}t|�}td�}tttt�}tj|dd�}|�	�|�
|�}|�|d|�|�|�||�|��x�t
dd�D]�}tttt�}tj|dd�}|�	�t|�}|�
|d|��}||�
||||��7}||�
||d��7}|�|d|�|�|�||�|��qxWx�dD]�}	tt|	�}tj|dd�}|�	�z~y|�
|�}Wn`tjk
�r�}z>|�|j|�dt|�}
|�t|�|
�|�t|�|
�Wdd}~XYnX|�d	�Wd|��X�qWdS)
Nr|r_)rhrr�r)r\zfoo
zIncompleteRead(%d bytes read)zIncompleteRead expected)r�rDr�rr�r�r�rrurvr�rSrr�
memoryviewr�r�r�r	r�)rrrZ	nexpectedr�rPrxr0�mr�r�r�rrr�test_readinto_chunked]sD

"zBasicTest.test_readinto_chunkedcCs�d}t|tt�}tj|dd�}|��|�|��d�|�|jd�|�|j	d�|�
|���|�|j
�|��|�
|j
�dS)NzEHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
ra)rhr���OK)rr�r�rrurvrSr.�status�reasonrpr�r�r�r)rr�rPrxrrr�test_chunked_head�szBasicTest.test_chunked_headcCs�d}t|tt�}tj|dd�}|��td�}|�|�}|�|d�|�t	|�d�|�|j
d�|�|jd�|�|�
��|�|j�|��|�|j�dS)	NzEHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
ra)rhr�rsr�r�)rr�r�rrurvr�r�rSr~r�r�rpr�r�r�r)rr�rPrxr�r0rrr�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
r_)rhsHello
)rrrurvrSr.rpr�)rrPrxrrr�test_negative_content_length�sz&BasicTest.test_negative_content_lengthc
Cs�td�}tj|dd�}|��y|��Wn`tjk
r�}z@|�|jd�|�t|�d�|�t	|�d�|�
|���Wdd}~XYnX|�d�dS)Nz.HTTP/1.1 200 OK
Content-Length: 10

Hello
r_)rhsHello
z-IncompleteRead(7 bytes read, 3 more expected)zIncompleteRead expected)
rrrurvr.r�rSr�r�r	rpr�r�)rrPrxr�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-Lengthzexample.comcs��ddd�S)Nr]z/urlrV)rRr)rUrr�<lambda>�rz&BasicTest.test_epipe.<locals>.<lambda>i�zBasic realm="example"zwww-authenticate)
r(rrOrPr�r*�getresponserSr�rw)rrPrxr)rUr�
test_epipe�s
zBasicTest.test_epipecCs8dddd}t�t|��}|�tjtjf|j�dS)NzHTTP/1.1 200 Okr�iz
)rrurr��LineTooLongr�rv)rrVrxrrr�test_overflowing_status_line�sz&BasicTest.test_overflowing_status_linecCs2dddd}t�t|��}|�tj|j�dS)NzHTTP/1.1 200 OK
X-Foo: barriz

)rrurr�rrv)rrVrxrrr�test_overflowing_header_line�sz&BasicTest.test_overflowing_header_linec	Cs^dd}t�t|��}|�tj��}|��WdQRX|�dt|j��|�dt|j��dS)NzHTTP/1.1 100 OK
r
i�zgot more than rW)	rrurr�r�rvrnr	�	exception)rrVrx�cmrrr�'test_overflowing_header_limit_after_100�sz1BasicTest.test_overflowing_header_limit_after_100cCs:dddd}t�t|��}|��|�tj|j�dS)Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

riza
hello world
0

)rrurrvr�rr.)rrVrxrrr�test_overflowing_chunked_line�sz'BasicTest.test_overflowing_chunked_linecCs`d}t|�}t�|�}|��|�|��d�|�|���|�|j	�|�
�|�|j	�dS)NzHTTP/1.1 200 Okr)rrrurvrSr.rpr�r�r�r)rrVrPrxrrr�test_early_eofs
zBasicTest.test_early_eofcsnt�d�}d�G�fdd�dtj�}||_td�|_|�dd�|�tj|j	�|�
�j�|�
|jj�dS)Nzexample.comcseZdZ�fdd�ZdS)z+BasicTest.test_error_leak.<locals>.Responsecs|�tjj|f|�|�dS)N)rrur)rr=r>)�responserrrsz4BasicTest.test_error_leak.<locals>.Response.__init__N)r#r$r%rr)rrr�ResponsesrzInvalid status liner_rN)
rrOruZresponse_classrrPrRr�r�rrpr�r)rrUrr)rr�test_error_leaks

zBasicTest.test_error_leakcCsRd}td}tt|tt�}tj|dd�}|��|�|�	�|�|�
�dS)Nz3;foo=bar
abc
sabcr_)rh)r�rr��last_chunk_extendedr�rrurvrSr.r)rZextrarrrPrxrrr�test_chunked_extensionsz BasicTest.test_chunked_extensioncCsBt}ttt�}tj|dd�}|��|�|��|�|�	�dS)z9some servers may serve up a short chunked encoding streamr_)rhN)
r�rr�r�rrurvrSr.r)rrrrPrxrrr�test_chunked_missing_end)sz"BasicTest.test_chunked_missing_endcCs\t}ttttt�}tj|dd�}|��|�	|�
�|�|�	|j�
�d�|��dS)z&See that trailers are read and ignoredr_)rhrN)
r�rr�r�r�r�rrurvrSr.rr)rrrrPrxrrr�test_chunked_trailers2szBasicTest.test_chunked_trailerscCsjt}d}ttttt|�}tj|dd�}|��|�	|�
�|�|�	|j�
�|�d��|�
�dS)zDCheck that we don't read past the end of the chunked-encoding stream�	extradatar_)rhrN)r�rr�r�r�r�rrurvrSr.rr
r)rrrrrPrxrrr�test_chunked_sync=szBasicTest.test_chunked_synccCs\d}d}td||�}tj|dd�}|��|�|��|�|�|j��|�|��dS)zBCheck that we don't read past the end of the Content-Length streams	extradatas
Hello123
s'HTTP/1.1 200 OK
Content-Length: 10

r_)rhN)rrrurvrSr.rr)rrrrrPrxrrr�test_content_length_syncIsz"BasicTest.test_content_length_synccCs`d}d}td||�}tj|dd�}|��|�|�d�|g�|�|j��|�|��dS)Ns	extradatas
Hello123
s'HTTP/1.1 200 OK
Content-Length: 10

r_)rhi�)	rrrurvrS�	readlinesrr.r)rrrrrPrxrrr�test_readlines_content_lengthUsz'BasicTest.test_readlines_content_lengthcCs^d}d}td||�}tj|dd�}|��|�|�d�|�|�|j��|�|��dS)Ns	extradatas
Hello123
s'HTTP/1.1 200 OK
Content-Length: 10

r_)rhi�)	rrrurvrS�read1rr.r)rrrrrPrxrrr�test_read1_content_length`sz#BasicTest.test_read1_content_lengthcCspd}d}td||�}tj|dd�}|��|�|�d�|�|�|�d�d�|�|j��|�|��dS)Ns	extradatas
Hello123
s'HTTP/1.1 200 OK
Content-Length: 10

r_)rh�
r)	rrrurvrSr1rr.r)rrrrrPrxrrr�"test_readline_bound_content_lengthksz,BasicTest.test_readline_bound_content_lengthcCsvd}d}td|d|�}tj|dd�}|��|�|�d�|d�|�|��|�|�|j��|�|��dS)	Ns	extradatas
Hello123
s'HTTP/1.1 200 OK
Content-Length: 30

r�r_)rh�r�)	rrrurvrSrr.rr)rrrrrPrxrrr�test_read1_bound_content_lengthwsz)BasicTest.test_read1_bound_content_lengthcs�t�tjtjtj��|��j���tdf����d���fdd�}t	j
|d�}|��|�|jt
d��tj����}|�dd�|��}z>|�|jtj�tj|��d�}z|�d	�Wd|��XWd|��|��X|��|��d	�dS)
Nrc
sb���\}}|�H|�d��2}x|��}|�d�s Pq W|�d�|���WdQRXWdQRXdS)Nrs
s'HTTP/1.1 200 Connection established

)Zacceptrr1�rstriprr.)rU�address�readerr�)�result�servrr�
run_server�s

z2BasicTest.test_response_fileno.<locals>.run_server)�targetrr`z
dummy:1234)�filenos
proxied data
)�socket�AF_INET�SOCK_STREAMZIPPROTO_TCP�
addCleanuprZbind�HOST�listen�	threadingZThread�startr��floatrrO�getsocknamerRrrSr�r�r(r�detach)rr&ZthreadrUrr�r)r$r%r�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>.UnsafeHTTPConnectioncSsdS)Nr)rr�rrr�_validate_path�szaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_pathN)r#r$r%r5rrrr�UnsafeHTTPConnection�sr6zexample.comr\r_z/N)rrOrrPrl)rr6rUrrr�*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>.UnsafeHTTPConnectioncSsdS)Nr)rr�rrr�_validate_host�sz_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_hostN)r#r$r%r8rrrrr6�sr6z
example.com
r\r_rNr)Z	skip_host)rrOrrPrl)rr6rUrrr�(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:rrrrr6�sr6zexample.comr\r_u/☃N)rrOrrPrl)rr6rUrrr�!test_putrequest_override_encoding�s
z+BasicTest.test_putrequest_override_encodingN)2r#r$r%r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr	rr
rrrrrrrrrrr r4r7r9r;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
fooZhelloNrz�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)Nr_)rh)	rr�rrurvr&�BufferedReader�fprx)rrPrxrrr�setUp�s

zExtendedReadTest.setUpcs�|j}|jj�d�fdd�	}||j_g}x�|�d�}|r�|�t|�d�|��}|�t|�t|��|�|�|��|�t|��}|�	||�n|��}|�
|�|�|�|s*Pq*W|�	d�|�|j
�dS)Nr-cs(�|�}|dkr|d|�S|dd�S)Nrrr)r0r�)�oldpeekrr�mypeek�sz*ExtendedReadTest.test_peek.<locals>.mypeekr�rr)r-)rxr>�peekZ
assertGreaterrDZassertGreaterEqualrprqr.rSr�rIr��lines_expected)rrxrA�allr�Zp2r�r)r@r�	test_peek�s(


zExtendedReadTest.test_peekcCs|j}|�|jj|j�dS)N)rx�_verify_readliner1rC)rrxrrr�
test_readlineszExtendedReadTest.test_readlinecCs`g}xD|d�}|r6|dkr6t|�dkr6|�|�d��|�|�|sPqW|�d�|�|�dS)Nr�sfoo�
r)rDrpr�rIrSr�)rr1rrrDr�rrrrFs
z!ExtendedReadTest._verify_readlinecs0�j���fdd�}t|�}��|j�j�dS)Ncs��d�}��t|�d�|S)N�)r�assertLessEqualrD)Zres)rxrrrr+s
z&ExtendedReadTest.test_read1.<locals>.r)rx�	ReadlinerrFr1rC)rrZ	readlinerr)rxrr�
test_read1)szExtendedReadTest.test_read1cCs@|j}g}x|��}|sP|�|�qW|�d�|�|j�dS)Nr)rxrrIrSr�rC)rrxrDr
rrr�test_read1_unbounded2sz%ExtendedReadTest.test_read1_unboundedcCsR|j}g}x.|�d�}|sP|�t|�d�|�|�qW|�d�|�|j�dS)Nrr)rxrrJrDrIrSr�rC)rrxrDr
rrr�test_read1_bounded<s
z#ExtendedReadTest.test_read1_boundedcCs|�|j�d�d�dS)Nrr)rSrxr)rrrr�test_read1_0GszExtendedReadTest.test_read1_0cCs |j�d�}|�dt|��dS)Nr)rxrBrJrD)rr�rrr�test_peek_0JszExtendedReadTest.test_peek_0)r#r$r%r3r��findr
rCZ
lines_chunkedr?rErGrFrLrMrNrOrPrrrrr<�s	
	
r<c@seZdZdZdZdS)�ExtendedReadTestChunkedz:
    Test peek(), read1(), readline() in chunked mode
    z�HTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello worl
3
d!

9
and now 

23
for something completely different

3
foo
0

N)r#r$r%r3r�rrrrrROsrRc@s eZdZdZdd�Zdd�ZdS)rKzT
    a simple readline class that uses an arbitrary read function and buffering
    cCs||_d|_dS)Nr)�readfunc�	remainder)rrSrrrriszReadliner.__init__cCs�g}d}|j}y�xP|�d�}|dkr&P|t|�|krB||d}|�|�|��}|sd}PqW|d7}|�|d|��||d�|_d�|�Sd�|�|_�YnXdS)NrrHr-rr)rTrQrDrIrSr�)r�limitr
Zdatalenr.r�rrrr1ms,


zReadliner.readlineN)r#r$r%r3rr1rrrrrKesrKc@s$eZdZdd�Zdd�Zdd�ZdS)�OfflineTestcCsjdh}ddh}xHtt�D]<}|�d�s||kr0qtt|�}t|dd�dkr|�|�qW|�tj|�dS)N�	responsesZHTTPMessage�
parse_headersr�r$zhttp.client)�dirrrq�getattr�addZassertCountEqual�__all__)rrrZ	blacklistr�Z
module_objectrrr�test_all�s
zOfflineTest.test_allcCs|�tjtjd�dS)Nz	Not Found)rSrrW�	NOT_FOUND)rrrr�test_responses�szOfflineTest.test_responsesc6Cs�ddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6g6}x4|D],}|j|d7��|�tt|��WdQRXqvWdS)8NZCONTINUEZSWITCHING_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_FAILEDZMISDIRECTED_REQUESTZUNPROCESSABLE_ENTITYZLOCKEDZFAILED_DEPENDENCYZUPGRADE_REQUIREDZPRECONDITION_REQUIREDZTOO_MANY_REQUESTSZREQUEST_HEADER_FIELDS_TOO_LARGEZINTERNAL_SERVER_ERRORZNOT_IMPLEMENTEDZBAD_GATEWAYZSERVICE_UNAVAILABLEZGATEWAY_TIMEOUTZHTTP_VERSION_NOT_SUPPORTEDZINSUFFICIENT_STORAGEZNOT_EXTENDEDZNETWORK_AUTHENTICATION_REQUIRED)Zconstant)r�rp�hasattrr)rrr�constrrr�test_client_constants�sr
z!OfflineTest.test_client_constantsN)r#r$r%r]r_rbrrrrrV�srVc@s@eZdZdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
dS)�SourceAddressTestcCs>t�tjtj�|_t�|j�|_t��|_|j�	�d|_
dS)N)r)r*r+r%r�	bind_portrZfind_unused_port�source_portr.rU)rrrrr?�s


zSourceAddressTest.setUpcCs*|jr|j��d|_|j��d|_dS)N)rUrr%)rrrr�tearDown�s


zSourceAddressTest.tearDowncCsBtjt|jd|jfd�|_|j��|�|jj�	�d|j�dS)Nr\)�source_addressr)
rrOr-rrerUr<rSrPr2)rrrr�testHTTPConnectionSourceAddress�s

z1SourceAddressTest.testHTTPConnectionSourceAddress�HTTPSConnectionz'http.client.HTTPSConnection not definedcCstjt|jd|jfd�|_dS)Nr\)rg)rrir-rrerU)rrrr� testHTTPSConnectionSourceAddress�s
z2SourceAddressTest.testHTTPSConnectionSourceAddressN)r#r$r%r?rfrh�unittest�skipIfr`rrjrrrrrc�s
rcc@s(eZdZdZdd�Zdd�Zdd�ZdS)�TimeoutTestNcCs.t�tjtj�|_t�|j�t_|j��dS)N)	r)r*r+r%rrdrm�PORTr.)rrrrr?�szTimeoutTest.setUpcCs|j��d|_dS)N)r%r)rrrrrf�s
zTimeoutTest.tearDownc	Cs�|�t���t�d�zt�ttj�}|�	�Wdt�d�X|�
|j��d�|�
�|�t���t�d�ztjttjdd�}|�	�Wdt�d�X|�
|j��d�|�
�tjttjdd�}|�	�|�
|j��d�|�
�dS)N�)�timeout)�assertIsNoner)ZgetdefaulttimeoutZsetdefaulttimeoutrrOr-rmrnr<rSrPZ
gettimeoutr)rZhttpConnrrr�testTimeoutAttributes*


z TimeoutTest.testTimeoutAttribute)r#r$r%rnr?rfrrrrrrrm�srmc@s$eZdZdd�Zdd�Zdd�ZdS)�PersistenceTestcCs�d}x�|D]�\}}}|j||d���d�||�}t|�}|�|j�|�dd�|���"}|�|jdk|�|��WdQRX|�|jdk|�|�|j	d�|�dd�|�|j	|r�dnd�WdQRXq
WdS)	N))z1.0r\F)z1.0zConnection: keep-alive
T)z1.1r\T)z1.1zConnection: close
F)z1.0zConnection: keep-ALIVE
T)z1.1zConnection: cloSE
F)�versionrTz4HTTP/{} 200 OK
{}Content-Length: 12

Dummy body
r_z/open-connectionrz/subsequent-requestr�)
r�rfr4rqrPrRrrSr.r5)r�testsrtrTZreuser�rUrrrr�test_reuse_reconnect's
z$PersistenceTest.test_reuse_reconnectc
Cs�dd�}tjtjf|tff}xr|D]j\}}|j|d��Ptd|�}|�dd�|�||j	�|�
|j�|�dd�|�|j
d�WdQRXq"WdS)	Ncs&t�|���fdd�}|�_t���S)z3Return BufferedReader that raises ECONNRESET at EOFcs tj��|�}|dkrt��|S)Nr)r&r'r��ConnectionResetError)�bufferr�)�streamrrr�JszNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readinto)r&r'r�r=)rr�r)ryr�make_reset_readerGs
z<PersistenceTest.test_disconnected.<locals>.make_reset_reader)r
rr_z
/eof-responsez
/reconnectr�)r&r'r�RemoteDisconnectedrwr�r4rRr�rrqrPrSr5)rrzruZstream_factoryr
rUrrr�test_disconnectedEs


z!PersistenceTest.test_disconnectedcCsVtd�}|jddddid�|�tj|j�|�|j�|�dd�|�|j	d�dS)	NsHTTP/1.1 100 Continue

r_rNZExpectz100-continue)rWz
/reconnectr�)
r4rRr�rr{rrqrPrSr5)rrUrrr�test_100_close`szPersistenceTest.test_100_closeN)r#r$r%rvr|r}rrrrrs%srsc@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)Nrizssl support required)r`r�skipTest)rrrrr?os
zHTTPSTest.setUpcCsddlm}|||d�S)Nr)�make_https_server)�certfile)Ztest.ssl_serversr�)rr�r�rrr�make_serversszHTTPSTest.make_servercCs$tjttjdd�}|�|jd�dS)Nro)rp)rrir-rmrnrSrp)rr�rrr�test_attributeswszHTTPSTest.test_attributesc
Cslddl}t�d�t�d��Ft�dd�}|�|j��}|�dd�WdQRX|�	|j
jd�WdQRXdS)Nr�networkzself-signed.pythontest.neti�r_rN�CERTIFICATE_VERIFY_FAILED)�sslr�requires�transient_internetrrir��SSLErrorrRrSr
r�)rr�r��exc_inforrr�test_networked|s
zHTTPSTest.test_networkedc	Cszddl}t�d�t�d��T|��}tjdd|d�}|�dd�|��}|�	�|�
d|�d	��|�	�WdQRXdS)
Nrr�zself-signed.pythontest.neti�)�contextr_rN�nginx�server)r�rr�r�Z_create_unverified_contextrrirRrrrnrw)rr�r�r�rxrrr�test_networked_noverification�s
z'HTTPSTest.test_networked_noverificationc	Csjt�d�t�d��Lt�dd�}|�dd�|��}|�d�}|��|��|�	d|�WdQRXdS)Nr�zwww.python.orgi�r_rNzcontent-typez	text/html)
rr�r�rrirRrrwrrn)rr�rxZ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�y(tj
|d|d�}|�dd�|��}WnR|jk
r�}z2t|�}t�d	|�r�t�d
|�d|�d����Wdd}~XYnX|�d
�}|��|��|�d|�WdQRXdS)Nrr�zself-signed.pythontest.netTi�)r�r_rNz(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.r�r�)r�rr�r��
SSLContext�PROTOCOL_TLS_CLIENTrSZverify_modeZ
CERT_REQUIRED�check_hostname�load_verify_locations� CERT_selfsigned_pythontestdotnetrrirRrr�r	�re�searchrkZSkipTestrwrrn)	rr�Zselfsigned_pythontestdotnetr�r�rxZssl_errZssl_err_strZ
server_stringrrr�test_networked_good_cert�s.


z"HTTPSTest.test_networked_good_certc
Cs�ddl}t�d�t�d��`|�|j�}|�t�tj	dd|d�}|�
|j��}|�dd�WdQRX|�
|jjd�WdQRXdS)	Nrr�zself-signed.pythontest.neti�)r�r_rNr�)r�rr�r�r�r�r��CERT_localhostrrir�r�rRrSr
r�)rr�r�r�r�rrr�test_networked_bad_cert�s

z!HTTPSTest.test_networked_bad_certc	CsXddl}|�t�}t�d|j�}|�|j��}|�dd�WdQRX|�	|j
jd�dS)Nr�	localhostr_rNr�)r�r�r�rrirr�r�rRrSr
r�)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)Nrr�)r�r_z/nonexistenti�)r�r�r�r�r�r�rrirr,rrRrrSr�)rr�r�r�r�rxrrr�test_local_good_hostname�s

z"HTTPSTest.test_local_good_hostnamec	Cs�ddl}|�t�}|�|j�}|�t�tjd|j|d�}|�	|j
��|�dd�WdQRXt�
dtf��tjd|j|dd�}WdQRX|�	|j
��|�dd�WdQRXd	|_t�
dtf��tjd|j|d	d�}WdQRX|�dd
�|��}|��|��|�|jd�d	|_tjd|j|d�}|�dd
�|��}|�|jd�|��|��t�
dtf��tjd|j|dd�}WdQRX|�	|j
��|�dd�WdQRXdS)Nrr�)r�r_rNr\T)r�r�Fz/nonexistenti�)r�r��CERT_fakehostnamer�r�r�rrirr�ZCertificateErrorrRrZcheck_warnings�DeprecationWarningr�rrrSr�)rr�r�r�r�rxrrr�test_local_bad_hostname�sB




z!HTTPSTest.test_local_bad_hostnameriz)http.client.HTTPSConnection not availablecCs^xdD]}|�tjtj|�qWx8dD]0\}}}t�|�}|�||j�|�||j�q&WdS)N)zwww.python.org:abczuser:password@www.python.org))z[fe80::207:e9ff:fe9b]:8000zfe80::207:e9ff:fe9bi@)zwww.python.org:443zwww.python.orgi�)zwww.python.org:zwww.python.orgi�)zwww.python.orgzwww.python.orgi�)z[fe80::207:e9ff:fe9b]zfe80::207:e9ff:fe9bi�)z[fe80::207:e9ff:fe9b]:zfe80::207:e9ff:fe9bi�)r�rr�rirSrr)rr�r�r�r�rrrr�s

zHTTPSTest.test_host_portcCs�ddl}|js|�d�t�dd�}|�|jj�|�|j	�}|�
|j�tjdd|d�}|�|j|�|�
|jj�tjdd|td�}|�|jj�dS)NrzTLS 1.3 support requiredr�i�)r�)r�Z	cert_file)
r�ZHAS_TLSv1_3rrrirpZ_contextZpost_handshake_authr�r�r�ZassertIsr�)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�r�r�r�r�rkrlr`rr�r�rrrrr~ms

!	
*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)Nzexample.comr\)rrOrUrrP)rrrrr?8szRequestBodyTest.setUpcCs(t�|jj�}|��t�|�}||fS)N)r&r'rPr
r1rrX)r�f�messagerrr�get_headers_and_fp=s
z"RequestBodyTest.get_headers_and_fpc
Cs�ddgdfdf}x�|D]�\}}|�|��zt�d�|_td�|j_|_|j�dd|�|��\}}|�d	|�|�d
|�|�	|�
d�d�|�	||���WdQRXqWdS)
Nsfoosbars3
foo
3
bar
0

))sfoosbars3
foo
3
bar
0

zexample.comr\r]z/urlzContent-TypezContent-LengthzTransfer-Encodingr�)r�rrOrUrrPrRr�r�rS�getr.)rr�rVrrr�r�rrr�test_list_bodyCs
zRequestBodyTest.test_list_bodycCsL|j�dddddi�|��\}}|�d|�d��|�dt|����dS)Nr]z/urlrVzContent-LengthZ42zcontent-lengthrI)rUrRr�rSr�rDr.)rr�r�rrr�test_manual_content_lengthWs

z*RequestBodyTest.test_manual_content_lengthcCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)Nr]z/urlrVz
text/plain�4zcontent-lengthsbody)	rUrRr�rS�get_content_typerq�get_charsetr�r.)rr�r�rrr�test_ascii_body`szRequestBodyTest.test_ascii_bodycCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)Nr]z/urlubodyÁz
text/plain�5zcontent-lengthsbody�)	rUrRr�rSr�rqr�r�r.)rr�r�rrr�test_latin1_bodyhsz RequestBodyTest.test_latin1_bodycCs`|j�ddd�|��\}}|�d|���|�|���|�d|�d��|�d|���dS)Nr]z/urlsbody�z
text/plainr�zcontent-length)	rUrRr�rSr�rqr�r�r.)rr�r�rrr�test_bytes_bodypszRequestBodyTest.test_bytes_bodyc	Cs�|�tjtj�ttjd��}|�d�WdQRXttj��r}|j�dd|�|��\}}|�	d|�
��|�|���|�|�
d��|�	d|�
d��|�	d	|���WdQRXdS)
N�wrVr]z/urlz
text/plainzcontent-lengthr�ztransfer-encodings4
body
0

)r,r�unlink�TESTFNr��writerUrRr�rSr�rqr�r�r.)rr�r�rrr�test_text_file_bodyxsz#RequestBodyTest.test_text_file_bodyc	Cs�|�tjtj�ttjd��}|�d�WdQRXttjd��n}|j�dd|�|��\}}|�	d|�
��|�|���|�	d|�
d��|�d	|�|�	d
|���WdQRXdS)N�wbsbody�rr]z/urlz
text/plainr�zTransfer-EncodingzContent-Lengths5
body�
0

)r,rr�r�r�r�rUrRr�rSr�rqr�r�r�r.)rr�r�rrr�test_binary_file_body�sz%RequestBodyTest.test_binary_file_bodyN)
r#r$r%r3r?r�r�r�r�r�r�r�r�rrrrr�5s	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)rrrurxrv)rrVrPrrrr?�szHTTPResponseTest.setUpcCs6|j�d�}|�|d�|j�dd�}|�|d�dS)Nz	My-Headerzfirst-value, second-valuezsome default)rxrwrS)rrTrrr�test_getting_header�sz$HTTPResponseTest.test_getting_headercCs|j�dd�}|�|d�dS)NzNo-Such-Headerz
default-value)rxrwrS)rrTrrr�3test_getting_nonexistent_header_with_string_default�szDHTTPResponseTest.test_getting_nonexistent_header_with_string_defaultcCs<|j�dddg�}|�|d�|j�dd�}|�|d�dS)NzNo-Such-Header�default�valueszdefault, values)r�r�)rxrwrS)rrTrrr�5test_getting_nonexistent_header_with_iterable_default�szFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_defaultcCs|j�d�}|�|d�dS)NzNo-Such-Header)rxrwrS)rrTrrr�/test_getting_nonexistent_header_without_default�sz@HTTPResponseTest.test_getting_nonexistent_header_without_defaultcCs |jjddd�}|�|d�dS)NzNo-Such-Headerrj)r�)rxrwrS)rrTrrr�test_getting_header_defaultint�sz/HTTPResponseTest.test_getting_header_defaultintN)	r#r$r%r?r�r�r�r�r�rrrrr��sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�TunnelTestscCs*d}d|_t�|j�|_|�|�|j_dS)Nz:HTTP/1.0 200 OK

HTTP/1.1 200 OK
Content-Length: 42

z	proxy.com)rrrOrUr9)r�
response_textrrrr?�szTunnelTests.setUpcCs|j��dS)N)rUr)rrrrrf�szTunnelTests.tearDowncsd�fdd�	}|S)Ncst�|d|dd�S)Nrr)rr)r)r"rprg)r�rrr8�sz9TunnelTests._create_connection.<locals>.create_connection)NNr)rr�r8r)r�rr9�szTunnelTests._create_connectioncCs�d}d}ddi}|jj|||d�|j�ddd�|�|jjj|j�|�|jjjtj�|�|jj	|�|�|jj
|�|�|jj|�dS)	Nzdestination.comi�"z
User-Agentz!Mozilla/5.0 (compatible, MSIE 11))rrWrarNr\)rU�
set_tunnelrRrSrPrrr�	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)Nzdestination.com)rUr<r��RuntimeErrorr�)rrrr�&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)	Nzdestination.comrarNr\sCONNECT destination.comsHost: destination.com:NonesHost: destination.comsHost: proxy.com)rUr�rRrSrPrrrr�rnr
r�)rrrr�test_connect_with_tunnel�sz$TunnelTests.test_connect_with_tunnelcCsl|j�d�|j�ddd�|�|jjj|j�|�|jjjtj�|�	d|jjj
�|�	d|jjj
�dS)Nzdestination.comr]rNr\sCONNECT destination.comsHost: destination.com)rUr�rRrSrPrrrr�rnr
)rrrr�test_connect_put_request�sz$TunnelTests.test_connect_put_requestc	Cszd}d�|�}|j�d�|�|�|j_|j�d�t���}|j�ddd�WdQRX|���	�}|�
d�|�|�dS)	Nz
X-Dummy: 1zHTTP/1.0 200 OK
{}

rzdestination.comr]rNr\z
header: {})rfrUZset_debuglevelr9r�rr�rRr�r�rn)rZexpected_headerr�r�r�rrr�test_tunnel_debuglog�s

z TunnelTests.test_tunnel_debuglogN)r#r$r%r?rfr9r�r�r�r�r�rrrrr��s


r��__main__r�)�	verbosity)5r+Zhttprr&rd�osr�r�r)r/rkZTestCaser�r�path�dirnamer��herer�r�r�r�r�r�Zchunk_extensionr�rr�r�r-rr(r'r,rOr4r@r�r�r�r<rRrKrVrcrmrsr~r�r�r�r#�mainrrrr�<module>sh!nS}"Q.HI`#I