
    z%ix                       d dl Z d dlZd dlmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ ej                  Zd dlmZ d dlmZ d dlmZ  ej(                  d       ej*                  j-                  e      Zej*                  j3                  ed	      Zej*                  j3                  ed
      Zej*                  j3                  ed      ZdZdZdZdZ dez   dz   Z!dZ"dZ#ejH                  Z$ G d d      Z% G d de%      Z& G d dejN                        Z( G d dejR                        Z* G d de      Z+ G d de      Z, G d d e      Z- G d! d"e      Z. G d# d$e      Z/ G d% d&e/      Z0 G d' d(      Z1 G d) d*e      Z2 G d+ d,e      Z3 G d- d.e      Z4 G d/ d0e      Z5 G d1 d2e      Z6 G d3 d4e      Z7 G d5 d6e      Z8 G d7 d8e      Z9e:d9k(  r ejv                  d:;       yy)<    N)client
HTTPStatus)mock)support)	os_helper)socket_helperT)modulezkeycert.pemzkeycert2.pemzselfsigned_pythontestdotnet.pemz{HTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello worl
3
d! 
8
and now 
22
for something completely different
s7   hello world! and now for something completely differentz;foo=barz0
0
zX-Dummy: foo
X-Dumm2: bar
c                   N    e Zd Zej                  ddfdZd ZddZd Zd Z	d Z
y)	
FakeSocketNc                     t        |t              r|j                  d      }|| _        || _        d| _        d| _        d| _        || _        || _	        y )Nascii    r   F)

isinstancestrencodetext	fileclassdatasendall_callsfile_closedhostport)selfr   r   r   r   s        E/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_httplib.py__init__zFakeSocket.__init__5   sM    dC ;;w'D	"	 		r   c                 X    | xj                   dz  c_         | xj                  |z  c_        y )N   )r   r   r   r   s     r   sendallzFakeSocket.sendall@   s!    a		T	r   c                     |dk7  r|dk7  rt        j                         | j                  | j                        | _        | j
                  | j                  _        | j                  S )Nrrb)r   UnimplementedFileModer   r   file
file_closeclose)r   modebufsizes      r   makefilezFakeSocket.makefileD   sK    3;44<..00NN499-	//		yyr   c                     d| _         y )NT)r   r   s    r   r'   zFakeSocket.file_closeL   s
    r   c                      y N r-   s    r   r(   zFakeSocket.closeO       r   c                      y r/   r0   )r   leveloptnamevalues       r   
setsockoptzFakeSocket.setsockoptR   r1   r   r/   )__name__
__module____qualname__ioBytesIOr   r!   r+   r'   r(   r6   r0   r   r   r   r   4   s+    ')zz4 	 r   r   c                       e Zd Zd Zd Zd Zy)EPipeSocketc                 >    t         j                  | |       || _        y r/   )r   r   pipe_trigger)r   r   r?   s      r   r   zEPipeSocket.__init__W   s    D$'(r   c                 ~    | j                   |v rt        t        j                  d      | xj                  |z  c_        y )Ngotcha)r?   OSErrorerrnoEPIPEr   r    s     r   r!   zEPipeSocket.sendall\   s/    $%++x00		T	r   c                      y r/   r0   r-   s    r   r(   zEPipeSocket.closea   r1   r   N)r7   r8   r9   r   r!   r(   r0   r   r   r=   r=   U   s    )

r   r=   c                        e Zd ZdZddZddZy)NoEOFBytesIOzLike 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.
    c                 f    t         j                  j                  | |      }|dk(  rt        d      |S Nr   zcaller tried to read past EOF)r:   r;   readAssertionError)r   nr   s      r   rJ   zNoEOFBytesIO.readj   s.    zztQ'3; !@AAr   Nc                 f    t         j                  j                  | |      }|dk(  rt        d      |S rI   )r:   r;   readlinerK   )r   lengthr   s      r   rN   zNoEOFBytesIO.readlinep   s0    zz""403; !@AAr   r/   )r7   r8   r9   __doc__rJ   rN   r0   r   r   rG   rG   d   s    
r   rG   c                   2     e Zd ZdZ fdZ fdZd Z xZS )FakeSocketHTTPConnectionz@HTTPConnection subclass using FakeSocket; counts connect() callsc                 b    d| _         t        | 	  d       || _        | j                  | _        y )Nr   example.com)connectionssuperr   fake_socket_argscreate_connection_create_connection)r   args	__class__s     r   r   z!FakeSocketHTTPConnection.__init__y   s.    ' $"&"8"8r   c                 J    | xj                   dz  c_         t        | 	         S )z.Count the number of times connect() is invokedr   )rW   rX   connect)r   r]   s    r   r_   z FakeSocketHTTPConnection.connect   s!    Aw  r   c                 &    t        | j                   S r/   )r   rY   )r   poskws      r   rZ   z*FakeSocketHTTPConnection.create_connection   s    40011r   )r7   r8   r9   rR   r   r_   rZ   __classcell__)r]   s   @r   rT   rT   v   s    J9!
2r   rT   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
HeaderTestsc                 p    G d dt               }dD ]  }dD ]  }t        j                  d      }t        d      |_         |       |_        d}i }|rt        t        |            ||<   |j                  dd	||       | j                  |j
                  j                  |j                            d
         y )Nc                       e Zd Zd Zd Zy);HeaderTests.test_auto_headers.<locals>.HeaderCountingBufferc                     i | _         y r/   )countr-   s    r   r   zDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__   s	    
r   c                    |j                  d      }t        |      dkD  rU|d   j                  d      j                         }| j                  j                  |d       | j                  |xx   dz  cc<   t        j                  | |       y )N   :r   r   r   )splitlendecodelowerrj   
setdefaultlistappend)r   itemkvlcKeys       r   rs   zBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.append   sl    ZZ%r7Q;qELL1779EJJ))%3JJu%*%D$'r   Nr7   r8   r9   r   rs   r0   r   r   HeaderCountingBufferrh      s     (r   rx   )TF)Content-lengthHostzAccept-encodingrV   blahblahblahspamspamspamPOST/r   )rr   r   HTTPConnectionr   sock_bufferr   rn   requestassertEqualrj   rp   )r   rx   explicit_headerheaderconnbodyheaderss          r   test_auto_headerszHeaderTests.test_auto_headers   s    
	(4 
	(  + 	HOE 
H,,];&~6	35%"&)#d)nGFOVS$8  !3!3FLLN!CQG
H	Hr   c                     G d dt               }d}d}t        j                  ||      D ]  \  }}t        j                  d      }t        d       |_         |       |_        |j                  |d|       | j                  |j                  j                  ddj                  |              d	}|D ]|  }t        j                  d      }t        d       |_         |       |_        |j                  |dd        | j                  |j                  j                  d d
j                  |             ~ |D ]|  }t        j                  d      }t        d       |_         |       |_        |j                  |dd       | j                  |j                  j                  ddj                  |             ~ t        j                  ||      D ]|  }t        j                  d      }t        d       |_         |       |_        |j                  |dd       | j                  |j                  j                  ddj                  |             ~ y )Nc                       e Zd Zd Zd Zy)?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckerc                 <    t         j                  |        d | _        y r/   )rr   r   content_lengthr-   s    r   r   zHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__   s    d#&*#r   c                     |j                  dd      }t        |      dkD  r.|d   j                         dk(  r|d   j                         | _        t
        j                  | |       y )Nrl   r   r   s   content-length)rm   rn   rp   stripr   rr   rs   )r   rt   ru   s      r   rs   zFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.append   sO    ZZa(r7Q;2a5;;=4E#E*,Q%++-D'D$'r   Nrw   r0   r   r   ContentLengthCheckerr      s    +(r   r   )N )PUTr}   PATCHrV   r~      0z%Header Content-Length incorrect on {})GETCONNECTDELETEHEADOPTIONSTRACEz.Header Content-Length set for empty body on {}r       1)rr   	itertoolsproductr   r   r   r   r   r   r   r   formatchain)r   r   bodiesmethods_with_bodymethodr   r   methods_without_bodys           r   test_content_length_0z!HeaderTests.test_content_length_0   s   	(4 	( 4%--.?H 	LFD((7D"4(DI/1DLLLd+++T7>>vF	 
 + 	F((7D"4(DI/1DLLLd+++T@GGO	 + 	F((7D"4(DI/1DLLLb)++T7>>vF	  oo&:<MN 	F((7D"4(DI/1DLLLc*++T7>>vF	r   c                 |   t        j                  d      }t        d       |_        |j	                  dd       |j                  dd       | j                  d|j                         |j                  dd       | j                  d	|j                         |j                  d
d       | j                  d|j                         |j                  dd       | j                  d|j                         |j                  ddd       | j                  d|j                         |j                  dd       | j                  d|j                         |j                  dd       | j                  d|j                         |j                  dd       | j                  d|j                         |j                  dd       | j                  d|j                         |j                  d d!       | j                  d"|j                         |j                  d#d$       | j                  d%|j                         |j                  d&d$       | j                  d'|j                         |j                  d(d$       | j                  d)|j                         |j                  d*d$       | j                  d+|j                         y ),NrV   r   r~   ry   *   s   Content-length: 42Fooz bar s
   Foo:  bar Barz	baz	s
   Bar: 	baz	AuthorizationzBearer mytokens   Authorization: Bearer mytoken
IterHeaderIterAIterBs   IterHeader: IterA
	IterBLatinHeader   s   LatinHeader: 
Utf8Headers   Às   Utf8Header: Àz
C1-Controls	   nextlines   C1-Control: nextlinezEmbedded-Fold-Spacezis
 alloweds!   Embedded-Fold-Space: is
 allowedzEmbedded-Fold-Tabzis
	alloweds   Embedded-Fold-Tab: is
	allowedz	Key Spacer5   s   Key Space: valuez	KeySpace s   KeySpace : values   NonbreakSpaces   NonbreakSpace: values   NonbreakSpaces   NonbreakSpace: value)r   r   r   r   
putrequest	putheaderassertInr   r   r   s     r   test_putheaderzHeaderTests.test_putheader   s   $$]3t$	c"',+T\\:ug&mT\\2ui(ot||4(896E|Wg65t||D}g.*DLL9|[1-t||<|_514<<@,.>?<dllK*,=>;T\\J{G,)4<<8{G,)4<<8+W514<<@+W514<<@r   c                    d}t        j                  d      }t        d      }||_        |j	                  dd       | j                  |j                  j                  |             d}t        j                  d      }t        d      }||_        |j	                  dd       | j                  |j                  j                  |             y )NsC   GET /foo HTTP/1.1
Host: [2001::]:81
Accept-Encoding: identity

z[2001::]:81r   r   /foosE   GET /foo HTTP/1.1
Host: [2001:102A::]
Accept-Encoding: identity

z[2001:102A::])r   r   r   r   r   
assertTruer   
startswithr   expectedr   r   s       r   test_ipv6host_headerz HeaderTests.test_ipv6host_header	  s    8$$]3"~	UF#		,,X678$$_5"~	UF#		,,X67r   c                     d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j	                  |j                  d      d       y )Nz4HTTP/1.1 200 OK
First: val
: nval
Second: val

FirstvalSecond)r   r   HTTPResponsebeginr   	getheaderr   r   r   resps       r   !test_malformed_headers_coped_withz-HeaderTests.test_malformed_headers_coped_with  s\    O$""4(

0%8159r   c           	         dt        t        dd            z   dz   t        t        dd            z   dz   }t        |      }t        j                  |      }|j                          | j                  |j                  d      d	       | j                  |j                  d   d	       | j                  |j                  d
      d       | j                  |j                  d
   d       dj                  t        t        t        dd                  }| j                  |j                  d      |       | j                  |j                  d   |       | j                  |j                  d             | j                  d|j                         |j                  d      |j                  d   fD ]T  }| j                  |j                  d             | j                  d|       | j                  |j!                  d             V y )Ns0   HTTP/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!#$%&'*+-.^_`|~r5   r   VCHARzobs-textzobs-foldr   z folded with spacezfolded with tab)bytesranger   r   r   r   r   r   msgjoinmapchrassertIsNotNoner   r   r   endswith)r   r   r   r   vcharfoldeds         r   test_parse_all_octetsz!HeaderTests.test_parse_all_octets&  s   uT84569 "%h"789< 	 $""4(

(893?"23S9(9:GD"34g>CtX!6780%8'*E2T^^J78j$((+~~j1488J3GH 	@FOOF--f56MM.7OOFOO,=>?	@r   c                 T   t        j                  d      }t        d      |_        |j	                  dd       d}|D ]R  \  }}| j                  ||f      5  | j                  t        d      5  |j                  ||       d d d        d d d        T y # 1 sw Y   xY w# 1 sw Y   kxY w)NrV   r   r   r~   ))s   Invalid
Name
   ValidValue)s   InvalidNamer   )s   Invalid
Namer   )s   
InvalidNamer   )s   InvalidNamer   )s   
InvalidNamer   )s    InvalidNamer   )s   	InvalidNamer   )s   Invalid:Namer   )s   :InvalidNamer   )	   ValidNames   Invalid
Value)r   s   InvalidValue)r   s   Invalid
Value)r   s   InvalidValue
)r   s   InvalidValue)r   s   InvalidValue
zInvalid header)	r   r   r   r   r   subTestassertRaisesRegex
ValueErrorr   )r   r   casesnamer5   s        r   test_invalid_headersz HeaderTests.test_invalid_headersD  s    $$]3rN	s#
$ ! 	0KD%tUm, 0++J8HI 0NN4/00 0	00 00 0s$   B,B?BBBB'	c                    d}t        |      }t        j                  |d      }t        j                         5 }|j                          d d d        j                         j                         }| j                  |d   d       | j                  |d   d       | j                  |d   d       | j                  |d	   d
       y # 1 sw Y   |xY w)Ns9   HTTP/1.1 200 OK
First: val
Second: val1
Second: val2
r   )
debuglevelr   zreply: 'HTTP/1.1 200 OK\r\n'zheader: First: val   zheader: Second: val1   zheader: Second: val2)	r   r   r   r   captured_stdoutr   getvalue
splitlinesr   )r   r   r   r   outputliness         r   test_headers_debuglevelz#HeaderTests.test_headers_debuglevelb  s      	 $""4A6$$& 	&JJL	!,,.q#CDq#78q#9:q#9:	 	s   CCN)r7   r8   r9   r   r   r   r   r   r   r   r   r0   r   r   re   re      s0    H:@D AD8&:@<0<;r   re   c                       e Zd Zd Zy)HttpMethodTestsc                     d}|D ]Y  }| j                  t        d      5  t        j                  d      }t	        d       |_        |j                  |d       d d d        [ y # 1 sw Y   fxY w)N)	zGETzPOST
zPUT
z
POST
ValuezPOST
HOST:abczGET
rHost:abc
zPOSTRemainder:z
GETHOST:
z
PUTz'method can't contain control charactersrV   r~   )r   url)r   r   r   r   r   r   r   )r   methodsr   r   s       r   test_invalid_method_namesz)HttpMethodTests.test_invalid_method_namesu  su    

  	5F'' IK 5,,];&t,	F4	5 5	55 5s   9A""A+	N)r7   r8   r9   r   r0   r   r   r   r   t  s    5r   r   c                   <    e Zd ZdZd Zd Zd Zd Zd
dZd Z	d Z
y	)TransferEncodingTests   It's just a flesh woundc                 `   t        j                  d      }t        d      |_        |j	                  dd       |j                  | j                         d       | j                  |j                  j                        \  }}}| j                  |      }| j                  || j                         y )NrV   r   r}   r~   T)encode_chunked)r   r   r   r   r   
endheaders
_make_body_parse_requestr   _parse_chunkedr   expected_body)r   r   _r   s       r   test_endheaders_chunkedz,TransferEncodingTest.test_endheaders_chunked  s    $$]3sO	$)$?((8
1d""4(t112r   c                 x   t        j                  d      }t        d      |_        |j	                  dd| j                         ddi       | j                  |j                  j                        \  }}}| j                  d|j                         D cg c]  }|j                          c}       | j                  |d   d       | j                  || j                         t        j                  d      }t        d      |_        |j	                  dd| j                  j                  d      ddi       | j                  |j                  j                        \  }}}| j                  d|j                         D cg c]  }|j                          c}       | j                  |d   d       | j                  || j                         t        j                  d      }t        d      |_        |j	                  dddd	id
| j                                | j                  |j                  j                        \  }}}| j                  d|D cg c]  }|j                          c}       | j                  |d   d	       | j                  | j                  |      | j                         y c c}w c c}w c c}w )NrV   r   r}   r~   Transfer-Encodingchunkedcontent-lengthlatin-1zgzip, chunkedT)r   r   r   )r   r   r   r   r   r   r   r   assertNotInkeysrp   r   r   ro   r   r   r   r   r   r   ks         r   test_explicit_headersz*TransferEncodingTest.test_explicit_headers  sH   $$]3sO	 	C*-@),L	N  ..tyy~~>7D)w||~+N!AGGI+NO!45yAt112 $$]3sO	C++229= ),	.  ..tyy~~>7D)w||~+N!AGGI+NO!45yAt112 $$]3sO	VS(/:" 	 	$  ..tyy~~>7D)w+G!AGGI+GH!45G,,T2D4F4FG5 ,O ,O ,Hs   J-
;J2
J7
c           	         dD ]  }t        j                  d      }t        d      |_        |j	                  dd| j                  |             | j                  |j                  j                        \  }}}| j                  |      }| j                  || j                         | j                  |d   d       | j                  d	|D cg c]  }|j                          c}        y c c}w )
N)FTrV   r   r}   r~   )empty_linesr   r   r  )r   r   r   r   r   r   r   r   r   r   r   r  rp   )r   r	  r   r   r   r   r  s          r   test_requestz!TransferEncodingTest.test_request  s    ) 	MK((7D"3DILLT___EG  $22499>>BAw&&t,DT4#5#56W%899E -7/Ka	/KL	M 0Ls   	C*c                 z   t        j                  d      }t        d      |_        |j	                  ddd       | j                  |j                  j                        \  }}}| j                  |d   d       | j                  d|D cg c]  }|j                          c}       | j                  |d	       y c c}w )
NrV   r   r}   r~   r0   r   r   r  s   0

)
r   r   r   r   r   r   r   r   r  rp   r  s         r   test_empty_bodyz$TransferEncodingTest.test_empty_body  s    $$]3sO	VS"%..tyy~~>7D!45yA)w+G!AGGI+GH|, ,Hs   B8
c              #      K   | j                   j                  d      }t        |      D ]-  \  }}|r	|dz  rd |t        |      dz
  k  r|dz    *| / y w)N    r   r   r   )r   rm   	enumeratern   )r   r	  r   idxlines        r   r   zTransferEncodingTest._make_body  sa     ""((."5) 	ICsQw	SZ!^#Tk!
	s   AAc                    |j                  d      }|d   }i }d}|t        |      k  rt        ||         dkD  r}||   j                  d      \  }}|j                  d      j                         }|j                  d      j                         ||<   |dz  }|t        |      k  rt        ||         dkD  r}||dj	                  ||dz   d        fS )N   
r   r   rl   r  )rm   rn   ro   r   r   )r   r   r   r   r   rL   keyr   s           r   r   z#TransferEncodingTest._parse_request  s    

7#(#e*nU1X!2Qx~~d+HC**Y'--/C::i0668GCLFA	 #e*nU1X!2 eAEFm!<<<r   c                    g }i }d}|j                  d      }	 |||dz    \  }}t        |d      }|dk(  r|dz  }nA| j                  |t        |             |j	                  |       |dz  }|t        |      kD  rncdj                  |      S )Nr   r  r      r   r   )rm   intr   rn   rs   r   )r   r   r   trailersrL   r   sizechunks           r   r   z#TransferEncodingTest._parse_chunked  s    

7#!A#,KD%tR=DqyQT3u:.KKFA 3u:~! $ xx~r   N)F)r7   r8   r9   r   r   r  r
  r  r   r   r   r0   r   r   r   r     s-    .M3$HLM -	=r   r   c                   J   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7y6)7	BasicTestc           
      f    | j                  h dt        t        t        d                  k         y )N>   r   r5   phrasedescription  )r   setdirr   r-   s    r   &test_dir_with_added_behavior_on_statusz0BasicTest.test_dir_with_added_behavior_on_status  s#    Bc#jY\oJ^F__`r   c                 j     G d dt         j                        }t        j                  |t               y )Nc                   `   e Zd ZdZdGdZed        Zed        Zed        Zed        Z	ed        Z
dZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7d5Z8d6Z9d7Z:d8Z;d9Z<d:Z=d;Z>d<Z?d=Z@d>ZAd?ZBd@ZCdAZDdBZEdCZFdDZGdEZHyF)H;BasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatusa  HTTP status codes and reason phrases

            Status codes from the following RFCs are all observed:

                * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
                * RFC 6585: Additional HTTP Status Codes
                * RFC 3229: Delta encoding in HTTP
                * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518
                * RFC 5842: Binding Extensions to WebDAV
                * RFC 7238: Permanent Redirect
                * RFC 2295: Transparent Content Negotiation in HTTP
                * RFC 2774: An HTTP Extension Framework
                * RFC 7725: An HTTP Status Code to Report Legal Obstacles
                * RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)
                * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)
                * RFC 8297: An HTTP Status Code for Indicating Hints
                * RFC 8470: Using Early Data in HTTP
            c                 \    t         j                  | |      }||_        ||_        ||_        |S r/   )r  __new___value_r  r  )clsr5   r  r  objs        r   r(  zCBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.__new__#  s,    kk#u-##
"-
r   c                 "    d| cxk  xr dk  S c S )Nd      r0   r-   s    r   is_informationalzLBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_informational+      d)c))))r   c                 "    d| cxk  xr dk  S c S )N   +  r0   r-   s    r   
is_successzFBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_success/  r0  r   c                 "    d| cxk  xr dk  S c S )N,    r0   r-   s    r   is_redirectionzJBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_redirection3  r0  r   c                 "    d| cxk  xr dk  S c S )N    r0   r-   s    r   is_client_errorzKBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_client_error7  r0  r   c                 "    d| cxk  xr dk  S c S )N  W  r0   r-   s    r   is_server_errorzKBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.is_server_error;  r0  r   )r-  Continuez!Request received, please continue)e   zSwitching Protocolsz.Switching to new protocol; obey Upgrade header)f   
Processing)g   zEarly Hints)r2  OKz#Request fulfilled, document follows)   CreatedzDocument created, URL follows)   Acceptedz/Request accepted, processing continues off-line)   zNon-Authoritative InformationzRequest fulfilled from cache)   z
No Contentz"Request fulfilled, nothing follows)   zReset Contentz"Clear input form for further input)   zPartial ContentzPartial content follows)   zMulti-Status)   zAlready Reported)   zIM Used)r6  zMultiple Choicesz,Object has several resources -- see URI list)i-  zMoved Permanently(Object moved permanently -- see URI list)i.  Found(Object moved temporarily -- see URI list)i/  z	See Otherz'Object moved -- see Method and URL list)i0  zNot Modifiedz)Document has not changed since given time)i1  z	Use Proxyz@You must use proxy specified in Location to access this resource)i3  zTemporary RedirectrT  )i4  zPermanent RedirectrR  )r:  zBad Requestz(Bad request syntax or unsupported method)  Unauthorizedz*No permission -- see authorization schemes)i  zPayment Requiredz"No payment -- see charging schemes)i  	Forbiddenz0Request forbidden -- authorization will not help)r   	Not FoundzNothing matches the given URI)i  zMethod Not Allowedz-Specified method is invalid for this resource)i  zNot Acceptablez%URI not available in preferred format)i  zProxy Authentication Requiredz7You must authenticate with this proxy before proceeding)i  zRequest Timeoutz"Request timed out; try again later)i  ConflictzRequest conflict)i  Gonez5URI no longer exists and has been permanently removed)i  zLength Requiredz"Client must specify Content-Length)i  zPrecondition Failedz Precondition in headers is false)i  zRequest Entity Too LargezEntity is too large)i  zRequest-URI Too LongzURI is too long)i  zUnsupported Media Typez!Entity body in unsupported format)i  zRequested Range Not SatisfiablezCannot satisfy request range)i  zExpectation Failedz'Expect condition could not be satisfied)i  zI'm a Teapotz5Server refuses to brew coffee because it is a teapot.)i  zMisdirected Requestz(Server is not able to produce a response)i  zUnprocessable Entity)i  Locked)i  zFailed Dependency)i  z	Too Early)i  zUpgrade Required)i  zPrecondition Requiredz8The origin server requires the request to be conditional)i  zToo Many RequestszOThe user has sent too many requests in a given amount of time ("rate limiting"))i  zRequest Header Fields Too LargezVThe server is unwilling to process the request because its header fields are too large)i  zUnavailable For Legal ReasonszOThe server is denying access to the resource as a consequence of a legal demand)r>  zInternal Server ErrorzServer got itself in trouble)i  zNot Implementedz&Server does not support this operation)i  zBad Gatewayz+Invalid responses from another server/proxy)i  zService Unavailablez8The server cannot process the request due to a high load)i  zGateway Timeoutz4The gateway server did not receive a timely response)i  zHTTP Version Not SupportedzCannot fulfill request)i  zVariant Also Negotiates)i  zInsufficient Storage)i  zLoop Detected)i  zNot Extended)i  zNetwork Authentication Requiredz7The client needs to authenticate to gain network accessN)r   )Ir7   r8   r9   rR   r(  propertyr/  r4  r8  r<  r@  CONTINUESWITCHING_PROTOCOLS
PROCESSINGEARLY_HINTSrF  CREATEDACCEPTEDNON_AUTHORITATIVE_INFORMATION
NO_CONTENTRESET_CONTENTPARTIAL_CONTENTMULTI_STATUSALREADY_REPORTEDIM_USEDMULTIPLE_CHOICESMOVED_PERMANENTLYFOUND	SEE_OTHERNOT_MODIFIED	USE_PROXYTEMPORARY_REDIRECTPERMANENT_REDIRECTBAD_REQUESTUNAUTHORIZEDPAYMENT_REQUIRED	FORBIDDEN	NOT_FOUNDMETHOD_NOT_ALLOWEDNOT_ACCEPTABLEPROXY_AUTHENTICATION_REQUIREDREQUEST_TIMEOUTCONFLICTGONELENGTH_REQUIREDPRECONDITION_FAILEDREQUEST_ENTITY_TOO_LARGEREQUEST_URI_TOO_LONGUNSUPPORTED_MEDIA_TYPEREQUESTED_RANGE_NOT_SATISFIABLEEXPECTATION_FAILEDIM_A_TEAPOTMISDIRECTED_REQUESTUNPROCESSABLE_ENTITYLOCKEDFAILED_DEPENDENCY	TOO_EARLYUPGRADE_REQUIREDPRECONDITION_REQUIREDTOO_MANY_REQUESTSREQUEST_HEADER_FIELDS_TOO_LARGEUNAVAILABLE_FOR_LEGAL_REASONSINTERNAL_SERVER_ERRORNOT_IMPLEMENTEDBAD_GATEWAYSERVICE_UNAVAILABLEGATEWAY_TIMEOUTHTTP_VERSION_NOT_SUPPORTEDVARIANT_ALSO_NEGOTIATESINSUFFICIENT_STORAGELOOP_DETECTEDNOT_EXTENDEDNETWORK_AUTHENTICATION_REQUIREDr0   r   r   CheckedHTTPStatusr&    s#   $ * * * * * * * * * * LH#F*J,KABEGCH-Q)PJVMOO.L6$G @!<LESI=LTI"<"<<K>L 6DI1I"A9N-K)6O:HID6O#4('$$# &5"/0+";IK#<#> "F 8(I6%L!!</(+-?)
%0!:O?K#LHO**&&D##> 0M.L/K+r   r  )enumIntEnum_test_simple_enumr   )r   r  s     r   test_simple_httpstatusz BasicTest.test_simple_httpstatus  s*    `	K `	KB 	0*=r   c                     t         j                  j                         D ]&  }| j                  |d       | j	                  |d       ( y)z1Checks that the statuses are in the 100-599 ranger-  r?  N)r   __members__valuesassertGreaterEqualassertLessEqual)r   members     r   test_httpstatus_rangezBasicTest.test_httpstatus_range  sB     !,,335 	.F##FC0  -	.r   c                     d}t         j                  j                         D ]L  }|D ]E  \  \  }}}t        ||      }||cxk  r|k  rn n| j	                  |       5| j                  |       G N y)z:Checks that the statuses belong to the standard categories)))r-  r.  r/  ))r2  r3  r4  ))r6  r7  r8  ))r:  r;  r<  ))r>  r?  r@  N)r   r  r  getattrr   assertFalse)r   
categoriesr  rp   uppercategorycategory_indicators          r   test_httpstatus_categoryz"BasicTest.test_httpstatus_category  sw    

 !,,335 	9F,6 9(%,VX%>"F+e+OO$67$$%789	9r   c                    d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j                  |j                                | j                  |j                         | j	                  |j                         d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         d}t        |      }t        j                  |      }| j                  t        j                  |j                         y )NHTTP/1.1 200 Ok

Textr   r      TextzHTTP/1.1 400.100 Not Ok

Text)r   r   r   r   r   rJ   r  isclosedclosedr   r(   assertRaisesBadStatusLiner   s       r   test_status_lineszBasicTest.test_status_lines  s     -$""4(

1s+)%g.(%

$4$""4(&..

;r   c                 d    t        j                  d      }| j                  t        |      d       y )Nr   zBadStatusLine("''"))r   r  r   repr)r   excs     r   test_bad_status_reprzBasicTest.test_bad_status_repr  s'    ""2&c$=>r   c                    d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j                  |j                                | j	                  |j                  d      d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y N*HTTP/1.1 200 Ok
Content-Length: 4

Textr      Te   xtr   r   r   r   r   rJ   r  r  r   r  r(   r   s       r   test_partial_readszBasicTest.test_partial_reads  s     B$""4(

1u-)1u-(%

$r   c                    d}t        |      }t        j                  |      }|j                          | j	                  |j                         d       | j                  |j                                | j	                  |j                         d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )Nz4HTTP/1.1 200 Ok
Content-Length: 13

Text
Anothers   Text
s   Another)r   r   r   r   r   rN   r  r  rJ   r   r  r(   r   s       r   test_mixed_readszBasicTest.test_mixed_reads  s     N$""4(

+6)j1(%

$r   c                 ~   d}t        |      }t        j                  |      }|j                          t	        d      }|j                  |      }| j                  |d       | j                  t        |      d       | j                  |j                                |j                  |      }| j                  |d       | j                  t        |      d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y r  r   r   r   r   	bytearrayreadintor   r   r  r  r   r  r(   r   r   r   r   brL   s         r   test_partial_readintosz BasicTest.test_partial_readintos  s     B$""4(

aLMM!Aq5))MM!Aq5)(%

$r   c                 t   d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )Nr  
   r  r   r   r   r   r   rJ   r   r  r  r  r(   r   s       r   test_partial_reads_past_endz%BasicTest.test_partial_reads_past_end  s    A$""4(

20(%

$r   c                    d}t        |      }t        j                  |      }|j                          t	        d      }|j                  |      }| j                  |d       | j                  t        |      d d d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )Nr  r     r  )r   r   r   r   r  r  r   r   r   r  r  r  r(   r  s         r   test_partial_readintos_past_endz)BasicTest.test_partial_readintos_past_end#  s    A$""4(

bMMM!Aq"1w/(%

$r   c                 6   d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j                  |j                                | j	                  |j                  d      d       | j	                  |j                  d      d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )Nr  r   r  r  r   r   r  r   s       r   $test_partial_reads_no_content_lengthz.BasicTest.test_partial_reads_no_content_length2  s     -$""4(

1u-)1u-1s+(%

$r   c                 8   d}t        |      }t        j                  |      }|j                          t	        d      }|j                  |      }| j                  |d       | j                  t        |      d       | j                  |j                                |j                  |      }| j                  |d       | j                  t        |      d       |j                  |      }| j                  |d       | j                  |j                                y )Nr  r   r  r  r   )r   r   r   r   r  r  r   r   r  r  r   r  s         r   (test_partial_readintos_no_content_lengthz2BasicTest.test_partial_readintos_no_content_lengthB  s     -$""4(

aLMM!Aq5))MM!Aq5)MM!A(r   c                    d}t        |      }t        j                  |      }|j                          | j	                  |j                  d      d       | j                  |j                                | j	                  |j                  d      d       | j	                  |j                  d      d       | j                  |j                                y )N+HTTP/1.1 200 Ok
Content-Length: 10

Textr   r  r  r   r   )	r   r   r   r   r   rJ   r  r  r   r   s       r   "test_partial_reads_incomplete_bodyz,BasicTest.test_partial_reads_incomplete_bodyU  s     C$""4(

1u-)1u-1s+(r   c                    d}t        |      }t        j                  |      }|j                          t	        d      }|j                  |      }| j                  |d       | j                  t        |      d       | j                  |j                                |j                  |      }| j                  |d       | j                  t        |      d       |j                  |      }| j                  |d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )Nr  r   r  r  r   r  r  s         r   &test_partial_readintos_incomplete_bodyz0BasicTest.test_partial_readintos_incomplete_bodyb  s	    C$""4(

aLMM!Aq5))MM!Aq5)MM!A(%

$r   c                     dD ]1  }| j                  t        j                  t        j                  |       3 dD ]S  \  }}}t        j                  |      }| j	                  ||j
                         | j	                  ||j                         U y )Nzwww.python.org:abczuser:password@www.python.org)z[fe80::207:e9ff:fe9b]:8000fe80::207:e9ff:fe9bi@  )zwww.python.org:80www.python.orgP   )www.python.org:r  r  )r  r  r  )[fe80::207:e9ff:fe9b]r  r  )[fe80::207:e9ff:fe9b]:r  r  )r  r   
InvalidURLr   r   r   r   r   hphpcs        r   test_host_portzBasicTest.test_host_portx  s     I 	LBf//1F1FK	LP 		(HB1 %%b)AQ'Q'		(r   c                     d}d}t        |      }t        j                  |      }|j                          |j	                  d      }| j                  ||       y )NzHTTP/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   r   r   r   r   r   )r   r   hdrsr#   cookiess         r   test_response_headerszBasicTest.test_response_headers  sT    O t"		++l+#&r   c                     t        dt              }t        j                  |d      }|j	                          |j                         r| j                  d       y y )N*HTTP/1.1 200 OK
Content-Length: 14432

r   r   )Did not expect response from HEAD request)r   rG   r   r   r   rJ   failr   r   r   s      r   test_read_headzBasicTest.test_read_head  sP      	
 ""47

99;IIAB r   c                    t        dt              }t        j                  |d      }|j	                          t        d      }|j                  |      dk7  r| j                  d       | j                  t        |      d       y )Nr  r   r     r   r          )
r   rG   r   r   r   r  r  r  r   r   )r   r   r   r  s       r   test_readinto_headzBasicTest.test_readinto_head  sp      	
 ""47

aL==q IIABq9-r   c                    dj                  d t        t        j                  dz         D              dz   }d|z   }t	        |      }t        j
                  |      }| j                  t        j                  d|j                         y )Nr   c              3   &   K   | ]	  }d |z    yw)zHeader%d: fooNr0   ).0is     r   	<genexpr>z2BasicTest.test_too_many_headers.<locals>.<genexpr>  s      F"# .1 Fs   r   zHTTP/1.1 200 OK
zgot more than \d+ headers)	r   r   r   _MAXHEADERSr   r   r   HTTPExceptionr   )r   r   r   r  r#   s        r   test_too_many_headerszBasicTest.test_too_many_headers  s}    ++ F',V-?-?!-C'DF FHNO%/t"v33;QWW	Fr   c           	      R   d}t        t        d      5 }t        j                  d      }t	        |      }||_        |j                  dd|       | j                  |j                  j                  |      |j                  d t        |       d|       d d d        y # 1 sw Y   y xY w)Ns_   GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

r$   rV   r   r   z != )open__file__r   r   r   r   r   r   r   r   rn   r   r   r   r   r   s        r   test_send_filezBasicTest.test_send_file  s    
 (D! 	;T((7Dd#DDILL-OODII00:YY~H.=: ;	; 	; 	;s   BBB&c                    d}t        j                  d      }t        d       }||_        |j	                  |       | j                  ||j                         d|_        |j	                  t        j                  d|             | j                  ||j                         d|_        |j	                  t        j                  |             | j                  ||j                         y )Ns"   this is a test this is only a testrV   r   r  )
r   r   r   r   sendr   r   arrayr:   r;   r   s       r   	test_sendzBasicTest.test_send  s    8$$]3$			(499-			%++c8,-499-			"**X&'499-r   c                     d  G fddt         j                        }d}t        j                  d      }t	        d      }||_        |j                   |              | j                  |j                  |       y )Nc               3   $   K   d d  d y w)Nr   data_twor0   r0   r   r   r   z/BasicTest.test_send_updating_file.<locals>.data  s     LJ   c                   *    e Zd ZdZ W         ZddZy)7BasicTest.test_send_updating_file.<locals>.UpdatingFiler#   c                 ,    t        | j                        S r/   )nextd)r   	blocksizes     r   rJ   z<BasicTest.test_send_updating_file.<locals>.UpdatingFile.read  s    DFF|#r   NrP   )r7   r8   r9   r)   r  rJ   )r   s   r   UpdatingFiler    s    DA$r   r  s   datarV   r   )	r:   
TextIOBaser   r   r   r   r  r   r   )r   r  r   r   r   r   s        @r   test_send_updating_filez!BasicTest.test_send_updating_file  sa    	
	$2== 	$ $$]3"~			,.!H-r   c                     d}d }t        j                  d      }t        d      }||_        |j	                  dd |       ddi       | j                  |j                  |       y )	Nsb   GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Content-Length: 11

onetwothreec               3   $   K   d d d y w)Ns   ones   twos   threer0   r0   r   r   r   z&BasicTest.test_send_iter.<locals>.body  s     LLNr  rV   r   r   r   r   11)r   r   r   r   r   r   r   r  s        r   test_send_iterzBasicTest.test_send_iter  s^    &	
 $$]3"~	UFDF-=t,DEH-r   c                 V   d}t        j                  d|      }t        d      }||_        d|z  dz   }|j	                  ddt        j                  |      d	d
i       | j                  |j                  d       |j                  j                  dd      d   }| j                  ||       y)z8Check that request() respects the configured block size.   rV   r  N   a   br   r~   r   9r      

r   )r   r   r   r   r   r:   r;   r   r   r   rm   )r   r  r   r   r   r   s         r   test_blocksize_requestz BasicTest.test_blocksize_request  s    	$$]iH$	)#d*UCH!58H#7NO++Q/yy{A.q1x(r   c                 "   d}t        j                  d|      }t        d      }||_        d|z  dz   }|j	                  t        j                  |             | j                  |j                  d       | j                  |j                  |       y)z5Check that send() respects the configured block size.r  rV   r  Nr  r   r   )
r   r   r   r   r  r:   r;   r   r   r   )r   r  r   r   r   s        r   test_blocksize_sendzBasicTest.test_blocksize_send  sx    	$$]iH$	)#d*		"**X&'++Q/H-r   c                     t        j                  d      }t        d      |_        | j	                  t
              5  |j                  dd|       d d d        y # 1 sw Y   y xY w)NrV   r   r}   test)r   r   r   r   r  	TypeErrorr   r   s     r   test_send_type_errorzBasicTest.test_send_type_error  sP    $$]3rN	y) 	/LL.	/ 	/ 	/s   AA!c                 X   t         }t        t        t        z   t        z         }t        j                  |d      }|j                          | j                  |j                         |       |j                          t        dd      D ]  }t        t        t        z   t        z         }t        j                  |d      }|j                          | j                  |j                  |      |j                  |      z   |j                         z   |       |j                           dD ]m  }t        t        |z         }t        j                  |d      }|j                          	 |j                          | j                  d       |j                          o y # t
        j                  $ rj}| j                  |j                  |       dt        |      z  }| j                  t!        |      |       | j                  t#        |      |       Y d }~d }~ww xY w# |j                          w xY w)Nr   r  r      r   zfoo
IncompleteRead expectedIncompleteRead(%d bytes read))chunked_expectedr   chunked_start
last_chunkchunked_endr   r   r   r   rJ   r(   r   r  IncompleteReadpartialrn   r  r   )r   r   r   r   rL   xr  expected_messages           r   test_chunkedzBasicTest.test_chunked  s   #-*4{BC""46

h/

 q" 	Amj8;FGD&&tE:DJJLTYYq\DIIaL8499;FQJJL	 ! 	Ama/0D&&tE:DJJL
		 		34

	 (( ;  H5#BS]#R   a*:;  Q)9::	; 

s1   #F3HH*A H
HHHH)c                    t         }t        |      }t        d      }t        t        t
        z   t        z         }t        j                  |d      }|j                          |j                  |      }| j                  |d | |       | j                  ||       |j                          t        dd      D ]  }t        t        t
        z   t        z         }t        j                  |d      }|j                          t        |      }|j                  |d|       }||j                  ||||z          z  }||j                  ||d        z  }| j                  |d | |       | j                  ||       |j                           dD ]n  }	t        t        |	z         }t        j                  |d      }|j                          	 |j                  |      }| j                  d       |j                          p y # t        j                   $ rj}| j                  |j"                  |       d	t        |      z  }
| j                  t%        |      |
       | j                  t'        |      |
       Y d }~d }~ww xY w# |j                          w xY w)
Nr   r   r  r   r+  r   r,  r-  r.  )r/  rn   r  r   r0  r1  r2  r   r   r   r  r   r(   r   
memoryviewr  r3  r4  r  r   )r   r   	nexpectedr  r   r   rL   mr  r5  r6  s              r   test_readinto_chunkedzBasicTest.test_readinto_chunked?  s'   #M	cN-*4{BC""46

MM!:I1I&

 q" 
	Amj8;FGD&&tE:DJJL1Aa!f%Aq1q5z**Aqu%%AQz	]H5Q	*JJL
	 ! 	Ama/0D&&tE:DJJL
MM!$ 		34

	 (( ;  H5#BS]#R   a*:;  Q)9::	; 

s1   G9I99I6A I1,I91I66I99Jc                    d}t        |t        z   t        z         }t        j                  |d      }|j                          | j                  |j                         d       | j                  |j                  d       | j                  |j                  d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )NEHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
r   r  r   r2  rF  )r   r1  r2  r   r   r   r   rJ   statusreasonr   r  r  r  r(   )r   r0  r   r   s       r   test_chunked_headzBasicTest.test_chunked_headj  s     	 -*4{BC""47

c*c*d+(%

$r   c                 T   d}t        |t        z   t        z         }t        j                  |d      }|j                          t        d      }|j                  |      }| j                  |d       | j                  t        |      d       | j                  |j                  d       | j                  |j                  d       | j                  |j                                | j                  |j                         |j!                          | j                  |j                         y )	Nr>  r   r  r  r   r  r2  rF  )r   r1  r2  r   r   r   r  r  r   r   r?  r@  r   r  r  r  r(   )r   r0  r   r   r  rL   s         r   test_readinto_chunked_headz$BasicTest.test_readinto_chunked_head~  s     	 -*4{BC""47

aLMM!Aq9-c*d+(%

$r   c                     t        d      }t        j                  |d      }|j                          | j	                  |j                         d       | j                  |j                                y )Nz.HTTP/1.1 200 OK
Content-Length: -1

Hello
r   r     Hello
)r   r   r   r   r   rJ   r   r  r  s      r   test_negative_content_lengthz&BasicTest.test_negative_content_length  sS    DF""46

l3(r   c                    t        d      }t        j                  |d      }|j                          	 |j	                          | j                  d       y # t        j                  $ r{}| j                  |j                  d       | j                  t        |      d       | j                  t        |      d       | j                  |j                                Y d }~y d }~ww xY w)Nz.HTTP/1.1 200 OK
Content-Length: 10

Hello
r   r  r-  rE  z-IncompleteRead(7 bytes read, 3 more expected))r   r   r   r   rJ   r  r3  r   r4  r  r   r   r  )r   r   r   r  s       r   test_incomplete_readzBasicTest.test_incomplete_read  s    RS""46


	1IIK II/0 $$ 	-QYY5T!WLNSVLNOODMMO,,	-s   A C$)A1CC$c                 "   t        dd      }t        j                  d      |_        | j	                  t
        fd       j                         }| j                  d|j                         | j                  d|j                  d             y )NzgHTTP/1.0 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Basic realm="example"
s   Content-LengthrV   c                  *     j                  ddd      S )Nr   /urlr   )r   )r   s   r   <lambda>z&BasicTest.test_epipe.<locals>.<lambda>  s    $,,uff"E r   rU  zBasic realm="example"zwww-authenticate)
r=   r   r   r   r  rB   getresponser   r?  r   )r   r   r   r   s      @r   
test_epipezBasicTest.test_epipe  s    < 	
 $$]3	'E	G!dkk*2(:;	=r   c                     dddz  z   dz   }t        j                  t        |            }| j                  t         j                  t         j
                  f|j                         y )NHTTP/1.1 200 Okr     r   )r   r   r   r  LineTooLongr  r   r   r   r   s      r   test_overflowing_status_linez&BasicTest.test_overflowing_status_line  sO     3;.7"":d#346--v/C/CDdjjQr   c                     dddz  z   dz   }t        j                  t        |            }| j                  t         j                  |j
                         y )NzHTTP/1.1 200 OK
X-Foo: barr#   rQ  z

)r   r   r   r  rR  r   rS  s      r   test_overflowing_header_linez&BasicTest.test_overflowing_header_line  sQ    ;')34 	 "":d#34&,,djj9r   c                 f   ddz  }t        j                  t        |            }| j                  t         j                        5 }|j                          d d d        | j                  dt        j                               | j                  dt        |j                               y # 1 sw Y   TxY w)NzHTTP/1.1 100 OK
r
i   zgot more than r   )	r   r   r   r  r   r   r   r   	exception)r   r   r   cms       r   'test_overflowing_header_limit_after_100z1BasicTest.test_overflowing_header_limit_after_100  s     	 "":d#34v334 	JJL	 	&BLL(9:iR\\!23	 	s   B''B0c                     dddz  z   dz   }t        j                  t        |            }|j                          | j	                  t         j
                  |j                         y )Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

r
   rQ  za
hello world
0

)r   r   r   r   r  rR  rJ   rS  s      r   test_overflowing_chunked_linez'BasicTest.test_overflowing_chunked_line  s\    1Ek 	 "":d#34

&,,dii8r   c                 r   d}t        |      }t        j                  |      }|j                          | j	                  |j                         d       | j                  |j                                | j                  |j                         |j                          | j                  |j                         y )NrP  r   r  r   s       r   test_early_eofzBasicTest.test_early_eof  s}     $""4(

c*(%

$r   c                    t        j                  d      }d  G fddt         j                        }||_        t	        d      |_        |j                  dd       | j                  t         j                  |j                         | j                  j                         | j                  |j
                  j                         y )NrV   c                       e Zd Z fdZy)+BasicTest.test_error_leak.<locals>.Responsec                 P    | t        j                  j                  | g|i | y r/   )r   r   r   )r   ra   rb   responses      r   r   z4BasicTest.test_error_leak.<locals>.Response.__init__  s&    ##,,T>C>2>r   N)r7   r8   r9   r   )rc  s   r   Responsera    s    ?r   rd  zInvalid status liner   r~   )r   r   r   response_classr   r   r   r  r  rM  r   r  r   )r   r   rd  rc  s      @r   test_error_leakzBasicTest.test_error_leak  s    $$]3	?v** 	?
 '45	UC &..0@0@A(		--.r   c                    d}t         dz   }t        t        |z   t        z   t        z         }t        j                  |d      }|j                          | j                  |j                         |       |j                          y )Nz3;foo=bar
abc
s   abcr   r  )r/  r   r0  last_chunk_extendedr2  r   r   r   r   rJ   r(   )r   extrar   r   r   s        r   test_chunked_extensionz BasicTest.test_chunked_extension  se    +#f,-%/2EEST""46

h/

r   c                     t         }t        t        t        z         }t	        j
                  |d      }|j                          | j                  |j                         |       |j                          y)z9some servers may serve up a short chunked encoding streamr   r  N)
r/  r   r0  r1  r   r   r   r   rJ   r(   r   r   r   r   s       r   test_chunked_missing_endz"BasicTest.test_chunked_missing_end  sP    #-*45""46

h/

r   c                 Z   t         }t        t        t        z   t        z   t
        z         }t        j                  |d      }|j                          | j                  |j                         |       | j                  |j                  j                         d       |j                          y)z&See that trailers are read and ignoredr   r  r   N)r/  r   r0  r1  r  r2  r   r   r   r   rJ   r&   r(   rl  s       r   test_chunked_trailerszBasicTest.test_chunked_trailers  su    #-*4x?+MN""46

h/)3/

r   c                    t         }d}t        t        t        z   t        z   t
        z   |z         }t        j                  |d      }|j                          | j                  |j                         |       | j                  |j                  j                         |j                  d             |j                          y)zDCheck that we don't read past the end of the chunked-encoding stream	extradatar   r  r   N)r/  r   r0  r1  r  r2  r   r   r   r   rJ   r&   r   r(   )r   r   rq  r   r   s        r   test_chunked_synczBasicTest.test_chunked_sync  s    #	-*4x?+MPYYZ""46

h/)9+;+;G+DE

r   c                 0   d}d}t        d|z   |z         }t        j                  |d      }|j                          | j	                  |j                         |       | j	                  |j                  j                         |       |j                          y)zBCheck that we don't read past the end of the Content-Length stream	   extradata
   Hello123
'   HTTP/1.1 200 OK
Content-Length: 10

r   r  N)r   r   r   r   r   rJ   r&   r(   r   rq  r   r   r   s        r   test_content_length_syncz"BasicTest.test_content_length_sync+  sw     	"JXUXaab""46

h/)95

r   c                 4   d}d}t        d|z   |z         }t        j                  |d      }|j                          | j	                  |j                  d      |g       | j	                  |j                  j                         |       |j                          y Nrt  ru  rv  r   r  i  )	r   r   r   r   r   	readlinesr&   rJ   r(   rw  s        r   test_readlines_content_lengthz'BasicTest.test_readlines_content_length7  s|     	"JXUXaab""46

-z:)95

r   c                 2   d}d}t        d|z   |z         }t        j                  |d      }|j                          | j	                  |j                  d      |       | j	                  |j                  j                         |       |j                          y rz  )	r   r   r   r   r   read1r&   rJ   r(   rw  s        r   test_read1_content_lengthz#BasicTest.test_read1_content_lengthB  sz     	"JXUXaab""46

D)84)95

r   c                 t   d}d}t        d|z   |z         }t        j                  |d      }|j                          | j	                  |j                  d      |       | j	                  |j                  d      d       | j	                  |j                  j                         |       |j                          y )Nrt  ru  rv  r   r  r  r   )	r   r   r   r   r   rN   r&   rJ   r(   rw  s        r   "test_readline_bound_content_lengthz,BasicTest.test_readline_bound_content_lengthM  s     	"JXUXaab""46

r*H5r*C0)95

r   c                 ~   d}d}t        d|dz  z   |z         }t        j                  |d      }|j                          | j	                  |j                  d      |dz         | j	                  |j                         |       | j	                  |j                  j                         |       |j                          y )	Nrt  ru  s'   HTTP/1.1 200 OK
Content-Length: 30

r   r   r     r   )	r   r   r   r   r   r~  rJ   r&   r(   rw  s        r   test_read1_bound_content_lengthz)BasicTest.test_read1_bound_content_lengthY  s     	"JXVWZWZccd""46

B!4h/)95

r   c                 z   t        j                  t        df      | j                  j                         d fd}t        j                  |      }|j                          | j                  |j                  t        d             t        j                  j                          }|j                  dd       |j                         }	 | j                  |j                   t        j"                         t        j                   |j%                               }	 |j'                  d       |j)                          	 |j	                          |j	                          |j                          | j                  d       y # |j)                          w xY w# |j	                          |j	                          w xY w)	Nr   c                  0   j                         \  } }| 5  | j                  d      5 }	 |j                         }|j                  d      sn#| j	                  d       |j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr$   r  s'   HTTP/1.1 200 Connection established

)acceptr+   rN   rstripr!   rJ   )r   addressreaderr  resultservs       r   
run_serverz2BasicTest.test_response_fileno.<locals>.run_serverk  s    "kkmOT7 't}}T* 'f!??,D;;w/  KL' ' ' ' ' 's#   BAB /B B		BB)targetr   r   z
dummy:1234)filenos   proxied data
)socketcreate_serverHOST
addCleanupr(   	threadingThreadstartr   floatr   r   getsocknamer   rM  r   r?  rF  r  r!   detach)r   r  threadr   rc  r  r  r  s         @@r   test_response_filenozBasicTest.test_response_filenoe  s2   ##T1I.

#
	' !!4U1X.$$d&6&6&89Y-##%		X__fii8X__%67A		+,
NNJJL!23 
NNJJLs%   AF F /F FF "F:c                      G d dt         j                        } |d      }t        d      |_        |j	                  dd       y)zv
        It should be possible to override the default validation
        behavior in putrequest (bpo-38216).
        c                       e Zd Zd Zy)RBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnectionc                      y r/   r0   r   r   s     r   _validate_pathzaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_path      r   N)r7   r8   r9   r  r0   r   r   UnsafeHTTPConnectionr        r   r  rV   r   r   z/ Nr   r   r   r   r   r   r  r   s      r   *test_putrequest_override_domain_validationz4BasicTest.test_putrequest_override_domain_validation  s9    
	6#8#8 	 $M2rN	w'r   c                      G d dt         j                        } |d      }t        d      |_        |j	                  ddd       y )	Nc                       e Zd Zd Zy)PBasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnectionc                      y r/   r0   r  s     r   _validate_hostz_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_host  r  r   N)r7   r8   r9   r  r0   r   r   r  r    r  r   r  zexample.com
r   r   r~   r   )	skip_hostr  r  s      r   (test_putrequest_override_host_validationz2BasicTest.test_putrequest_override_host_validation  s@    	6#8#8 	 $$56rN	 	sa0r   c                      G d dt         j                        } |d      }t        d      |_        |j	                  dd       y)z
        It should be possible to override the default encoding
        to transmit bytes in another encoding even if invalid
        (bpo-36274).
        c                       e Zd Zd Zy)IBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnectionc                 $    |j                  d      S )Nutf-8)r   )r   str_urls     r   _encode_requestzYBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnection._encode_request  s    ~~g..r   N)r7   r8   r9   r  r0   r   r   r  r    s    /r   r  rV   r   r   u   /☃Nr  r  s      r   !test_putrequest_override_encodingz+BasicTest.test_putrequest_override_encoding  s9    	/6#8#8 	/ $M2rN	v&r   N)8r7   r8   r9   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#  r%  r)  r7  r<  rA  rC  rF  rH  rN  rT  rV  rZ  r\  r^  rf  rj  rm  ro  rr  rx  r|  r  r  r  r  r  r  r  r0   r   r   r  r  
  s   ab>H.9$<*?%%%(
%%% )&)%,("'$C.F;..*. 
)	./@)V%(%.)1 ="R
:49
%/ 	

		

#4J(	1'r   r  c                       e Zd ZdZdZeej                  d      d j                  d      ZdZd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)ExtendedReadTestz*
    Test peek(), read1(), readline()
    zOHTTP/1.1 200 OK

hello world!
and now 
for something completely different
foohelloNr   HTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello worl
3
d!

9
and now 

23
for something completely different

3
foo
0

c                     t        | j                        }t        j                  |d      }|j	                          t        j                  |j                        |_        || _        y )Nr   r  )	r   r   r   r   r   r:   BufferedReaderfpr   r  s      r   setUpzExtendedReadTest.setUp  sH    $**%""46

##DGG,	r   c                    | j                   }|j                  j                  dfd	}||j                  _        g }	 |j                  d      }|r| j                  t	        |      d       |j                         }| j                  t	        |      t	        |             | j                  |j                  |             |j                  t	        |            }| j                  ||       n!|j                         }| j                  |       |j                  |       |sn| j                  dj                  |      | j                         y )Nc                 2     |       }| dk\  r|d |  S |d d S )Nr   r  r0   )rL   r  oldpeeks     r   mypeekz*ExtendedReadTest.test_peek.<locals>.mypeek  s)    
AAv!uSb6Mr   r   r   r   rP   )r   r  peekassertGreaterrn   r  r   r   rJ   r   r  rs   r   lines_expected)r   r   r  allr  p2r  r  s          @r   	test_peekzExtendedReadTest.test_peek  s   yy'',,	
 		!A""3q61-YY[''BQ8a 01yyR)  r*yy{  &JJt! " 	#(;(;<r   c                 |    | j                   }| j                  | j                   j                  | j                         y r/   )r   _verify_readlinerN   r  )r   r   s     r   test_readlinezExtendedReadTest.test_readline  s+    yydii00$2E2EFr   c                     g }	  |d      }|r3|dk7  r.t        |      dk  r | j                  |j                  d             |j                  |       |snR| j	                  dj                  |      |       y )Nr     foo   
r   )rn   r   r   rs   r   r   )r   rN   r   r  r  s        r   r  z!ExtendedReadTest._verify_readline  sm    A;Dt9q=OODMM%$89JJt  	#1r   c                       j                    fd}t        |      } j                  |j                   j                         y )Nc                  `    j                  d      } j                  t        |       d       | S )Nr  )r~  r  rn   )resr   r   s    r   r#   z&ExtendedReadTest.test_read1.<locals>.r
  s)    **Q-C  S1-Jr   )r   	Readlinerr  rN   r  )r   r#   	readlinerr   s   `  @r   
test_read1zExtendedReadTest.test_read1  s8    yy	 aL	i00$2E2EFr   c                     | j                   }g }	 |j                         }|sn|j                  |       %| j                  dj	                  |      | j
                         y Nr   )r   r~  rs   r   r   r  r   r   r  r   s       r   test_read1_unboundedz%ExtendedReadTest.test_read1_unbounded  sU    yy::<DJJt	 
 	#(;(;<r   c                     | j                   }g }	 |j                  d      }|sn-| j                  t        |      d       |j	                  |       A| j                  dj                  |      | j                         y )Nr  r   )r   r~  r  rn   rs   r   r   r  r  s       r   test_read1_boundedz#ExtendedReadTest.test_read1_bounded  sk    yy::b>D  TB/JJt  	#(;(;<r   c                 Z    | j                  | j                  j                  d      d       y )Nr   r   )r   r   r~  r-   s    r   test_read1_0zExtendedReadTest.test_read1_0&  s    +S1r   c                 p    | j                   j                  d      }| j                  dt        |             y Nr   )r   r  r  rn   )r   r  s     r   test_peek_0zExtendedReadTest.test_peek_0)  s(    IINN1QA'r   )r7   r8   r9   rR   r   findr   r  lines_chunkedr  r  r  r  r  r  r  r  r  r0   r   r   r  r    sm    	 
 5::g./077@N	 "=>G2G=	=2(r   r  c                       e Zd ZdZdZy)ExtendedReadTestChunkedz:
    Test peek(), read1(), readline() in chunked mode
    r  N)r7   r8   r9   rR   r   r0   r   r   r  r  .  s    	 
r   r  c                       e Zd ZdZd Zd Zy)r  zT
    a simple readline class that uses an arbitrary read function and buffering
    c                      || _         d| _        y r  )readfunc	remainder)r   r  s     r   r   zReadliner.__init__H  s     r   c                 t   g }d}| j                   }	 	 |j                  d      }|dk7  rn@|t        |      z   |k\  r||z
  dz
  }|j                  |       | j	                         }|sd}nW|dz  }|j                  |d |        ||d  | _         dj                  |      S #  dj                  |      | _          xY w)Nr   r  rQ   r   r   )r  r  rn   rs   r  r   )r   limitr   datalenrJ   r  s         r   rN   zReadliner.readlineL  s    ~~	ii&"9SY&%/'/A-CD!}}C  1HCKKTc
#!#$ZDN88D>!	 XXd^DNs   BB B7N)r7   r8   r9   rR   r   rN   r0   r   r   r  r  D  s    r   r  c                       e Zd Zd Zd Zd Zy)OfflineTestc                 
   dh}ddh}t        t              D ]J  }|j                  d      s||v rt        t        |      }t        |dd       dk(  s:|j	                  |       L | j                  t        j                  |       y )N	responsesHTTPMessageparse_headersr   r8   zhttp.client)r"  r   r   r  addassertCountEqual__all__)r   r   denylistr   module_objects        r   test_allzOfflineTest.test_allg  s}    = "?3K 	#Ds#tx'7#FD1M}lD9]JT"	# 	fnnh7r   c                 f    | j                  t        j                  t        j                     d       y )NrX  )r   r   r  rv  r-   s    r   test_responseszOfflineTest.test_responsesu  s#    ))&*:*:;[Ir   c                     g d}|D ]<  }| j                  |      5  | j                  t        t        |             d d d        > y # 1 sw Y   IxY w)N):r]  r^  r_  rF  ra  rb  rc  rd  re  rf  rg  ri  rj  rk  rl  rm  rn  ro  rp  rr  rs  rt  ru  rv  rw  rx  ry  rz  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  r  r  r  r`  r  )constant)r   r   hasattrr   )r   r   consts      r   test_client_constantsz!OfflineTest.test_client_constantsx  sV    ;
x  	8Eu- 8 678 8	88 8s    AA	N)r7   r8   r9   r  r  r  r0   r   r   r  r  f  s    8J@8r   r  c                   `    e Zd Zd Zd Zd Z ej                   ee	d       d      d        Z
y)SourceAddressTestc                 .   t        j                   t         j                  t         j                        | _        t	        j
                  | j                        | _        t	        j                         | _        | j                  j                          d | _
        y r/   )r  AF_INETSOCK_STREAMr  r   	bind_portr   find_unused_portsource_portlistenr   r-   s    r   r  zSourceAddressTest.setUp  s\    MM&..&2D2DE	!++DII6	(99;			r   c                     | j                   r!| j                   j                          d | _         | j                  j                          d | _        y r/   )r   r(   r  r-   s    r   tearDownzSourceAddressTest.tearDown  s3    99IIOODI			r   c                 (   t        j                  t        | j                  d| j                  f      | _        | j
                  j                          | j                  | j
                  j                  j                         d   | j                         y )Nr   source_addressr   )
r   r   r  r   r  r   r_   r   r   r  r-   s    r   testHTTPConnectionSourceAddressz1SourceAddressTest.testHTTPConnectionSourceAddress  sf    ))$		 "D$4$457			335a8$:J:JKr   HTTPSConnectionz'http.client.HTTPSConnection not definedc                 r    t        j                  t        | j                  d| j                  f      | _        y )Nr   r
  )r   r  r  r   r  r   r-   s    r    testHTTPSConnectionSourceAddressz2SourceAddressTest.testHTTPSConnectionSourceAddress  s,     **4 "D$4$457	r   N)r7   r8   r9   r  r  r  unittestskipIfr  r   r  r0   r   r   r  r    sC    L X__):;;>@7@7r   r  c                   "    e Zd ZdZd Zd Zd Zy)TimeoutTestNc                     t        j                   t         j                  t         j                        | _        t	        j
                  | j                        t        _        | j                  j                          y r/   )	r  r  r  r  r   r  r  PORTr  r-   s    r   r  zTimeoutTest.setUp  sE    MM&..&2D2DE	(22499=		r   c                 F    | j                   j                          d | _         y r/   )r  r(   r-   s    r   r  zTimeoutTest.tearDown  s    			r   c                 X   | j                  t        j                                t        j                  d       	 t	        j
                  t        t        j                        }|j                          t        j                  d        | j                  |j                  j                         d       |j                          | j                  t        j                                t        j                  d       	 t	        j
                  t        t        j                  d       }|j                          t        j                  d        | j                  |j                  j                         d        |j                          t	        j
                  t        t        j                  d      }|j                          | j                  |j                  j                         d       |j                          y # t        j                  d        w xY w# t        j                  d        w xY wN   )timeout)assertIsNoner  getdefaulttimeoutsetdefaulttimeoutr   r   r  r  r  r_   r   r   
gettimeoutr(   )r   httpConns     r   testTimeoutAttributez TimeoutTest.testTimeoutAttribute  s   
 	&2245  $	+,,T;3C3CDH$$T*113R8 	&2245  $	+,,T;3C3C6:<H$$T*113T: (({/?/?L113R8) $$T* $$T*s   8G8 ::H 8HH))r7   r8   r9   r  r  r  r   r0   r   r   r  r    s    D
r   r  c                       e Zd Zd Zd Zd Zy)PersistenceTestc                    d}|D ]"  \  }}}| j                  ||      5  dj                  ||      }t        |      }| j                  |j                         |j                  dd       |j                         5 }| j                  |j                  d u |        |j                          d d d        | j                  |j                  d u |        | j                  |j                  d       |j                  dd       | j                  |j                  |rdnd       d d d        % y # 1 sw Y   xY w# 1 sw Y   =xY w)	N))1.0r   F)r$  zConnection: keep-alive
T)1.1r   T)r%  zConnection: close
F)r$  zConnection: keep-ALIVE
T)r%  zConnection: cloSE
F)versionr   z4HTTP/{} 200 OK
{}Content-Length: 12

Dummy body
r   z/open-connectionr   z/subsequent-requestr   )
r   r   rT   r  r   r   rM  r   rJ   rW   )r   testsr&  r   reuser   r   rc  s           r   test_reuse_reconnectz$PersistenceTest.test_reuse_reconnect
  s:   
 ', 	F"GVUgf= F%
 &&)  04!!$)),U$67%%' $8$$TYY$%6E	BMMO$   d!2I>  !1!115U$9:  !1!111E#F F	F$ $F Fs%   AD8;0D,+A5D8,D51D88E	c                    d }t         j                  t        j                  f|t        ff}|D ]  \  }}| j                  |      5  t        d|      }|j                  dd       | j                  ||j                         | j                  |j                         |j                  dd       | j                  |j                  d       d d d         y # 1 sw Y   xY w)Nc                 p    t        j                  |       fd}|_        t        j                        S )z3Return BufferedReader that raises ECONNRESET at EOFc                 f    t         j                  j                  |       }|dk(  r
t               |S r  )r:   r;   r  ConnectionResetError)bufferr  streams     r   r  zNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readinto-  s.    zz**66:19.00r   )r:   r;   r  r  )r   r  r/  s     @r   make_reset_readerz<PersistenceTest.test_disconnected.<locals>.make_reset_reader*  s0    ZZ%F
 'FO$$V,,r   )rX  r   r   z/eof-response
/reconnectr   )r:   r;   r   RemoteDisconnectedr-  r   rT   r   r  rM  r  r   r   rW   )r   r0  r'  stream_factoryrX  r   s         r   test_disconnectedz!PersistenceTest.test_disconnected(  s    		- ZZ223 45
 */ 	6%NI	2 6/^DUO4!!)T-=-=>!!$)),UL1  !1!1156 6	66 6s   BCC	c                 ,   t        d      }|j                  ddddi       | j                  t        j                  |j
                         | j                  |j                         |j                  dd       | j                  |j                  d       y )	Ns   HTTP/1.1 100 Continue

r   r~   Expectz100-continuer   r1  r   )
rT   r   r  r   r2  rM  r  r   r   rW   r   s     r   test_100_closezPersistenceTest.test_100_closeC  s|    '

 	UC(N)CD&33T5E5EF$))$UL)))1-r   N)r7   r8   r9   r)  r4  r8  r0   r   r   r"  r"    s    F<66
.r   r"  c                       e Zd Zd Zd Zd Zd Zd Zej                  d        Z
d Z ej                  d      d	        Zd
 Zd Zd Z ej$                   eed       d      d        Zd Zy)	HTTPSTestc                 H    t        t        d      s| j                  d       y y )Nr  zssl support required)r  r   skipTestr-   s    r   r  zHTTPSTest.setUpR  s    v01MM01 2r   c                 "    ddl m}  || |      S )Nr   )make_https_server)certfile)test.ssl_serversr>  )r   r?  r>  s      r   make_serverzHTTPSTest.make_serverV  s    6 99r   c                     t        j                  t        t        j                  d      }| j                  |j                  d       y r  )r   r  r  r  r  r   r  )r   r  s     r   test_attributeszHTTPSTest.test_attributesZ  s0    ""4)9)92FB'r   c                    dd l }t        j                  d       t        j                  d      5  t        j                  dd      }| j                  |j                        5 }|j                  dd       d d d        | j                  j                  j                  d       d d d        y # 1 sw Y   8xY w# 1 sw Y   y xY w)Nr   networkself-signed.pythontest.net  r   r~   CERTIFICATE_VERIFY_FAILED)sslr   requiresr   transient_internetr   r  r  SSLErrorr   r   rX  r@  )r   rI  r  exc_infos       r   test_networkedzHTTPSTest.test_networked_  s    #--.JK 	U&&'CSIA""3<<0 &H		%%&X//668ST		U 	U& &	U 	Us#   2B7!B+4.B7+B4	0B77C c                    dd l }t        j                  d       t        j                  d      5  |j                         }t        j                  dd|      }|j                  dd       |j                         }|j                          | j                  d|j                  d	             |j                          d d d        y # 1 sw Y   y xY w)
Nr   rE  rF  rG  contextr   r~   nginxserver)rI  r   rJ  r   rK  _create_unverified_contextr   r  r   rM  r(   r   r   )r   rI  rQ  r  r   s        r   test_networked_noverificationz'HTTPSTest.test_networked_noverificationi  s    #--.JK 	446G&&'CS/68AIIeS!==?DGGIMM'4>>(#;<JJL	 	 	s   BCCc                 x   t        j                  d       t        j                  d      5  t	        j
                  dd      }|j                  dd       |j                         }|j                  d      }|j                          |j                          | j                  d|       d d d        y # 1 sw Y   y xY w)NrE  r  rG  r   r~   zcontent-typez	text/html)r   rJ  r   rK  r   r  r   rM  r   r(   r   )r   r  r   content_types       r   &test_networked_trusted_by_default_certz0HTTPSTest.test_networked_trusted_by_default_certw  s     	#--.>? 	5&&'7=AIIeS!==?D>>.9LJJLGGIMM+|4	5 	5 	5s   A<B00B9c           	         dd l }t        j                  d       d}t        j                  |      5  |j                  |j                        }| j                  |j                  |j                         | j                  |j                  d       |j                  t               	 t        j                  |d|      }|j                  dd       |j!                         }|j/                  d      }|j1                          |j1                          | j3                  d|       d d d        y # |j"                  $ rC}t%        |      }t'        j(                  d	|      rt+        j,                  d
| d| d       d }~ww xY w# 1 sw Y   y xY w)Nr   rE  rF  TrG  rP  r   r~   z(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.rS  rR  )rI  r   rJ  r   rK  
SSLContextPROTOCOL_TLS_CLIENTr   verify_modeCERT_REQUIREDcheck_hostnameload_verify_locations CERT_selfsigned_pythontestdotnetr   r  r   rM  rL  r   researchr  SkipTestr   r(   r   )	r   rI  selfsigned_pythontestdotnetrQ  r  r   ssl_errssl_err_strserver_strings	            r   test_networked_good_certz"HTTPSTest.test_networked_good_cert  se   #&B#--.IJ 	2nnS%<%<=GW00#2C2CDW33T:))*JK**+F3:<		%%}} !NN84MJJLGGIMM'=15	2 	2 << !'l 990+>"++{m ,9: ;BBC C 	2 	2s1   A3F %:D+AF +E=:>E88E==F  F	walltimec                    dd l }t        j                  d       t        j                  d      5  |j                  |j                        }|j                  t               t        j                  dd|      }| j                  |j                        5 }|j                  dd       d d d        | j                  j                  j                   d       d d d        y # 1 sw Y   8xY w# 1 sw Y   y xY w)	Nr   rE  rF  rG  rP  r   r~   rH  )rI  r   rJ  r   rK  rZ  r[  r_  CERT_localhostr   r  r  rL  r   r   rX  r@  )r   rI  rQ  r  rM  s        r   test_networked_bad_certz!HTTPSTest.test_networked_bad_cert  s     	#--.JK 	UnnS%<%<=G)).9&&'CSRYZA""3<<0 &H		%%&X//668ST	U 	U& &		U 	Us$   A$C)C&.C)C&	"C))C2c                 F   dd l }| j                  t              }t        j                  d|j
                        }| j                  |j                        5 }|j                  dd       d d d        | j                  j                  j                  d       y # 1 sw Y   0xY w)Nr   	localhostr   r~   rH  )rI  rA  rk  r   r  r   r  rL  r   r   rX  r@  )r   rI  rS  r  rM  s        r   test_local_unknown_certz!HTTPSTest.test_local_unknown_cert  s    !!.1"";<s||, 	"IIeS!	"++224OP	" 	"s   BB c                    dd l }| j                  t              }|j                  |j                        }|j                  t               t        j                  d|j                  |      }| j                  |j                         |j                  dd       |j                         }| j                  |j                         | j                  |j                  d       y )Nr   rn  rP  r   /nonexistentr   )rI  rA  rk  rZ  r[  r_  r   r  r   r  r(   r   rM  r   r?  r   rI  rS  rQ  r  r   s         r   test_local_good_hostnamez"HTTPSTest.test_local_good_hostname  s    !!.1..!8!89%%n5"";WM 			%(}}

#c*r   c                 B   dd l }| j                  t              }|j                  |j                        }|j                  t               t        j                  d|j                  |      }| j                  |j                        5  |j                  dd       d d d        d|_        t        j                  d|j                  |      }| j                  |j                        5  |j                  dd       d d d        d|_        t        j                  d|j                  |      }|j                  dd       |j                         }|j                          |j                          | j                  |j                   d	       y # 1 sw Y   xY w# 1 sw Y   xY w)
Nr   rn  rP  r   r~   TFrq  r   )rI  rA  CERT_fakehostnamerZ  r[  r_  r   r  r   r  CertificateErrorr   r^  rM  r(   r   r?  rr  s         r   test_local_bad_hostnamez!HTTPSTest.test_local_bad_hostname  sB   !!"34..!8!89%%&78"";WMs334 	"IIeS!	" "&"";WMs334 	"IIeS!	" "'"";WM			%(}}

		c*!	" 	"	" 	"s   F	&F	FFr  z)http.client.HTTPSConnection not availablec                     dD ]1  }| j                  t        j                  t        j                  |       3 dD ]S  \  }}}t        j                  |      }| j	                  ||j
                         | j	                  ||j                         U y )Nr  )r  )zwww.python.org:443r  rG  )r  r  rG  )r  r  rG  )r  r  rG  )r  r  rG  )r  r   r  r  r   r   r   r  s        r   r  zHTTPSTest.test_host_port  s    
 I 	MBf//1G1GL	M# 
	(HB1 &&r*AQ'Q'
	(r   c                    dd l }|j                  s| j                  d       t        j                  dd      }| j                  |j                  j                         |j                  |j                        }| j                  |j                         t        j                  dd|      }| j                  |j                  |       | j                  |j                  j                         |j                  |j                  t              }d|_        t        j                  dd|      }| j                  |j                  j                         y )Nr   zTLS 1.3 support requiredrn  rG  rP  )	cert_fileT)rI  HAS_TLSv1_3r<  r   r  r   _contextpost_handshake_authrZ  r[  r  assertIsrk  )r   rI  r  rQ  s       r   test_tls13_phazHTTPSTest.test_tls13_pha  s    MM45"";4

667..!8!89445"";WEajj'*778..!8!8N.S&*#"";WE

667r   N)r7   r8   r9   r  rA  rC  rN  rU  r   system_must_validate_certrX  rh  requires_resourcerl  ro  rs  rw  r  r  r  r   r  r  r0   r   r   r:  r:  P  s    2:(
U &&
5 '
52B Wz*
U +
UQ++2 X__):;;@B(B($8r   r:  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)RequestBodyTestz3Test cases where a request includes a message body.c                     t        j                  d      | _        t        d      x| j                  _        | _        | j                  | j                  _        y )NrV   r   )r   r   r   r   r   r-   s    r   r  zRequestBodyTest.setUp  s9    ))-8	%/^3				r   c                     t        j                  | j                  j                        }|j	                          t        j                  |      }||fS r/   )r:   r;   r   r   rN   r   r  r   fmessages      r   get_headers_and_fpz"RequestBodyTest.get_headers_and_fp  s;    JJtyy~~&	

&&q)zr   c                    ddgdfdf}|D ]  \  }}| j                  |      5  t        j                  d      | _        t	        d      x| j                  _        | _        | j                  j                  dd|       | j                         \  }}| j                  d	|       | j                  d
|       | j                  |j                  d      d       | j                  ||j                                d d d         y # 1 sw Y   xY w)Nr     bar   3
foo
3
bar
0

))r  r  r  rV   r   r   rK  zContent-Typer   r   r   )r   r   r   r   r   r   r   r  r  r   getrJ   )r   r   r   r   r   r  s         r   test_list_bodyzRequestBodyTest.test_list_body  s    
 fCDD
 $ 
	5ND(d# 	5"11-@	-7^;				!!%6002Q  5  !137  )<!=yI  16684	5 	5
	5	5 	5s   CC>>D	c                     | j                   j                  dddddi       | j                         \  }}| j                  d|j	                  d             | j                  dt        |j                                      y )Nr   rK  r   r   42r  r  )r   r   r  r   r  rn   rJ   r   r  r  s      r   test_manual_content_lengthz*RequestBodyTest.test_manual_content_length+  sj     			%+T2	4,,.
w{{+;<=CM*r   c                 d   | j                   j                  ddd       | j                         \  }}| j                  d|j	                                | j                  |j                                | j                  d|j                  d             | j                  d|j                                y )Nr   rK  r   
text/plain4r  s   body	r   r   r  r   get_content_typer  get_charsetr  rJ   r  s      r   test_ascii_bodyzRequestBodyTest.test_ascii_body4  s    		%0,,.
w'?'?'AB'--/0gkk*:;<!&&(+r   c                 d   | j                   j                  ddd       | j                         \  }}| j                  d|j	                                | j                  |j                                | j                  d|j                  d             | j                  d|j                                y )Nr   rK  u   bodyÁr  5r     bodyr  r  s      r   test_latin1_bodyz RequestBodyTest.test_latin1_body<  s    		%4,,.
w'?'?'AB'--/0gkk*:;<affh/r   c                 d   | j                   j                  ddd       | j                         \  }}| j                  d|j	                                | j                  |j                                | j                  d|j                  d             | j                  d|j                                y )Nr   rK  r  r  r  r  r  r  s      r   test_bytes_bodyzRequestBodyTest.test_bytes_bodyD  s    		%5,,.
w'?'?'AB'--/0gkk*:;<affh/r   c                    | j                  t        j                  t        j                         t	        t        j                  dd      5 }|j                  d       d d d        t	        t        j                  d      5 }| j                  j                  dd|       | j                         \  }}| j                  d|j                                | j                  |j                                | j                  |j                  d             | j                  d	|j                  d
             | j                  d|j                                d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nwr  )encodingr   r   rK  r  r  r   ztransfer-encodings   4
body
0

)r  r   unlinkTESTFNr  writer   r   r  r   r  r  r  r  rJ   r  s      r   test_text_file_bodyz#RequestBodyTest.test_text_file_bodyL  s$   	(()*:*:;)""C': 	aGGFO	)""W5 		BIIeVQ/002JGQ\7+C+C+EFg1134 gkk*:;<Y4G(HI6A		B 		B	 			B 		Bs   E CE&E#&E/c                    | j                  t        j                  t        j                         t	        t        j                  d      5 }|j                  d       d d d        t	        t        j                  d      5 }| j                  j                  dd|       | j                         \  }}| j                  d|j                                | j                  |j                                | j                  d|j                  d             | j                  d	|       | j                  d
|j                                d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nwbr  r$   r   rK  r  r   r   r   s   5
body
0

)r  r   r  r  r  r  r   r   r  r   r  r  r  r  r  rJ   r  s      r   test_binary_file_bodyz%RequestBodyTest.test_binary_file_body[  s   	(()*:*:;)""D) 	!QGGK 	!)""D) 	FQIIeVQ/002JGQ\7+C+C+EFg1134Y4G(HI-w7:AFFHE	F 	F	! 	!	F 	Fs   	E	=CE	EEN)r7   r8   r9   rR   r  r  r  r  r  r  r  r  r  r0   r   r   r  r  	  s4    =#
5(+,00BFr   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)HTTPResponseTestc                     d}t        |      }t        j                  |      | _        | j                  j	                          y )NzXHTTP/1.1 200 Ok
My-Header: first-value
My-Header:                 second-value

Text)r   r   r   r   r   )r   r   r   s      r   r  zHTTPResponseTest.setUpk  s3    *$''-			r   c                     | j                   j                  d      }| j                  |d       | j                   j                  dd      }| j                  |d       y )Nz	My-Headerzfirst-value, second-valuezsome defaultr   r   r   r   r   s     r   test_getting_headerz$HTTPResponseTest.test_getting_headerr  sN    $$[1!<=$$[.A!<=r   c                 `    | j                   j                  dd      }| j                  |d       y )NNo-Such-Headerzdefault-valuer  r  s     r   3test_getting_nonexistent_header_with_string_defaultzDHTTPResponseTest.test_getting_nonexistent_header_with_string_defaulty  s)    $$%5G1r   c                     | j                   j                  dddg      }| j                  |d       | j                   j                  dd      }| j                  |d       y )Nr  defaultr  zdefault, values)r  r  r  r  s     r   5test_getting_nonexistent_header_with_iterable_defaultzFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_default}  sX    $$%5	87LM!23$$%57LM!23r   c                 ^    | j                   j                  d      }| j                  |d        y )Nr  r  r  s     r   /test_getting_nonexistent_header_without_defaultz@HTTPResponseTest.test_getting_nonexistent_header_without_default  s'    $$%56&r   c                 b    | j                   j                  dd      }| j                  |d       y )Nr  r   )r  r  r  s     r   test_getting_header_defaultintz/HTTPResponseTest.test_getting_header_defaultint  s,    $$%5b$A$r   N)	r7   r8   r9   r  r  r  r  r  r  r0   r   r   r  r  i  s     >24'%r   r  c                   ~    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TunnelTestsc                     d}d| _         t        j                  | _        t        j                  | j                         | _        | j                  |      | j
                  _        y )Nz:HTTP/1.1 200 OK

HTTP/1.1 200 OK
Content-Length: 42

z	proxy.com)r   r   	HTTP_PORTr   r   r   r[   )r   response_texts     r   r  zTunnelTests.setUp  sO    ) 	
  	$$	))$))4	'+'>'>}'M		$r   c                 8    | j                   j                          y r/   )r   r(   r-   s    r   r  zTunnelTests.tearDown  s    		r   c                     dfd	}|S )Nc                 ,    t        | d   | d         S )Nr   r   r   r   r   )r  r  r  r  s      r   rZ   z9TunnelTests._create_connection.<locals>.create_connection  s    m'!*71:NNr   NNr0   )r   r  rZ   s    ` r   r[   zTunnelTests._create_connection  s    	O  r   c                    d}d}ddi}|j                         }d||fz  |d<   | j                  j                  |||       | j                  j                  dd	d
       | j	                  | j                  j
                  j                  | j                         | j	                  | j                  j
                  j                  | j                         | j	                  | j                  j                  |       | j	                  | j                  j                  |       | j	                  | j                  j                  |       y )Ndestination.com"  
User-Agent!Mozilla/5.0 (compatible, MSIE 11)%s:%drz   r   r   r   r~   r   )copyr   
set_tunnelr   r   r   r   r   _tunnel_host_tunnel_port_tunnel_headers)r   tunnel_hosttunnel_porttunnel_headerstunnel_headers_afters        r   2test_set_tunnel_host_port_headers_add_host_missingz>TunnelTests.test_set_tunnel_host_port_headers_add_host_missing  s   '&(KL-224'.+{1K'KV$		[{%3 	 	5		&#r*,,dii8,,dii8//=//=224HIr   c                 b   d}d}dd||fz  d}| j                   j                  |||       | j                   j                  ddd	       | j                  | j                   j                  j
                  | j
                         | j                  | j                   j                  j                  | j                         | j                  | j                   j                  |       | j                  | j                   j                  |       | j                  | j                   j                  |       y )
Nr  r  r  r  r  rz   r  r   r~   r   
r   r  r   r   r   r   r   r  r  r  r   r  r  r  s       r   4test_set_tunnel_host_port_headers_set_host_identicalz@TunnelTests.test_set_tunnel_host_port_headers_set_host_identical  s    '(K")[+,F"FH		[{%3 	 	5		&#r*,,dii8,,dii8//=//=22NCr   c                 ^   d}d}dddz  d}| j                   j                  |||       | j                   j                  dd	d
       | j                  | j                   j                  j
                  | j
                         | j                  | j                   j                  j                  | j                         | j                  | j                   j                  |       | j                  | j                   j                  |       | j                  | j                   j                  |       y )Nr  r  r  r  )rV   ih  r  r  r   r~   r   r  r  s       r   4test_set_tunnel_host_port_headers_set_host_differentz@TunnelTests.test_set_tunnel_host_port_headers_set_host_different  s    '(K"),A"AC		[{%3 	 	5		&#r*,,dii8,,dii8//=//=22NCr   c                     | j                   j                          | j                  t        | j                   j                  d       y )Nr  )r   r_   r  RuntimeErrorr  r-   s    r   &test_disallow_set_tunnel_after_connectz2TunnelTests.test_disallow_set_tunnel_after_connect  s1    		,		(<(<+	-r   c                 r   dt         j                  d}| j                  j                  |d   j	                  d             | j                  j                  ddd       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  | j                         | j                  d|z  | j                  j                  j                         | j                  d	|z  | j                  j                  j                         y 
N   destination.com   host   portr  r   r   r~   r   ?   CONNECT %(host)s:%(port)d HTTP/1.1
Host: %(host)s:%(port)d

!   HEAD / HTTP/1.1
Host: %(host)s
r   r  r   r  ro   r   r   r   r   r   r   r   r   r  s     r   test_connect_with_tunnelz$TunnelTests.test_connect_with_tunnel      '%%
 			QwZ..w78		&#r*,,dii8,,dii8 9;<=iinn))	+ 	>Biinn))	+r   c                 |   dt         j                  d}| j                  j                  |d   j	                  d      |d          | j                  j                  ddd	       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  | j                         | j                  d
|z  | j                  j                  j                         | j                  d|z  | j                  j                  j                         y )Nr  r  r  r   r  r   r   r~   r   r  r  r  r  s     r   *test_connect_with_tunnel_with_default_portz6TunnelTests.test_connect_with_tunnel_with_default_port  s    '%%
 			QwZ..w7ajI		&#r*,,dii8,,dii8 9;<=iinn))	+ 	>Biinn))	+r   c                 `   ddd}| j                   j                  |d   j                  d      |d          | j                   j                  dd	d
       | j	                  | j                   j
                  j                  | j                         | j	                  | j                   j
                  j                  | j                         | j                  d|z  | j                   j
                  j                         | j                  d|z  | j                   j
                  j                         y )Nr  r  r  r  r   r  r  r   r~   r   r  s*   HEAD / HTTP/1.1
Host: %(host)s:%(port)d
)
r   r  ro   r   r   r   r   r   r   r   r  s     r   .test_connect_with_tunnel_with_nonstandard_portz:TunnelTests.test_connect_with_tunnel_with_nonstandard_port  s    '
 			QwZ..w7ajI		&#r*,,dii8,,dii8 9;<=iinn))	+ 	G!Kiinn))	+r   c                    ddt         j                  d}| j                  j                  |d   j	                  d      d|d   j	                  d      i       | j                  j                  d	d
d       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  | j                         | j                  d|z  | j                  j                  j                         | j                  d|z  | j                  j                  j                         y )Nr  s   example.com:9876)r     tunnel_host_headerr  r  r   r  r  r7  r   r~   r   sD   CONNECT %(host)s:%(port)d HTTP/1.1
HOST: %(tunnel_host_header)s

r  r  r  s     r   3test_connect_with_tunnel_with_different_host_headerz?TunnelTests.test_connect_with_tunnel_with_different_host_header	  s   '#6%%

 			gJg&Q45<<WEF 	 	H 			&#r*,,dii8,,dii8 >@ABiinn))	+ 	>Biinn))	+r   c                 r   dt         j                  d}| j                  j                  |d   j	                  d             | j                  j                  ddd       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  | j                         | j                  d|z  | j                  j                  j                         | j                  d	|z  | j                  j                  j                         y r  r  r  s     r   'test_connect_with_tunnel_different_hostz3TunnelTests.test_connect_with_tunnel_different_host	  r  r   c                    d}d|j                  d      t        j                  fz  }d||fz  }| j                  j	                  |       | j                  j                  ddd       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  t        j                         | j                  || j                  j                  j                         y )Nu	   δπθ.grs   %s:%didnas!   CONNECT %s HTTP/1.1
Host: %s

r   r~   r   )r   r   r  r   r  r   r   r   r   r   r   r   )r   dest	dest_portr   s       r   test_connect_with_tunnel_idnaz)TunnelTests.test_connect_with_tunnel_idna"	  s    &F 3V5E5EFF	=yA" "		T"		&#r*,,dii8,,f.>.>?h		 3 34r   c                 D   t         j                  j                  | j                  d      5 }| j                  j	                  d       | j                  j                          | j                  j                  dd       ddd       j                          | j                  t        |j                        dd|j                          |j                  d	   d   d	   }| j                  d
|       | j                  |j                  d      d|       y# 1 sw Y   xY w)z8Regresstion test for https://bugs.python.org/issue43332.r  r  r   r~   Nr   z!unexpected number of send calls: )r   r   s   CONNECT destination.comr"  zunexpected proxy data sent )r   patchobjectr   r  r_   r   assert_calledr  rn   
mock_callsr   r   r   )r   	mock_sendproxy_setup_data_sents      r   0test_tunnel_connect_single_send_connection_setupz<TunnelTests.test_tunnel_connect_single_send_connection_setup-	  s   ZZtyy&1 	*YII  !23IIIIeS)	* 	!I(()17	8L8L7MN 	 	P !* 4 4Q 7 :1 =02GH%..{;12G1JK 	 	M	* 	*s   ADDc                 r   dt         j                  d}| j                  j                  |d   j	                  d             | j                  j                  ddd       | j                  | j                  j                  j                  | j                         | j                  | j                  j                  j                  | j                         | j                  d|z  | j                  j                  j                         | j                  d	|z  | j                  j                  j                         y )
Nr  r  r  r   r   r~   r   r  s    PUT / HTTP/1.1
Host: %(host)s
r  r  s     r   test_connect_put_requestz$TunnelTests.test_connect_put_request>	  s    '%%
 			QwZ..w78		%b),,dii8,,dii8 9;<=iinn))	+ 	=Aiinn))	+r   c                    d}dj                  |      }| j                  j                  d       | j                  |      | j                  _        | j                  j	                  d       t        j                         5 }| j                  j                  ddd       d d d        j                         j                         }| j                  dj                  |      |       y # 1 sw Y   IxY w)	Nz
X-Dummy: 1zHTTP/1.0 200 OK
{}

r   r  r   r~   r   z
header: {})r   r   set_debuglevelr[   r  r   r   r   r   r   r   )r   expected_headerr  r   r   s        r   test_tunnel_debuglogz TunnelTests.test_tunnel_debuglogM	  s    &7>>O		  #'+'>'>}'M		$		./$$& 	.&IIeS"-	.!,,.l))/:EB	. 	.s   >C$$C-c                 l   d}dj                  dj                  |            }| j                  |      | j                  _        | j                  j	                  d       | j                  j                  ddd       | j                  j                         }| j                  ||j                                y )NzX-Dummy1HTTP/1.0 200 OK
{0}

:r  r   r~   r   )	r   r   r[   r   r  r   get_proxy_response_headersr   itemsr   r  r  r   s       r   test_proxy_response_headersz'TunnelTests.test_proxy_response_headersZ	  s    * &/!:; 	
 (,'>'>}'M		$		./		%b)))668ow}}7r   c                    d}dj                  dj                  |            }| j                  |      | j                  _        | j                  j	                  ddd       | j                  j                         }| j                  |       y )Nr  r  r  r   r~   r   )r   r   r[   r   r   r  r  r  s       r   test_no_proxy_response_headersz*TunnelTests.test_no_proxy_response_headersh	  ss    * &/!:; 	
 (,'>'>}'M		$		%b)))668'"r   c                 6   d dfd	}|| j                   _        | j                   j                  d       d }	 | j                   j                  ddd       | j                  |       | j                  j                         y # t        $ r}|}Y d }~=d }~ww xY w)Nc                 0    t        d| d   | d         S )NzHTTP/1.1 404 NOT FOUND

r   r   r  r  )r  r  r  r   s      r   r[   z8TunnelTests.test_tunnel_leak.<locals>._create_connectionx	  s%    0QZQZD
 Kr   r  r   r~   r   r  )r   r[   r  r   rB   r   r   r   )r   r[   r  er   s       @r   test_tunnel_leakzTunnelTests.test_tunnel_leaku	  s    	 (:		$		./	IIfc2. 	S!(()	  	C	s   B 	BBBN)r7   r8   r9   r  r  r[   r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r0   r   r   r  r    sg    	N!
JDD-+++$+$+	5M"+C8#*r   r  __main__r   )	verbosity)<r  rC   httpr   r   r:   r   osr	  ra  r  r  r  r   TestCaser'  r   test.supportr   r   requires_working_socketpathdirnamer  herer   rk  ru  r`  r0  r/  chunk_extensionr1  rh  r  r2  r  r   r=   r;   rG   r   rT   re   r   r   r  r  r  r  r  r  r  r"  r:  r  r  r  r7   mainr0   r   r   <module>r%     s	     # 	  	  	      " &   t ,	wwx dM2GGLL~6 #%77<<6W#X  	-  N 
O+f4 - B* 2:: $2v44 2"j;( j;Z5h 5,}8 }@d' d'Nz(x z(z. , DR8( R8j7 7>+( +\E.h E.Pv8 v8r]Fh ]F@!%x !%F~*( ~*B zHMMA r   