
    <en^                    <   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Zd dlmZ ej        Zd dlmZ d dlmZ d dlmZ d dlmZ  ej        d	           ej                            e          Zej                            ed
          Zej                            ed          Zej                            ed          ZdZdZ dZ!dZ"de!z   dz   Z#dZ$dZ%ej&        Z& G d d          Z' G d de'          Z( G d dej)                  Z* G d dej+                  Z, G d de          Z- G d de          Z. G d  d!e          Z/ G d" d#e          Z0 G d$ d%e          Z1 G d& d'e1          Z2 G d( d)          Z3 G d* d+e          Z4 G d, d-e          Z5 G d. d/e          Z6 G d0 d1e          Z7 G d2 d3e          Z8 G d4 d5e          Z9 G d6 d7e          Z: G d8 d9e          Z;e<d:k    r ej=        d;<           dS dS )=    N)client
HTTPStatus)mock)support)	os_helper)socket_helper)warnings_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                   F    e Zd Zej        ddfdZd ZddZd Zd Z	d Z
dS )	
FakeSocketNc                     t          |t                    r|                    d          }|| _        || _        d| _        d| _        d| _        || _        || _	        d S )Nascii    r   F)

isinstancestrencodetext	fileclassdatasendall_callsfile_closedhostport)selfr   r   r   r   s        (/usr/lib/python3.11/test/test_httplib.py__init__zFakeSocket.__init__7   s\    dC   	(;;w''D	"	 				r   c                 F    | xj         dz  c_         | xj        |z  c_        d S )N   )r   r   r   r   s     r   sendallzFakeSocket.sendallB   s*    a		T				r   c                     |dk    r|dk    rt          j                    |                     | j                  | _        | j        | j        _        | j        S )Nrrb)r   UnimplementedFileModer   r   file
file_closeclose)r   modebufsizes      r   makefilezFakeSocket.makefileF   sJ    3;;44<<.000NN49--	/	yr   c                     d| _         d S )NT)r   r   s    r   r(   zFakeSocket.file_closeN   s    r   c                     d S N r.   s    r   r)   zFakeSocket.closeQ       r   c                     d S r0   r1   )r   leveloptnamevalues       r   
setsockoptzFakeSocket.setsockoptT   r2   r   r0   )__name__
__module____qualname__ioBytesIOr   r"   r,   r(   r)   r7   r1   r   r   r   r   6   s        ')z4 	 	 	 	                r   r   c                        e Zd Zd Zd Zd ZdS )EPipeSocketc                 J    t                               | |           || _        d S r0   )r   r   pipe_trigger)r   r   r@   s      r   r   zEPipeSocket.__init__Y   s&    D$'''(r   c                 l    | j         |v rt          t          j        d          | xj        |z  c_        d S )Ngotcha)r@   OSErrorerrnoEPIPEr   r!   s     r   r"   zEPipeSocket.sendall^   s6    $$%+x000		T				r   c                     d S r0   r1   r.   s    r   r)   zEPipeSocket.closec   r2   r   N)r8   r9   r:   r   r"   r)   r1   r   r   r>   r>   W   sA        ) ) )
  
    r   r>   c                   "    e Zd ZdZddZddZdS )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                 p    t           j                            | |          }|dk    rt          d          |S Nr   zcaller tried to read past EOF)r;   r<   readAssertionError)r   nr   s      r   rL   zNoEOFBytesIO.readl   s4    ztQ''3;; !@AAAr   Nc                 p    t           j                            | |          }|dk    rt          d          |S rK   )r;   r<   readlinerM   )r   lengthr   s      r   rP   zNoEOFBytesIO.readliner   s6    z""4003;; !@AAAr   rI   r0   )r8   r9   r:   __doc__rL   rP   r1   r   r   rH   rH   f   sF         
        r   rH   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                 ~    d| _         t                                          d           || _        | j        | _        d S )Nr   example.com)connectionssuperr   fake_socket_argscreate_connection_create_connection)r   args	__class__s     r   r   z!FakeSocketHTTPConnection.__init__{   s<    ''' $"&"8r   c                 d    | xj         dz  c_         t                                                      S )z.Count the number of times connect() is invokedr    )rX   rY   connect)r   r^   s    r   r`   z FakeSocketHTTPConnection.connect   s+    Aww   r   c                     t          | j         S r0   )r   rZ   )r   poskws      r   r[   z*FakeSocketHTTPConnection.create_connection   s    4011r   )r8   r9   r:   rS   r   r`   r[   __classcell__)r^   s   @r   rU   rU   x   sf        JJ9 9 9 9 9! ! ! ! !
2 2 2 2 2 2 2r   rU   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
HeaderTestsc                     G d dt                     }dD ]}dD ]}t          j        d          }t          d          |_         |            |_        d}i }|rt          t          |                    ||<   |                    dd	||           | 	                    |j        j
        |                                         d
           d S )Nc                       e Zd Zd Zd ZdS );HeaderTests.test_auto_headers.<locals>.HeaderCountingBufferc                     i | _         d S r0   )countr.   s    r   r   zDHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.__init__   s    


r   c                 F   |                     d          }t          |          dk    r]|d                             d                                          }| j                            |d           | j        |xx         dz  cc<   t                              | |           d S )N   :r    r   r   )splitlendecodelowerrk   
setdefaultlistappend)r   itemkvlcKeys       r   rt   zBHeaderTests.test_auto_headers.<locals>.HeaderCountingBuffer.append   s    ZZ%%r77Q;;qELL117799EJ))%333Ju%%%*%%%D$'''''r   Nr8   r9   r:   r   rt   r1   r   r   HeaderCountingBufferri      s2             ( ( ( ( (r   ry   )TF)Content-lengthHostzAccept-encodingrW   blahblahblahspamspamspamPOST/r    )rs   r   HTTPConnectionr   sock_bufferr   ro   requestassertEqualrk   rq   )r   ry   explicit_headerheaderconnbodyheaderss          r   test_auto_headerszHeaderTests.test_auto_headers   s    
	( 
	( 
	( 
	( 
	(4 
	( 
	( 
	(  + 	H 	HOE 
H 
H,];;&~66	3355%" 5&)#d))nnGFOVS$888  !3FLLNN!CQGGGG
H	H 	Hr   c                     G d dt                     }d}d}t          j        ||          D ]\  }}t          j        d          }t          d           |_         |            |_        |                    |d|           | 	                    |j        j
        dd                    |                     d	}|D ]}t          j        d          }t          d           |_         |            |_        |                    |dd            | 	                    |j        j
        d d
                    |                     |D ]}t          j        d          }t          d           |_         |            |_        |                    |dd           | 	                    |j        j
        dd                    |                     t          j        ||          D ]}t          j        d          }t          d           |_         |            |_        |                    |dd           | 	                    |j        j
        dd                    |                     d S )Nc                       e Zd Zd Zd ZdS )?HeaderTests.test_content_length_0.<locals>.ContentLengthCheckerc                 H    t                               |            d | _        d S r0   )rs   r   content_lengthr.   s    r   r   zHHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.__init__   s"    d###&*###r   c                    |                     dd          }t          |          dk    r=|d                                         dk    r|d                                         | _        t
                              | |           d S )Nrm   r    r   s   content-length)rn   ro   rq   stripr   rs   rt   )r   ru   rv   s      r   rt   zFHeaderTests.test_content_length_0.<locals>.ContentLengthChecker.append   si    ZZa((r77Q;;2a5;;==4E#E#E*,Q%++--D'D$'''''r   Nrx   r1   r   r   ContentLengthCheckerr      s2        + + +( ( ( ( (r   r   )N )PUTr~   PATCHrW   r      0z%Header Content-Length incorrect on {})GETCONNECTDELETEHEADOPTIONSTRACEz.Header Content-Length set for empty body on {}r       1)rs   	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H 	 	LFD(77D"4((DI//11DLLLd++++T7>>vFF    
 + 	 	F(77D"4((DI//11DLLLd++++T@GGOO    + 	 	F(77D"4((DI//11DLLLb)))+T7>>vFF     o&:<MNN 	 	F(77D"4((DI//11DLLLc***+T7>>vFF   	 	r   c                    t          j        d          }t          d           |_        |                    dd           |                    dd           |                     d|j                   |                    dd           |                     d	|j                   |                    d
d           |                     d|j                   |                    dd           |                     d|j                   |                    ddd           |                     d|j                   |                    dd           |                     d|j                   |                    dd           |                     d|j                   |                    dd           |                     d|j                   |                    dd           |                     d|j                   |                    d d!           |                     d"|j                   |                    d#d$           |                     d%|j                   |                    d&d$           |                     d'|j                   |                    d(d$           |                     d)|j                   |                    d*d$           |                     d+|j                   d S ),NrW   r   r   rz   *   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 Spacer6   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3t$$	c"""',,,+T\:::ug&&&mT\222ui(((ot|444(89996EEE|Wg6665t|DDD}g...*DL999|[111-t|<<<|_55514<@@@,.>???<dlKKK*,=>>>;T\JJJ{G,,,)4<888{G,,,)4<888+W55514<@@@+W55514<@@@@@r   c                    d}t          j        d          }t          d          }||_        |                    dd           |                     |j                            |                     d}t          j        d          }t          d          }||_        |                    dd           |                     |j                            |                     d S )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3"~~	UF###	,,X667778$_55"~~	UF###	,,X6677777r   c                    d}t          |          }t          j        |          }|                                 |                     |                    d          d           |                     |                    d          d           d S )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0%88811599999r   c           	         dt          t          dd                    z   dz   t          t          dd                    z   dz   }t          |          }t          j        |          }|                                 |                     |                    d          d	           |                     |j        d         d	           |                     |                    d
          d           |                     |j        d
         d           d	                    t          t          t          dd                              }|                     |                    d          |           |                     |j        d         |           |                     |                    d                     |                     d|j                   |                    d          |j        d         fD ]h}|                     |                    d                     |                     d|           |                     |                    d                     id S )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!#$%&'*+-.^_`|~r6   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45569 "%h"7"7889< 	 $"4((

(8993???"23S999(9::GDDD"34g>>>CtX!6!6778800%888'*E222T^^J77888j$(+++~~j1148J3GH 	@ 	@FOOF--f55666MM.777OOFOO,=>>????	@ 	@r   c                    t          j        d          }t          d          |_        |                    dd           d}|D ]}\  }}|                     ||f          5  |                     t          d          5  |                    ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   ~d S )NrW   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namer6   s        r   test_invalid_headersz HeaderTests.test_invalid_headersF  sE   $]33rNN	s###
$ ! 	0 	0KD%tUm,, 0 0++J8HII 0 0NN4///0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0	0 	0s6   B5;BB5B""B5%B"&B55B9	<B9	c                    d}t          |          }t          j        |d          }t          j                    5 }|                                 d d d            n# 1 swxY w Y   |                                                                }|                     |d         d           |                     |d         d           |                     |d         d           |                     |d	         d
           d S )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_debugleveld  s+     	 $"4A666$&& 	&JJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!!,,..q#CDDDq#7888q#9:::q#9:::::s   AA #A N)r8   r9   r:   r   r   r   r   r   r   r   r   r1   r   r   rf   rf      s        H H H:@ @ @D A  A  AD8 8 8&: : :@ @ @<0 0 0<; ; ; ; ;r   rf   c                       e Zd Zd ZdS )HttpMethodTestsc                     d}|D ]t}|                      t          d          5  t          j        d          }t	          d           |_        |                    |d           d d d            n# 1 swxY w Y   ud S )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 charactersrW   r   )r   url)r   r   r   r   r   r   r   )r   methodsr   r   s       r   test_invalid_method_namesz)HttpMethodTests.test_invalid_method_namesw  s    

  	5 	5F'' IK K 5 5,];;&t,,	F444	5 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5s   A A..A2	5A2	N)r8   r9   r:   r   r1   r   r   r   r   v  s#        5 5 5 5 5r   r   c                   >    e Zd ZdZd Zd Zd Zd ZddZd Z	d	 Z
d
S )TransferEncodingTests   It's just a flesh woundc                 z   t          j        d          }t          d          |_        |                    dd           |                    |                                 d           |                     |j        j                  \  }}}| 	                    |          }| 
                    || j                   d S )NrW   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3sOO	$$$))$???((88
1d""4((t122222r   c                 X   t          j        d          }t          d          |_        |                    dd|                                 ddi           |                     |j        j                  \  }}}|                     dd |	                                D                        | 
                    |d         d           | 
                    || j                   t          j        d          }t          d          |_        |                    dd| j                            d	          ddi           |                     |j        j                  \  }}}|                     dd
 |	                                D                        | 
                    |d         d           | 
                    || j                   t          j        d          }t          d          |_        |                    ddddid|                                            |                     |j        j                  \  }}}|                     dd |D                        | 
                    |d         d           | 
                    |                     |          | j                   d S )NrW   r   r~   r   Transfer-Encodingchunkedcontent-lengthc                 6    g | ]}|                                 S r1   rq   .0ks     r   
<listcomp>z>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>       +N+N+N!AGGII+N+N+Nr   latin-1c                 6    g | ]}|                                 S r1   r  r  s     r   r  z>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>  r	  r   zgzip, chunkedT)r   r   r   c                 6    g | ]}|                                 S r1   r  r  s     r   r  z>TransferEncodingTest.test_explicit_headers.<locals>.<listcomp>       +G+G+G!AGGII+G+G+Gr   )r   r   r   r   r   r   r   r   assertNotInkeysr   r   rp   r   r   r   r   r   r   s        r   test_explicit_headersz*TransferEncodingTest.test_explicit_headers  s   $]33sOO	 	C**-@),L	N 	N 	N  ..ty~>>7D)+N+Nw||~~+N+N+NOOO!45yAAAt1222 $]33sOO	C+229== ),	. 	. 	.  ..ty~>>7D)+N+Nw||~~+N+N+NOOO!45yAAAt1222 $]33sOO	VS(/:"" 	 	$ 	$ 	$  ..ty~>>7D)+G+Gw+G+G+GHHH!45GGG,,T22D4FGGGGGr   c                    dD ]}t          j        d          }t          d          |_        |                    dd|                     |                     |                     |j        j                  \  }}}|                     |          }| 	                    || j
                   | 	                    |d         d           |                     d	d
 |D                        d S )N)FTrW   r   r~   r   )empty_linesr   r  r  c                 6    g | ]}|                                 S r1   r  r  s     r   r  z5TransferEncodingTest.test_request.<locals>.<listcomp>  s     /K/K/Ka		/K/K/Kr   )r   r   r   r   r   r   r   r   r   r   r   r  )r   r  r   r   r   r   s         r   test_requestz!TransferEncodingTest.test_request  s    ) 	M 	MK(77D"3DILLT___EEG G G  $2249>BBAw&&t,,DT4#5666W%899EEE -/K/K7/K/K/KLLLL	M 	Mr   c                 n   t          j        d          }t          d          |_        |                    ddd           |                     |j        j                  \  }}}|                     |d         d           |                     dd	 |D                        |                     |d
           d S )NrW   r   r~   r   r1   r   r  r  c                 6    g | ]}|                                 S r1   r  r  s     r   r  z8TransferEncodingTest.test_empty_body.<locals>.<listcomp>  r  r   s   0

)	r   r   r   r   r   r   r   r   r  r  s        r   test_empty_bodyz$TransferEncodingTest.test_empty_body  s    $]33sOO	VS"%%%..ty~>>7D!45yAAA)+G+Gw+G+G+GHHH|,,,,,r   Fc              #      K   | j                             d          }t          |          D ]2\  }}|r	|dz  rdV  |t          |          dz
  k     r|dz   V  .|V  3d S )N    r   r   r    )r   rn   	enumeratero   )r   r  r   idxlines        r   r   zTransferEncodingTest._make_body  s      "((.."5)) 	 	IC sQw 			SZZ!^##Tk!!!!



	 	r   c                 "   |                     d          }|d         }i }d}|t          |          k     rt          ||                   dk    r||                              d          \  }}|                    d                                          }|                    d                                          ||<   |dz  }|t          |          k     rt          ||                   dk    ||d                    ||dz   d                    fS )N   
r   r    rm   r
  )rn   ro   rp   r   r   )r   r   r   r   r   rN   keyr   s           r   r   z#TransferEncodingTest._parse_request  s    

7##(#e**nnU1X!2!2Qx~~d++HC**Y''--//C::i006688GCLFA	 #e**nnU1X!2!2 eAEFFm!<!<<<r   c                 `   g }i }d}|                     d          }	 |||dz            \  }}t          |d          }|dk    r|dz  }nR|                     |t          |                     |                    |           |dz  }|t          |          k    rn~d                    |          S )Nr   r  Tr      r    r   )rn   intr   ro   rt   r   )r   r   r   trailersrN   r   sizechunks           r   r   z#TransferEncodingTest._parse_chunked  s    

7##	!A#,KD%tR==DqyyQT3u::...KKFA 3u::~~!	$ xx~~r   N)F)r8   r9   r:   r   r   r  r  r  r   r   r   r1   r   r   r   r     s        .M3 3 3$H $H $HLM M M - - -	 	 	 	= = =    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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 Z5d4S )5	BasicTestc           
          |                      h dt          t          t          d                              k               d S )N>   r   r6   phrasedescription  )r   setdirr   r.   s    r   &test_dir_with_added_behavior_on_statusz0BasicTest.test_dir_with_added_behavior_on_status  s=    BBBc#jY\ooJ^J^F_F__`````r   c                 j     G d dt           j                  }t          j        |t                     d S )Nc                      e Zd ZdZdCd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/Z0d0Z1d1Z2d2Z3d3Z4d4Z5d5Z6d6Z7d7Z8d8Z9d9Z:d:Z;d;Z<d<Z=d=Z>d>Z?d?Z@d@ZAdAZBdBS )D;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
            r   c                 f    t                               | |          }||_        ||_        ||_        |S r0   )r#  __new___value_r*  r+  )clsr6   r*  r+  objs        r   r4  zCBasicTest.test_simple_httpstatus.<locals>.CheckedHTTPStatus.__new__%  s/    kk#u--##
"-
r   )d   Continuez!Request received, please continue)e   zSwitching Protocolsz.Switching to new protocol; obey Upgrade header)f   
Processing)g   zEarly Hints)   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)i,  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 RedirectrM  )i4  zPermanent RedirectrK  )i  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)i  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   )Cr8   r9   r:   rS   r4  CONTINUESWITCHING_PROTOCOLS
PROCESSINGEARLY_HINTSr?  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_REQUIREDr1   r   r   CheckedHTTPStatusr2    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 K	K K	K K	K K	K K	K K	K K	KX 	0*=====r   c                    d}t          |          }t          j        |          }|                                 |                     |                    d          d           |                     |                                           |                     |j                   |                     |                                d           | 	                    |                                           |                     |j                   |
                                 | 	                    |j                   d}t          |          }t          j        |          }|                     t          j        |j                   d S )NHTTP/1.1 200 Ok

Textr   r      TextzHTTP/1.1 400.100 Not Ok

Text)r   r   r   r   r   rL   assertFalseisclosedclosedr   r)   assertRaisesBadStatusLiner   s       r   test_status_lineszBasicTest.test_status_lines  s7    -$"4((

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

$$$4$"4((&.
;;;;;r   c                 t    t          j        d          }|                     t          |          d           d S )Nr   zBadStatusLine("''"))r   r  r   repr)r   excs     r   test_bad_status_reprzBasicTest.test_bad_status_repr  s5    "2&&c$=>>>>>r   c                 H   d}t          |          }t          j        |          }|                                 |                     |                    d          d           |                     |                                           |                     |                    d          d           |                     |                                           |                     |j	                   |
                                 |                     |j	                   d S N*HTTP/1.1 200 Ok
Content-Length: 4

Textr      Te   xtr   r   r   r   r   rL   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   d}t          |          }t          j        |          }|                                 |                     |                                d           |                     |                                           |                     |                                d           | 	                    |                                           |                     |j
                   |                                 | 	                    |j
                   d S )Nz4HTTP/1.1 200 Ok
Content-Length: 13

Text
Anothers   Text
s   Another)r   r   r   r   r   rP   r  r  rL   r   r  r)   r   s       r   test_mixed_readszBasicTest.test_mixed_reads  s     N$"4((

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

$$$$$r   c                    d}t          |          }t          j        |          }|                                 t	          d          }|                    |          }|                     |d           |                     t          |          d           |                     |	                                           |                    |          }|                     |d           |                     t          |          d           | 
                    |	                                           |                     |j                   |                                 | 
                    |j                   d S r  r   r   r   r   	bytearrayreadintor   r   r  r  r   r  r)   r   r   r   r   brN   s         r   test_partial_readintosz BasicTest.test_partial_readintos  s8    B$"4((

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

$$$$$r   c                    d}t          |          }t          j        |          }|                                 |                     |                    d          d           |                     |                                           |                     |j	                   |
                                 |                     |j	                   d S )Nr  
   r  r   r   r   r   r   rL   r   r  r  r  r)   r   s       r   test_partial_reads_past_endz%BasicTest.test_partial_reads_past_end  s    A$"4((

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

$$$$$r   c                     d}t          |          }t          j        |          }|                                 t	          d          }|                    |          }|                     |d           |                     t          |          d d         d           |                     |	                                           | 
                    |j                   |                                 |                     |j                   d S )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((

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

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

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

$$$$$r   c                    d}t          |          }t          j        |          }|                                 t	          d          }|                    |          }|                     |d           |                     t          |          d           |                     |	                                           |                    |          }|                     |d           |                     t          |          d           |                    |          }|                     |d           | 
                    |	                                           d S )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_length  s'    -$"4((

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

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

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

$$$$$r   c                    dD ]-}|                      t          j        t          j        |           .dD ]P\  }}}t          j        |          }|                     ||j                   |                     ||j                   Qd S )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_portM  s     I 	L 	LBf/1FKKKKP 		( 		(HB1 %b))AQ'''Q''''		( 		(r   c                     d}d}t          |          }t          j        |          }|                                 |                    d          }|                     ||           d S )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^  sj    O t""				++l++#&&&&&r   c                     t          dt                    }t          j        |d          }|                                 |                                r|                     d           d S d S )N*HTTP/1.1 200 OK
Content-Length: 14432

r   r   )Did not expect response from HEAD request)r   rH   r   r   r   rL   failr   r   r   s      r   test_read_headzBasicTest.test_read_headp  sw      	 
 "4777

99;; 	CIIABBBBB	C 	Cr   c                 D   t          dt                    }t          j        |d          }|                                 t          d          }|                    |          dk    r|                     d           |                     t          |          d           d S )Nr  r   r     r   r          )
r   rH   r   r   r   r  r  r  r   r   )r   r   r   r  s       r   test_readinto_headzBasicTest.test_readinto_head}  s      	 
 "4777

aLL==q  IIABBBq9-----r   c                    d                     d t          t          j        dz             D                       dz   }d|z   }t	          |          }t          j        |          }|                     t          j        d|j                   d S )Nr   c              3       K   | ]	}d |z  V  
dS )zHeader%d: fooNr1   )r  is     r   	<genexpr>z2BasicTest.test_too_many_headers.<locals>.<genexpr>  sC       F F"# .1 F F F F F Fr   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 F',V-?!-C'D'DF F F F FHNO%/t""v3;QW	F 	F 	F 	F 	Fr   c           	         d}t          t          d          5 }t          j        d          }t	          |          }||_        |                    dd|           |                     |j        	                    |          |j        d t          |                   d|           d d d            d S # 1 swxY w Y   d S )Ns_   GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Transfer-Encoding: chunked

r%   rW   r   r   z != )open__file__r   r   r   r   r   r   r   r   ro   r   r   r   r   r   s        r   test_send_filezBasicTest.test_send_file  s   
 (D!! 	;T(77Dd##DDILL---OODI00::Y~H~...=: ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   BB44B8;B8c                    d}t          j        d          }t          d           }||_        |                    |           |                     ||j                   d|_        |                    t          j        d|                     |                     ||j                   d|_        |                    t          j	        |                     |                     ||j                   d S )Ns"   this is a test this is only a testrW   r   r  )
r   r   r   r   sendr   r   arrayr;   r<   r   s       r   	test_sendzBasicTest.test_send  s    8$]33$			(49---			%+c8,,---49---			"*X&&'''49-----r   c                 
   d  G fddt           j                  }d}t          j        d          }t	          d          }||_        |                     |                       |                     |j        |           d S )Nc               3   "   K   dV  d V  dV  d S )Nr   data_twor1   r1   r   r   r   z/BasicTest.test_send_updating_file.<locals>.data  s*      LLLJJJr   c                   0    e Zd ZdZ              ZddZdS )7BasicTest.test_send_updating_file.<locals>.UpdatingFiler$   rI   c                 *    t          | j                  S r0   )nextd)r   	blocksizes     r   rL   z<BasicTest.test_send_updating_file.<locals>.UpdatingFile.read  s    DF||#r   NrR   )r8   r9   r:   r*   r  rL   )r   s   r   UpdatingFiler    s9        DA$ $ $ $ $ $r   r  s   datarW   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  s    	 	 	
	$ 	$ 	$ 	$ 	$ 	$ 	$2= 	$ 	$ 	$ $]33"~~			,,..!!!H-----r   c                     d}d }t          j        d          }t          d          }||_        |                    dd |            ddi           |                     |j        |           d S )	Nsb   GET /foo HTTP/1.1
Host: example.com
Accept-Encoding: identity
Content-Length: 11

onetwothreec               3   "   K   dV  dV  dV  d S )Ns   ones   twos   threer1   r1   r   r   r   z&BasicTest.test_send_iter.<locals>.body  s%      LLLLLLNNNNNr   rW   r   r   r   r   11)r   r   r   r   r   r   r   r  s        r   test_send_iterzBasicTest.test_send_iter  s~    &	 	 	
 $]33"~~	UFDDFF-=t,DEEEH-----r   c                 n   d}t          j        d|          }t          d          }||_        d|z  dz   }|                    ddt          j        |          d	d
i           |                     |j        d           |j	        
                    dd          d         }|                     ||           dS )z8Check that request() respects the configured block size.   rW   r  N   a   br   r   r   9r      

r    )r   r   r   r   r   r;   r<   r   r   r   rn   )r   r  r   r   r   r   s         r   test_blocksize_requestz BasicTest.test_blocksize_request  s    	$]iHHH$	)#d*UCH!5!58H#7NOOO+Q///y{A..q1x(((((r   c                 ,   d}t          j        d|          }t          d          }||_        d|z  dz   }|                    t          j        |                     |                     |j        d           |                     |j	        |           dS )z5Check that send() respects the configured block size.r  rW   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  s    	$]iHHH$	)#d*		"*X&&'''+Q///H-----r   c                     t          j        d          }t          d          |_        |                     t
                    5  |                    dd|           d d d            d S # 1 swxY w Y   d S )NrW   r   r~   test)r   r   r   r   r  	TypeErrorr   r   s     r   test_send_type_errorzBasicTest.test_send_type_error  s    $]33rNN	y)) 	/ 	/LL...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   A((A,/A,c                    t           }t          t          t          z   t          z             }t          j        |d          }|                                 |                     |	                                |           |
                                 t          dd          D ]}t          t          t          z   t          z             }t          j        |d          }|                                 |                     |	                    |          |	                    |          z   |	                                z   |           |
                                 dD ]+}t          t          |z             }t          j        |d          }|                                 	 |	                                 |                     d           n# t
          j        $ r}}|                     |j        |           dt          |          z  }|                     t!          |          |           |                     t#          |          |           Y d }~nd }~ww xY w|
                                 # |
                                 w xY wd S )Nr   r  r       r   zfoo
IncompleteRead expectedIncompleteRead(%d bytes read))chunked_expectedr   chunked_start
last_chunkchunked_endr   r   r   r   rL   r)   r   r  IncompleteReadpartialro   r  r   )r   r   r   r   rN   xr  expected_messages           r   test_chunkedzBasicTest.test_chunked  s8   #-*4{BCC"4666

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

 q" 	 	Amj8;FGGD&tE:::DJJLLLTYYq\\DIIaLL8499;;FQQQJJLLLL  	 	Ama/00D&tE:::DJJLLL
		 		34444 ( ; ; ;  H555#BS]]#R   a*:;;;  Q)9::::::::	; 



	 	s1   "G6I1IA3II1II11Jc                 :   t           }t          |          }t          d          }t          t          t
          z   t          z             }t          j        |d          }|	                                 |
                    |          }|                     |d |         |           |                     ||           |                                 t          dd          D ]}t          t          t
          z   t          z             }t          j        |d          }|	                                 t          |          }|
                    |d|                   }||
                    ||||z                      z  }||
                    ||d                    z  }|                     |d |         |           |                     ||           |                                 
dD ],}	t          t          |	z             }t          j        |d          }|	                                 	 |
                    |          }|                     d           n# t          j        $ r}}|                     |j        |           d	t          |          z  }
|                     t%          |          |
           |                     t'          |          |
           Y d }~nd }~ww xY w|                                 # |                                 w xY wd S )
Nr   r   r  r    r  r   r  r  r  )r  ro   r  r   r  r  r  r   r   r   r  r   r)   r   
memoryviewr  r  r  r  r   )r   r   	nexpectedr  r   r   rN   mr  r  r  s              r   test_readinto_chunkedzBasicTest.test_readinto_chunked  s   #MM	cNN-*4{BCC"4666

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

 q" 
	 
	Amj8;FGGD&tE:::DJJLLL1Aa!f%%Aq1q5z***Aqu%%%AQz	z]H555Q	***JJLLLL  	 	Ama/00D&tE:::DJJLLL
MM!$$ 		34444 ( ; ; ;  H555#BS]]#R   a*:;;;  Q)9::::::::	; 



	 	s1   2ILK),A3K$L$K))LLc                 6   d}t          |t          z   t          z             }t          j        |d          }|                                 |                     |                                d           |                     |j        d           |                     |j	        d           | 
                    |                                           |                     |j                   |                                 | 
                    |j                   d S )NEHTTP/1.1 200 OK
Transfer-Encoding: chunked

a
hello world
1
d
r   r  r   r>  r?  )r   r  r  r   r   r   r   rL   statusreasonr   r  r  r  r)   )r   r  r   r   s       r   test_chunked_headzBasicTest.test_chunked_head?  s     	 -*4{BCC"4777

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

$$$$$r   c                    d}t          |t          z   t          z             }t          j        |d          }|                                 t          d          }|                    |          }|                     |d           |                     t          |          d           |                     |j
        d           |                     |j        d           |                     |                                           |                     |j                   |                                 |                     |j                   d S )	Nr&  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  rN   s         r   test_readinto_chunked_headz$BasicTest.test_readinto_chunked_headS  s    	 -*4{BCC"4777

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

$$$$$r   c                    t          d          }t          j        |d          }|                                 |                     |                                d           |                     |                                           d S )Nz.HTTP/1.1 200 OK
Content-Length: -1

Hello
r   r     Hello
)r   r   r   r   r   rL   r   r  r  s      r   test_negative_content_lengthz&BasicTest.test_negative_content_lengthj  sv    DF F"4666

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


	1IIKKK II/00000 $ 	- 	- 	-QY555T!WWLN N NSVVLN N NOODMMOO,,,,,,,,,	-s   A& &D5BDDc                 J   t          dd          }t          j        d          |_        |                     t
          fd                                           }|                     d|j                   |                     d|	                    d                     d S )NzgHTTP/1.0 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Basic realm="example"
s   Content-LengthrW   c                  2                          ddd          S )Nr   /urlr   )r   )r   s   r   <lambda>z&BasicTest.test_epipe.<locals>.<lambda>  s    $,,uff"E"E r   rN  zBasic realm="example"zwww-authenticate)
r>   r   r   r   r  rC   getresponser   r'  r   )r   r   r   r   s      @r   
test_epipezBasicTest.test_epipe  s    < 	 
 $]33	'EEEE	G 	G 	G!!dk***2(:;;	= 	= 	= 	= 	=r   c                     dddz  z   dz   }t          j        t          |                    }|                     t           j        t           j        f|j                   d S )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  sV     3;.7":d#3#3446-v/CDdjQQQQQr   c                     dddz  z   dz   }t          j        t          |                    }|                     t           j        |j                   d S )NzHTTP/1.1 200 OK
X-Foo: barr$   r9  z

)r   r   r   r  r:  r   r;  s      r   test_overflowing_header_linez&BasicTest.test_overflowing_header_line  s[    ;')34 	 ":d#3#344&,dj99999r   c                    ddz  }t          j        t          |                    }|                     t           j                  5 }|                                 d d d            n# 1 swxY w Y   |                     dt          |j                             |                     dt          |j                             d S )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#344v344 	JJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	&BL(9(9:::iR\!2!233333s   A''A+.A+c                     dddz  z   dz   }t          j        t          |                    }|                                 |                     t           j        |j                   d S )Nz/HTTP/1.1 200 OK
Transfer-Encoding: chunked

r   r9  za
hello world
0

)r   r   r   r   r  r:  rL   r;  s      r   test_overflowing_chunked_linez'BasicTest.test_overflowing_chunked_line  sj    1Ek 	 ":d#3#344

&,di88888r   c                    d}t          |          }t          j        |          }|                                 |                     |                                d           |                     |                                           |                     |j	                   |
                                 |                     |j	                   d S )Nr8  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          |_        |                    dd           |                     t           j        |j	                   | 
                    j                   | 
                    |j        j                   d S )NrW   c                       e Zd Z fdZdS )+BasicTest.test_error_leak.<locals>.Responsec                 @    | t          j        j        | g|R i | d S r0   )r   r   r   )r   rb   rc   responses      r   r   z4BasicTest.test_error_leak.<locals>.Response.__init__  s2    #,T>C>>>2>>>>>r   N)r8   r9   r:   r   )rK  s   r   ResponserI    s.        ? ? ? ? ? ? ?r   rL  zInvalid status liner   r   )r   r   r   response_classr   r   r   r  r  r5  r   r  r   )r   r   rL  rK  s      @r   test_error_leakzBasicTest.test_error_leak  s    $]33	? 	? 	? 	? 	? 	? 	?v* 	? 	? 	?
 '455	UC   &.0@AAA(((	-.....r   c                 8   d}t           dz   }t          t          |z   t          z   t          z             }t          j        |d          }|                                 |                     |	                                |           |
                                 d S )Nz3;foo=bar
abc
s   abcr   r  )r  r   r  last_chunk_extendedr  r   r   r   r   rL   r)   )r   extrar   r   r   s        r   test_chunked_extensionz BasicTest.test_chunked_extension  s    +#f,-%/2EESTT"4666

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

r   c                    t           }t          t          t          z             }t	          j        |d          }|                                 |                     |                                |           |	                                 dS )z9some servers may serve up a short chunked encoding streamr   r  N)
r  r   r  r  r   r   r   r   rL   r)   r   r   r   r   s       r   test_chunked_missing_endz"BasicTest.test_chunked_missing_end  sj    #-*455"4666

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

r   c                    t           }t          t          t          z   t          z   t
          z             }t          j        |d          }|                                 | 	                    |
                                |           | 	                    |j        
                                d           |                                 dS )z&See that trailers are read and ignoredr   r  r   N)r  r   r  r  r$  r  r   r   r   r   rL   r'   r)   rT  s       r   test_chunked_trailerszBasicTest.test_chunked_trailers  s    #-*4x?+MNN"4666

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

r   c                    t           }d}t          t          t          z   t          z   t
          z   |z             }t          j        |d          }|                                 | 	                    |
                                |           | 	                    |j        
                                |                    d                     |                                 dS )zDCheck that we don't read past the end of the chunked-encoding stream	extradatar   r  r   N)r  r   r  r  r$  r  r   r   r   r   rL   r'   r   r)   )r   r   rY  r   r   s        r   test_chunked_synczBasicTest.test_chunked_sync  s    #	-*4x?+MPYYZZ"4666

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

r   c                 ^   d}d}t          d|z   |z             }t          j        |d          }|                                 |                     |                                |           |                     |j                                        |           |                                 dS )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   rL   r'   r)   r   rY  r   r   r   s        r   test_content_length_syncz"BasicTest.test_content_length_sync   s     	"JXUXaabb"4666

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

r   c                 b   d}d}t          d|z   |z             }t          j        |d          }|                                 |                     |                    d          |g           |                     |j                                        |           |                                 d S Nr\  r]  r^  r   r  i  )	r   r   r   r   r   	readlinesr'   rL   r)   r_  s        r   test_readlines_content_lengthz'BasicTest.test_readlines_content_length  s     	"JXUXaabb"4666

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

r   c                 `   d}d}t          d|z   |z             }t          j        |d          }|                                 |                     |                    d          |           |                     |j                                        |           |                                 d S rb  )	r   r   r   r   r   read1r'   rL   r)   r_  s        r   test_read1_content_lengthz#BasicTest.test_read1_content_length  s     	"JXUXaabb"4666

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

r   c                    d}d}t          d|z   |z             }t          j        |d          }|                                 |                     |                    d          |           |                     |                    d          d           |                     |j                                        |           |                                 d S )Nr\  r]  r^  r   r  r  r   )	r   r   r   r   r   rP   r'   rL   r)   r_  s        r   "test_readline_bound_content_lengthz,BasicTest.test_readline_bound_content_length"  s     	"JXUXaabb"4666

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

r   c                    d}d}t          d|dz  z   |z             }t          j        |d          }|                                 |                     |                    d          |dz             |                     |                                |           |                     |j                                        |           |                                 d S )	Nr\  r]  s'   HTTP/1.1 200 OK
Content-Length: 30

r   r   r     r   )	r   r   r   r   r   rf  rL   r'   r)   r_  s        r   test_read1_bound_content_lengthz)BasicTest.test_read1_bound_content_length.  s     	"JXVWZWZccdd"4666

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

r   c                    t          j        t          df          |                     j                   d fd}t          j        |          }|                                 |                     |j        t          d                     t          j                                         }|                    dd           |                                }	 |                     |j        t          j                   t          j         |                                          }	 |                    d           |                                 n# |                                 w xY w	 |                                 |                                 n-# |                                 |                                 w xY w|                                 |                     d           d S )	Nr   c                  p                                    \  } }| 5  |                     d          5 }	 |                                }|                    d          sn+|                     d           |                                d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr%   Tr  s'   HTTP/1.1 200 Connection established

)acceptr,   rP   rstripr"   rL   )r   addressreaderr  resultservs       r   
run_serverz2BasicTest.test_response_fileno.<locals>.run_server@  s3   "kkmmOT7 ' 't}}T** 'f!??,,D;;w//  KLLL' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's5   B+ABB+B	B+B	B++B/2B/)targetr    r   z
dummy:1234)filenos   proxied data
)socketcreate_serverHOST
addCleanupr)   	threadingThreadstartr   floatr   r   getsocknamer   r5  r   r'  r?  rw  r"   detach)r   ru  threadr   rK  r  rs  rt  s         @@r   test_response_filenozBasicTest.test_response_fileno:  s   #T1I..
###
	' 
	' 
	' 
	' 
	' 
	' !444U1XX...$d&6&6&8&89Y---##%%		X_fi888X__%6%6777A		+,,,








NNJJLLLL NNJJLLLL!233333s%   AF )E >F E))F *G c                      G d dt           j                  } |d          }t          d          |_        |                    dd           dS )zv
        It should be possible to override the default validation
        behavior in putrequest (bpo-38216).
        c                       e Zd Zd ZdS )RBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnectionc                     d S r0   r1   r   r   s     r   _validate_pathzaBasicTest.test_putrequest_override_domain_validation.<locals>.UnsafeHTTPConnection._validate_pathe      r   N)r8   r9   r:   r  r1   r   r   UnsafeHTTPConnectionr  d  #            r   r  rW   r   r   z/ Nr   r   r   r   r   r   r  r   s      r   *test_putrequest_override_domain_validationz4BasicTest.test_putrequest_override_domain_validation_  sh    
	 	 	 	 	6#8 	 	 	 $#M22rNN	w'''''r   c                      G d dt           j                  } |d          }t          d          |_        |                    ddd           d S )	Nc                       e Zd Zd ZdS )PBasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnectionc                     d S r0   r1   r  s     r   _validate_hostz_BasicTest.test_putrequest_override_host_validation.<locals>.UnsafeHTTPConnection._validate_hostn  r  r   N)r8   r9   r:   r  r1   r   r   r  r  m  r  r   r  zexample.com
r   r   r   r    )	skip_hostr  r  s      r   (test_putrequest_override_host_validationz2BasicTest.test_putrequest_override_host_validationl  so    	 	 	 	 	6#8 	 	 	 $#$566rNN	 	sa00000r   c                      G d dt           j                  } |d          }t          d          |_        |                    dd           dS )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dS )IBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnectionc                 ,    |                     d          S )Nutf-8)r   )r   str_urls     r   _encode_requestzYBasicTest.test_putrequest_override_encoding.<locals>.UnsafeHTTPConnection._encode_request~  s    ~~g...r   N)r8   r9   r:   r  r1   r   r   r  r  }  s#        / / / / /r   r  rW   r   r   u   /☃Nr  r  s      r   !test_putrequest_override_encodingz+BasicTest.test_putrequest_override_encodingw  sh    	/ 	/ 	/ 	/ 	/6#8 	/ 	/ 	/ $#M22rNN	v&&&&&r   N)6r8   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  r$  r)  r+  r.  r0  r6  r<  r>  rB  rD  rF  rN  rR  rU  rW  rZ  r`  rd  rg  ri  rl  r  r  r  r  r1   r   r   r(  r(    s$       a a aM> M> M>`< < <*? ? ?% % %% % %% % %(
% 
% 
%% % %% % % ) ) )&) ) )% % %,( ( ("' ' '$C C C. . .F F F; ; ;. . .. . .*. . . 
) 
) 
)	. 	. 	./ / /  @) ) )V% % %(% % %.) ) )1 1 1 = = ="R R R
: : :4 4 49 9 9
% 
% 
%/ / /     	 	 	
 
 

 
 
	 	 		 	 	
 
 

 
 
#4 #4 #4J( ( (	1 	1 	1' ' ' ' 'r   r(  c                       e Zd ZdZdZee                    d          d                             d          ZdZd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd ZdS )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          }|                                 t          j        |j                  |_        || _        d S )Nr   r  )	r   r   r   r   r   r;   BufferedReaderfpr   r  s      r   setUpzExtendedReadTest.setUp  sR    $*%%"4666

#DG,,			r   c                    | j         }|j        j        dfd	}||j        _        g }	 |                    d          }|r|                     t	          |          d           |                                }|                     t	          |          t	          |                     |                     |                    |                     |                    t	          |                    }| 	                    ||           n)|                                }| 
                    |           |                    |           |sn"| 	                    d                    |          | j                   d S )NrI   c                 N     |           }| dk    r
|d |          S |d d         S )Nr   r  r1   )rN   r  oldpeeks     r   mypeekz*ExtendedReadTest.test_peek.<locals>.mypeek  s3    

AAvv!uSbS6Mr   Tr   r   r   rR   )r   r  peekassertGreaterro   assertGreaterEqualr   r   rL   r   r  rt   r   lines_expected)r   r   r  allr  p2r  r  s          @r   	test_peekzExtendedReadTest.test_peek  sd   y',	 	 	 	 	 	
 			!A 
'""3q661---YY[[''BQ888a 0 0111yyR))  r****yy{{  &&&JJt !	" 	#(;<<<<<r   c                 ^    | j         }|                     | j         j        | j                   d S r0   )r   _verify_readlinerP   r  )r   r   s     r   test_readlinezExtendedReadTest.test_readline  s-    ydi0$2EFFFFFr   c                 ,   g }	  |d          }|rA|dk    r;t          |          dk     r(|                     |                    d                     |                    |           |sng|                     d                    |          |           d S )NTr     foo   
r   )ro   r   r   rt   r   r   )r   rP   r   r  r  s        r   r  z!ExtendedReadTest._verify_readline  s    	8A;;D :t99q==OODMM%$8$8999JJt 	 	#11111r   c                       j          fd}t          |          }                     |j         j                   d S )Nc                  x                         d          }                     t          |           d           | S )Nr  )rf  assertLessEqualro   )resr   r   s    r   r$   z&ExtendedReadTest.test_read1.<locals>.r  s3    **Q--C  S1---Jr   )r   	Readlinerr  rP   r  )r   r$   	readlinerr   s   `  @r   
test_read1zExtendedReadTest.test_read1  sX    y	 	 	 	 	 	 aLL	i0$2EFFFFFr   c                     | j         }g }	 |                                }|sn|                    |           -|                     d                    |          | j                   d S )NTr   )r   rf  rt   r   r   r  r   r   r  r   s       r   test_read1_unboundedz%ExtendedReadTest.test_read1_unbounded  sm    y	::<<D JJt		
 	#(;<<<<<r   c                    | j         }g }	 |                    d          }|sn9|                     t          |          d           |                    |           Q|                     d                    |          | j                   d S )NTr  r   )r   rf  r  ro   rt   r   r   r  r  s       r   test_read1_boundedz#ExtendedReadTest.test_read1_bounded  s    y	::b>>D   TB///JJt	 	#(;<<<<<r   c                 b    |                      | j                            d          d           d S )Nr   r   )r   r   rf  r.   s    r   test_read1_0zExtendedReadTest.test_read1_0  s,    ++S11111r   c                     | j                             d          }|                     dt          |                     d S Nr   )r   r  r  ro   )r   r  s     r   test_peek_0zExtendedReadTest.test_peek_0  s7    INN1QA'''''r   )r8   r9   r:   rS   r   findr   r  lines_chunkedr  r  r  r  r  r  r  r  r  r1   r   r   r  r    s         	 
 5::g..//077@@N	 "  = = =>G G G2 2 2G G G= = =	= 	= 	=2 2 2( ( ( ( (r   r  c                       e Zd ZdZdZdS )ExtendedReadTestChunkedz:
    Test peek(), read1(), readline() in chunked mode
    r  N)r8   r9   r:   rS   r   r1   r   r   r  r    s"         	 
EEr   r  c                       e Zd ZdZd Zd ZdS )r  zT
    a simple readline class that uses an arbitrary read function and buffering
    c                 "    || _         d| _        d S )Nr   )readfunc	remainder)r   r  s     r   r   zReadliner.__init__  s     r   c                    g }d}| j         }	 	 |                    d          }|dk    rnM|t          |          z   |k    r||z
  dz
  }|                    |           |                                 }|sd}ni|dz  }|                    |d |                    ||d          | _         d                    |          S #  d                    |          | _          xY w)Nr   Tr  rI   r    r   )r  r  ro   rt   r  r   )r   limitr   datalenrL   r  s         r   rP   zReadliner.readline!  s    ~	ii&&"99SYY&%//'/A-CD!!!}} C 1HCKKTcT
###!#$$ZDN88D>>!	 XXd^^DNs   B/B= =CN)r8   r9   r:   rS   r   rP   r1   r   r   r  r    s<               r   r  c                        e Zd Zd Zd Zd ZdS )OfflineTestc                 4   dh}ddh}t          t                    D ][}|                    d          s||v rt          t          |          }t          |dd           dk    r|                    |           \|                     t          j        |           d S )N	responsesHTTPMessageparse_headersr   r9   zhttp.client)r.  r   r   getattraddassertCountEqual__all__)r   r   denylistr   module_objects        r   test_allzOfflineTest.test_all<  s    = "?3KK 	# 	#Ds## tx'7'7#FD11M}lD99]JJT"""fnh77777r   c                 f    |                      t          j        t          j                 d           d S )NrQ  )r   r   r  rn  r.   s    r   test_responseszOfflineTest.test_responsesJ  s)    )&*:;[IIIIIr   c                     g d}|D ]X}|                      |          5  |                     t          t          |                     d d d            n# 1 swxY w Y   Yd S )N):rU  rV  rW  r?  rY  rZ  r[  r\  r]  r^  r_  ra  rb  rc  rd  re  rf  rg  rh  rj  rk  rl  rm  rn  ro  rp  rq  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  rX  r  )constant)r   r   hasattrr   )r   r   consts      r   test_client_constantsz!OfflineTest.test_client_constantsM  s    ;
 ;
 ;
x  	8 	8Eu-- 8 8 6 67778 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8s   )AA	A	N)r8   r9   r:   r  r  r  r1   r   r   r  r  ;  sI        8 8 8J J J@8 @8 @8 @8 @8r   r  c                   j    e Zd Zd Zd Zd Z ej         ee	d           d          d             Z
dS )SourceAddressTestc                    t          j         t           j        t           j                  | _        t	          j        | j                  | _        t	          j                    | _        | j        	                                 d | _
        d S r0   )rx  AF_INETSOCK_STREAMrt  r   	bind_portr   find_unused_portsource_portlistenr   r.   s    r   r  zSourceAddressTest.setUp  s^    M&.&2DEE	!+DI66	(9;;				r   c                     | j         r | j                                          d | _         | j                                         d | _        d S r0   )r   r)   rt  r.   s    r   tearDownzSourceAddressTest.tearDown  sB    9 	IOODI				r   c                    t          j        t          | j        d| j        f          | _        | j                                         |                     | j        j        	                                d         | j                   d S )Nr   source_addressr    )
r   r   rz  r   r  r   r`   r   r   r  r.   s    r   testHTTPConnectionSourceAddressz1SourceAddressTest.testHTTPConnectionSourceAddress  st    )$	 "D$457 7 7		3355a8$:JKKKKKr   HTTPSConnectionz'http.client.HTTPSConnection not definedc                 `    t          j        t          | j        d| j        f          | _        d S )Nr   r  )r   r  rz  r   r  r   r.   s    r    testHTTPSConnectionSourceAddressz2SourceAddressTest.testHTTPSConnectionSourceAddress  s2     *4 "D$457 7 7			r   N)r8   r9   r:   r  r  r  unittestskipIfr  r   r  r1   r   r   r  r    s            L L L X_):;;;>@ @7 7@ @7 7 7r   r  c                   $    e Zd ZdZd Zd Zd ZdS )TimeoutTestNc                     t          j         t           j        t           j                  | _        t	          j        | j                  t          _        | j                                         d S r0   )	rx  r  r  rt  r   r  r  PORTr  r.   s    r   r  zTimeoutTest.setUp  sI    M&.&2DEE	(249==	r   c                 F    | j                                          d | _         d S r0   )rt  r)   r.   s    r   r  zTimeoutTest.tearDown  s    				r   c                    |                      t          j                               t          j        d           	 t	          j        t          t          j                  }|	                                 t          j        d            n# t          j        d            w xY w| 
                    |j                                        d           |                                 |                      t          j                               t          j        d           	 t	          j        t          t          j        d           }|	                                 t          j        d            n# t          j        d            w xY w| 
                    |j                                        d            |                                 t	          j        t          t          j        d          }|	                                 | 
                    |j                                        d           |                                 d S N   )timeout)assertIsNonerx  getdefaulttimeoutsetdefaulttimeoutr   r   rz  r  r  r`   r   r   
gettimeoutr)   )r   httpConns     r   testTimeoutAttributez TimeoutTest.testTimeoutAttribute  s   
 	&244555 $$$	+,T;3CDDH$T****F$T****1133R888 	&244555 $$$	+,T;3C6:< < <H$T****F$T****1133T::: ({/?LLL1133R888s   8B	 	B:E- -F)r8   r9   r:   r  r  r  r
  r1   r   r   r  r    sF        D  
      r   r  c                        e Zd Zd Zd Zd ZdS )PersistenceTestc                    d}|D ]W\  }}}|                      ||          5  d                    ||          }t          |          }|                     |j                   |                    dd           |                                5 }|                     |j        d u |            |                                 d d d            n# 1 swxY w Y   |                     |j        d u |            |                     |j	        d           |                    dd           |                     |j	        |rdnd           d d d            n# 1 swxY w Y   Yd S )	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   rU   r  r   r   r5  r   rL   rX   )r   testsr  r   reuser   r   rK  s           r   test_reuse_reconnectz$PersistenceTest.test_reuse_reconnect  s   
 ', 	F 	F"GVUgf== F F%
 &&))  044!!$),,,U$6777%%'' $8$$TY$%6E	BBBMMOOO$ $ $ $ $ $ $ $ $ $ $ $ $ $ $   d!2I>>>  !11555U$9:::  !13D111EEE#F F F F F F F F F F F F F F F	F 	Fs7   A*E3C ECECA1EE	E	c                    d }t           j        t          j        f|t          ff}|D ]\  }}|                     |          5  t          d|          }|                    dd           |                     ||j	                   | 
                    |j                   |                    dd           |                     |j        d           d d d            n# 1 swxY w Y   d S )Nc                 l    t          j        |           fd}|_        t          j                  S )z3Return BufferedReader that raises ECONNRESET at EOFc                 p    t           j                            |           }|dk    rt                      |S r  )r;   r<   r  ConnectionResetError)bufferr%  streams     r   r  zNPersistenceTest.test_disconnected.<locals>.make_reset_reader.<locals>.readinto  s4    z**66::199.000r   )r;   r<   r  r  )r   r  r  s     @r   make_reset_readerz<PersistenceTest.test_disconnected.<locals>.make_reset_reader  sE    Z%%F    
 'FO$V,,,r   )r@  r   r   z/eof-response
/reconnectr   )r;   r<   r   RemoteDisconnectedr  r   rU   r   r  r5  r  r   r   rX   )r   r  r  stream_factoryr@  r   s         r   test_disconnectedz!PersistenceTest.test_disconnected  s9   		- 		- 		- Z23 45
 */ 	6 	6%NI	22 6 6/^DDUO444!!)T-=>>>!!$),,,UL111  !115556 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6s   BCC	"C	c                 8   t          d          }|                    ddddi           |                     t          j        |j                   |                     |j                   |                    dd           |                     |j	        d           d S )	Ns   HTTP/1.1 100 Continue

r   r   Expectz100-continue)r   r  r   )
rU   r   r  r   r  r5  r  r   r   rX   r   s     r   test_100_closezPersistenceTest.test_100_close  s    '
 

 	UC(N)CDDD&3T5EFFF$)$$$UL))))1-----r   N)r8   r9   r:   r  r  r!  r1   r   r   r  r    sD        F F F<6 6 66
. 
. 
. 
. 
.r   r  c                       e Zd Zd Zd Zd Zd Zd Zej	        d             Z
d Zd Zd	 Zd
 Zd Z ej         eed           d          d             Zd ZdS )	HTTPSTestc                 ^    t          t          d          s|                     d           d S d S )Nr  zssl support required)r  r   skipTestr.   s    r   r  zHTTPSTest.setUp'  s8    v011 	2MM011111	2 	2r   c                 (    ddl m}  || |          S )Nr   )make_https_server)certfile)test.ssl_serversr'  )r   r(  r'  s      r   make_serverzHTTPSTest.make_server+  s*    666666  9999r   c                     t          j        t          t          j        d          }|                     |j        d           d S r  )r   r  rz  r  r  r   r  )r   r  s     r   test_attributeszHTTPSTest.test_attributes/  s:    "4)92FFFB'''''r   c                    dd l }t          j        d           t          j        d          5  t          j        dd          }|                     |j                  5 }|	                    dd           d d d            n# 1 swxY w Y   | 
                    |j        j        d           d d d            d S # 1 swxY w Y   d S )Nr   networkself-signed.pythontest.net  r   r   CERTIFICATE_VERIFY_FAILED)sslr   requiresr   transient_internetr   r  r  SSLErrorr   r   r@  r(  )r   r2  r  exc_infos       r   test_networkedzHTTPSTest.test_networked4  sR   


###-.JKK 	U 	U&'CSIIA""3<00 &H		%%%%& & & & & & & & & & & & & & &X/68STTT		U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us5   0B8B 4B8 B	B8B	#B88B<?B<c                    dd l }t          j        d           t          j        d          5  |                                }t          j        dd|          }|                    dd           |	                                }|
                                 |                     d|                    d	                     |
                                 d d d            d S # 1 swxY w Y   d S )
Nr   r.  r/  r0  contextr   r   nginxserver)r2  r   r3  r   r4  _create_unverified_contextr   r  r   r5  r)   r   r   )r   r2  r:  r  r   s        r   test_networked_noverificationz'HTTPSTest.test_networked_noverification>  s   


###-.JKK 	 	4466G&'CS/68 8 8AIIeS!!!==??DGGIIIMM'4>>(#;#;<<<JJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B'C!!C%(C%c                    t          j        d           t          j        d          5  t	          j        dd          }|                    dd           |                                }|                    d          }|	                                 |	                                 | 
                    d|           d d d            d S # 1 swxY w Y   d S )Nr.  r  r0  r   r   zcontent-typez	text/html)r   r3  r   r4  r   r  r   r5  r   r)   r   )r   r  r   content_types       r   &test_networked_trusted_by_default_certz0HTTPSTest.test_networked_trusted_by_default_certL  s     	###-.>?? 	5 	5&'7==AIIeS!!!==??D>>.99LJJLLLGGIIIMM+|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   BC		CCc           	      B   dd l }t          j        d           d}t          j        |          5  |                    |j                  }|                     |j        |j	                   |                     |j
        d           |                    t                     	 t          j        |d|          }|                    dd           |                                }nR# |j        $ rE}t%          |          }t'          j        d	|          rt+          j        d
| d| d           d }~ww xY w|                    d          }|                                 |                                 |                     d|           d d d            d S # 1 swxY w Y   d S )Nr   r.  r/  Tr0  r9  r   r   z(?i)key.too.weakzGot z trying to connect to z). See https://bugs.python.org/issue36816.r<  r;  )r2  r   r3  r   r4  
SSLContextPROTOCOL_TLS_CLIENTr   verify_modeCERT_REQUIREDcheck_hostnameload_verify_locations CERT_selfsigned_pythontestdotnetr   r  r   r5  r5  r   researchr  SkipTestr   r)   r   )	r   r2  selfsigned_pythontestdotnetr:  r  r   ssl_errssl_err_strserver_strings	            r   test_networked_good_certz"HTTPSTest.test_networked_good_certY  s   


###&B#-.IJJ 	2 	2nnS%<==GW0#2CDDDW3T:::))*JKKK*+F3:< < <		%%%%}}<   !'ll 90+>> C"+B{ B B9B B BC C C  !NN844MJJLLLGGIIIMM'=1115	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s9   A0F AC"!F"
D1,A D,,D11AFFFc                    dd l }t          j        d           t          j        d          5  |                    |j                  }|                    t                     t          j
        dd|          }|                     |j                  5 }|                    dd           d d d            n# 1 swxY w Y   |                     |j        j        d           d d d            d S # 1 swxY w Y   d S )	Nr   r.  r/  r0  r9  r   r   r1  )r2  r   r3  r   r4  rC  rD  rH  CERT_localhostr   r  r  r5  r   r   r@  r(  )r   r2  r:  r  r6  s        r   test_networked_bad_certz!HTTPSTest.test_networked_bad_certz  s   


###-.JKK 	U 	UnnS%<==G)).999&'CSRYZZZA""3<00 &H		%%%%& & & & & & & & & & & & & & &X/68STTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us6   A&C.B6*C.6B:	:C.=B:	>#C..C25C2c                 F   dd l }|                     t                    }t          j        d|j                  }|                     |j                  5 }|                    dd           d d d            n# 1 swxY w Y   | 	                    |j
        j        d           d S )Nr   	localhostr   r   r1  )r2  r*  rS  r   r  r   r  r5  r   r   r@  r(  )r   r2  r<  r  r6  s        r   test_local_unknown_certz!HTTPSTest.test_local_unknown_cert  s    


!!.11";<<s|,, 	"IIeS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"+24OPPPPPs   A66A:=A:c                    dd l }|                     t                    }|                    |j                  }|                    t                     t          j        d|j        |          }| 	                    |j
                   |                    dd           |                                }| 	                    |j
                   |                     |j        d           d S )Nr   rV  r9  r   /nonexistentr,  )r2  r*  rS  rC  rD  rH  r   r  r   r{  r)   r   r5  r   r'  r   r2  r<  r:  r  r   s         r   test_local_good_hostnamez"HTTPSTest.test_local_good_hostname  s    


!!.11..!899%%n555";WMMM   			%(((}}
###c*****r   c                 |   dd l }|                     t                    }|                    |j                  }|                    t                     t          j        d|j        |          }| 	                    |j
                  5  |                    dd           d d d            n# 1 swxY w Y   t          j        dt          f          5  t          j        d|j        |d          }d d d            n# 1 swxY w Y   | 	                    |j
                  5  |                    dd           d d d            n# 1 swxY w Y   d	|_        t          j        dt          f          5  t          j        d|j        |d	          }d d d            n# 1 swxY w Y   |                    dd
           |                                }|                                 |                                 |                     |j        d           d	|_        t          j        d|j        |          }|                    dd
           |                                }|                     |j        d           |                                 |                                 t          j        dt          f          5  t          j        d|j        |d          }d d d            n# 1 swxY w Y   | 	                    |j
                  5  |                    dd           d d d            d S # 1 swxY w Y   d S )Nr   rV  r9  r   r   r   T)r:  rG  FrY  r,  )r2  r*  CERT_fakehostnamerC  rD  rH  r   r  r   r  CertificateErrorr   r	   check_warningsDeprecationWarningrG  r5  r)   r   r'  rZ  s         r   test_local_bad_hostnamez!HTTPSTest.test_local_bad_hostname  s   


!!"344..!899%%&7888";WMMMs344 	" 	"IIeS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" +R1C,DEE 	M 	M&{FK/6tM M MA	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M s344 	" 	"IIeS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" "'+R1C,DEE 	N 	N&{FK/6uN N NA	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	
		%(((}}

				c*** "'";WMMM			%(((}}c***

				 +R1C,DEE 	M 	M&{FK/6tM M MA	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M s344 	" 	"IIeS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"sl   	B,,B03B0C<<D D !EEE1FF"F>K((K,/K,L11L58L5r  z)http.client.HTTPSConnection not availablec                    dD ]-}|                      t          j        t          j        |           .dD ]P\  }}}t          j        |          }|                     ||j                   |                     ||j                   Qd S )Nr  )r  )zwww.python.org:443r  r0  )r  r  r0  )r  r  r0  )r  r  r0  )r  r  r0  )r  r   r  r  r   r   r   r  s        r   r  zHTTPSTest.test_host_port  s    
 I 	M 	MBf/1GLLLL# 
	( 
	(HB1 &r**AQ'''Q''''
	( 
	(r   c                    dd l }|j        s|                     d           t          j        dd          }|                     |j        j                   |                    |j	                  }| 
                    |j                   t          j        dd|          }|                     |j        |           | 
                    |j        j                   t          j                    5  t          j        ddt                     t          j        dd|t                     }d d d            n# 1 swxY w Y   |                     |j        j                   d S )	Nr   zTLS 1.3 support requiredrV  r0  r9  ignorez5key_file, cert_file and check_hostname are deprecated)r:  	cert_file)r2  HAS_TLSv1_3r%  r   r  r   _contextpost_handshake_authrC  rD  r  assertIswarningscatch_warningsfilterwarningsr`  rS  )r   r2  r  r:  s       r   test_tls13_phazHTTPSTest.test_tls13_pha  s   


 	6MM4555";44
6777..!8994555";WEEEaj'***7888$&& 	A 	A#H.e$68 8 8&{C1?A A AA	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A
 	
677777s   -9D22D69D6N)r8   r9   r:   r  r*  r,  r7  r>  r   system_must_validate_certrA  rQ  rT  rW  r[  ra  r  r  r  r   r  rm  r1   r   r   r#  r#  %  s(       2 2 2: : :( ( (
U U U   &
5 
5 '&
52 2 2B
U 
U 
UQ Q Q+ + +(" (" ("T X_):;;;@B B( (B B($8 8 8 8 8r   r#  c                   H    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S )RequestBodyTestz3Test cases where a request includes a message body.c                     t          j        d          | _        t          d          x| j        _        | _        | j        | j        _        d S )NrW   r   )r   r   r   r   r   r.   s    r   r  zRequestBodyTest.setUp  s9    )-88	%/^^3		r   c                     t          j        | j        j                  }|                                 t          j        |          }||fS r0   )r;   r<   r   r   rP   r   r  r   fmessages      r   get_headers_and_fpz"RequestBodyTest.get_headers_and_fp  s<    Jty~&&	

&q))zr   c                 V   ddgdfdf}|D ]\  }}|                      |          5  t          j        d          | _        t	          d          x| j        _        | _        | j                            dd|           |                                 \  }}|                     d	|           |                     d
|           | 	                    |
                    d          d           | 	                    ||                                           d d d            n# 1 swxY w Y   d S )Nr     bar   3
foo
3
bar
0

))r  rx  ry  rW   r   r   r3  zContent-Typer   r   r  )r   r   r   r   r   r   r   rv  r  r   getrL   )r   r   r   r   r   rt  s         r   test_list_bodyzRequestBodyTest.test_list_body  sh   
 fCDD
 $ 
	5 
	5ND(d## 	5 	5"1-@@	-7^^;		!!%6660022Q  555  !13777  )<!=!=yIII  16688444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5
	5 
	5s   C*DD 	#D 	c                 .   | j                             dddddi           |                                 \  }}|                     d|                    d                     |                     dt          |                                                     d S )Nr   r3  r   r   42r  r  )r   r   rv  r   rz  ro   rL   r   ru  rt  s      r   test_manual_content_lengthz*RequestBodyTest.test_manual_content_length  s     		%+T2	4 	4 	4,,..
w{{+;<<===CMM*****r   c                    | j                             ddd           |                                 \  }}|                     d|                                           |                     |                                           |                     d|                    d                     |                     d|                                           d S )Nr   r3  r   
text/plain4r  s   body	r   r   rv  r   get_content_typer  get_charsetrz  rL   r~  s      r   test_ascii_bodyzRequestBodyTest.test_ascii_body  s    	%000,,..
w'?'?'A'ABBB'--//000gkk*:;;<<<!&&((+++++r   c                    | j                             ddd           |                                 \  }}|                     d|                                           |                     |                                           |                     d|                    d                     |                     d|                                           d S )Nr   r3  u   bodyÁr  5r     bodyr  r~  s      r   test_latin1_bodyz RequestBodyTest.test_latin1_body#  s    	%444,,..
w'?'?'A'ABBB'--//000gkk*:;;<<<affhh/////r   c                    | j                             ddd           |                                 \  }}|                     d|                                           |                     |                                           |                     d|                    d                     |                     d|                                           d S )Nr   r3  r  r  r  r  r  r~  s      r   test_bytes_bodyzRequestBodyTest.test_bytes_body+  s    	%555,,..
w'?'?'A'ABBB'--//000gkk*:;;<<<affhh/////r   c                 J   |                      t          j        t          j                   t	          t          j        dd          5 }|                    d           d d d            n# 1 swxY w Y   t	          t          j        d          5 }| j                            dd|           |                                 \  }}| 	                    d|
                                           |                     |                                           |                     |                    d                     | 	                    d	|                    d
                     | 	                    d|                                           d d d            d S # 1 swxY w Y   d S )Nwr  )encodingr   r   r3  r  r  r  ztransfer-encodings   4
body
0

)r{  r   unlinkTESTFNr  writer   r   rv  r   r  r  r  rz  rL   rs  s      r   test_text_file_bodyz#RequestBodyTest.test_text_file_body3  s   	()*:;;;)"C'::: 	aGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	)"W555 		BIeVQ///0022JGQ\7+C+C+E+EFFFg1133444 gkk*:;;<<<Y4G(H(HIII6AAA		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		Bs%   A))A-0A-C<FFFc                     |                      t          j        t          j                   t	          t          j        d          5 }|                    d           d d d            n# 1 swxY w Y   t	          t          j        d          5 }| j                            dd|           |                                 \  }}| 	                    d|
                                           |                     |                                           | 	                    d|                    d                     |                     d	|           | 	                    d
|                                           d d d            d S # 1 swxY w Y   d S )Nwbr  r%   r   r3  r  r  r   r   s   5
body
0

)r{  r   r  r  r  r  r   r   rv  r   r  r  r  rz  r  rL   rs  s      r   test_binary_file_bodyz%RequestBodyTest.test_binary_file_bodyB  s   	()*:;;;)"D)) 	!QGGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!)"D)) 	FQIeVQ///0022JGQ\7+C+C+E+EFFFg1133444Y4G(H(HIII-w777:AFFHHEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs%   A''A+.A+C*FF
FN)r8   r9   r:   rS   r  rv  r{  r  r  r  r  r  r  r1   r   r   rp  rp    s        ==# # #
  5 5 5(+ + +, , ,0 0 00 0 0B B BF F F F Fr   rp  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )HTTPResponseTestc                     d}t          |          }t          j        |          | _        | j                                         d S )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.setUpR  s@    *$'--		r   c                     | j                             d          }|                     |d           | j                             dd          }|                     |d           d S )Nz	My-Headerzfirst-value, second-valuezsome defaultr   r   r   r   r   s     r   test_getting_headerz$HTTPResponseTest.test_getting_headerY  sb    $$[11!<===$$[.AA!<=====r   c                 h    | j                             dd          }|                     |d           d S )NNo-Such-Headerzdefault-valuer  r  s     r   3test_getting_nonexistent_header_with_string_defaultzDHTTPResponseTest.test_getting_nonexistent_header_with_string_default`  s6    $$%5GG11111r   c                     | j                             dddg          }|                     |d           | j                             dd          }|                     |d           d S )Nr  defaultvalueszdefault, values)r  r  r  r  s     r   5test_getting_nonexistent_header_with_iterable_defaultzFHTTPResponseTest.test_getting_nonexistent_header_with_iterable_defaultd  sl    $$%5	87LMM!2333$$%57LMM!233333r   c                 f    | j                             d          }|                     |d            d S )Nr  r  r  s     r   /test_getting_nonexistent_header_without_defaultz@HTTPResponseTest.test_getting_nonexistent_header_without_defaultk  s4    $$%566&&&&&r   c                 j    | j                             dd          }|                     |d           d S )Nr  r   )r  r  r  s     r   test_getting_header_defaultintz/HTTPResponseTest.test_getting_header_defaultinto  s9    $$%5b$AA$$$$$r   N)	r8   r9   r:   r  r  r  r  r  r  r1   r   r   r  r  P  sn          > > >2 2 24 4 4' ' '% % % % %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S )TunnelTestsc                     d}d| _         t          j        | j                   | _        |                     |          | j        _        d S )Nz:HTTP/1.0 200 OK

HTTP/1.1 200 OK
Content-Length: 42

z	proxy.com)r   r   r   r   r\   )r   response_texts     r   r  zTunnelTests.setUpt  sG    ) 	
  	)$)44	'+'>'>}'M'M	$$$r   c                 8    | j                                          d S r0   )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   )rq  r  r  r  s      r   r[   z9TunnelTests._create_connection.<locals>.create_connection  s     m'!*71:NNNNr   NNr1   )r   r  r[   s    ` r   r\   zTunnelTests._create_connection  s-    	O 	O 	O 	O 	O 	O  r   c                    d}d}ddi}| j                             |||           | j                             ddd           |                     | j         j        j        | j                   |                     | j         j        j        t          j                   |                     | j         j	        |           |                     | j         j
        |           |                     | j         j        |           d S )	Ndestination.comi"  z
User-Agentz!Mozilla/5.0 (compatible, MSIE 11))r   r   r   r   r   )r   
set_tunnelr   r   r   r   r   r   	HTTP_PORT_tunnel_host_tunnel_port_tunnel_headers)r   tunnel_hosttunnel_porttunnel_headerss       r   !test_set_tunnel_host_port_headersz-TunnelTests.test_set_tunnel_host_port_headers  s    '&(KL	[{%3 	 	5 	5 	5	&#r***,di888,f.>???/===/===2NCCCCCr   c                     | j                                          |                     t          | j         j        d           d S )Nr  )r   r`   r  RuntimeErrorr  r.   s    r   &test_disallow_set_tunnel_after_connectz2TunnelTests.test_disallow_set_tunnel_after_connect  sD    	,	(<+	- 	- 	- 	- 	-r   c                 L   | j                             d           | j                             ddd           |                     | j         j        j        | j                   |                     | j         j        j        t          j                   | 	                    d| j         j        j
                   |                     d| j         j        j
                   | 	                    d| j         j        j
                   |                     d| j         j        j
                   d S )	Nr  r   r   r      CONNECT destination.coms   Host: destination.com:None   Host: destination.coms   Host: proxy.com)r   r  r   r   r   r   r   r   r  r   r   r  r.   s    r   test_connect_with_tunnelz$TunnelTests.test_connect_with_tunnel  s    	.///	&#r***,di888,f.>???0$).2EFFF6	8KLLL.	0CDDD 	+TY^-@AAAAAr   c                 `   t           j                            | j        d          5 }| j                            d           | j                                         | j                            dd           ddd           n# 1 swxY w Y   |                                 |                     t          |j
                  dd|j
                    |j
        d	         d         d	         }|                     d
|           |                     |                    d          d|           dS )z8Regresstion test for https://bugs.python.org/issue43332.r  r  r   r   Nr    z!unexpected number of send calls: )r   r   r  r
  zunexpected proxy data sent )r   patchobjectr   r  r`   r   assert_calledr  ro   
mock_callsr   r   r   )r   	mock_sendproxy_setup_data_sents      r   0test_tunnel_connect_single_send_connection_setupz<TunnelTests.test_tunnel_connect_single_send_connection_setup  sz   Zty&11 	*YI  !2333IIeS)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	!!!I())1N	8LNN 	 	P 	P 	P !* 4Q 7 :1 =02GHHH%..{;;K2GKK 	 	M 	M 	M 	M 	Ms   ABBBc                    | j                             d           | j                             ddd           |                     | j         j        j        | j                   |                     | j         j        j        t          j                   | 	                    d| j         j        j
                   | 	                    d| j         j        j
                   d S )Nr  r   r   r   r  r  )r   r  r   r   r   r   r   r   r  r   r   r.   s    r   test_connect_put_requestz$TunnelTests.test_connect_put_request  s    	.///	%b))),di888,f.>???0$).2EFFF.	0CDDDDDr   c                    d}d                     |          }| j                            d           |                     |          | j        _        | j                            d           t          j                    5 }| j                            ddd           d d d            n# 1 swxY w Y   |                                	                                }| 
                    d                     |          |           d S )	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_debuglog  s   &7>>OO	  ###'+'>'>}'M'M	$	.///$&& 	.&IeS"---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.!!,,..l))/::EBBBBBs   >B''B+.B+c                 4   d dfd	}|| j         _        | j                             d           d }	 | j                             ddd           n# t          $ r}|}Y d }~nd }~ww xY w|                     |           |                     j                   d S )Nc                 D    t          d| d         | d                   S )NzHTTP/1.1 404 NOT FOUND

r   r    r  r  )rq  r  r  r   s      r   r\   z8TunnelTests.test_tunnel_leak.<locals>._create_connection  s/    0QZQZ  D
 Kr   r  r   r   r   r  )r   r\   r  r   rC   r   r   r   )r   r\   r  er   s       @r   test_tunnel_leakzTunnelTests.test_tunnel_leak  s    	 	 	 	 	 	 (:	$	.///	Ifc2.... 	 	 	CCCCCC	 	S!!!()))))s   A 
A&A!!A&N)r8   r9   r:   r  r  r\   r  r  r  r  r  r  r  r1   r   r   r  r  s  s        N N N  ! ! !
D D D- - -B B BM M M"E E EC C C* * * * *r   r  __main__r   )	verbosity)>r  rD   httpr   r   r;   r   osr  rJ  rx  r|  rj  r  r   TestCaser  r   test.supportr   r   r	   requires_working_socketpathdirnamer  herer   rS  r]  rI  r  r  chunk_extensionr  rP  r$  r  rz  r   r>   r<   rH   r   rU   rf   r   r   r(  r  r  r  r  r  r  r  r#  rp  r  r  r8   mainr1   r   r   <module>r     s?     # # # # # # # # 				     				  				                    " " " " " " & & & & & & ( ( ( ( ( (  t , , , ,	wx  dM22GLL~66 #%7<<6W#X#X  	-  N 
O+f4 -       B    *       2:   $2 2 2 2 2v4 2 2 2"j; j; j; j; j;( j; j; j;Z5 5 5 5 5h 5 5 5,} } } } }8 } } }@w' w' w' w' w' w' w' w'tz( z( z( z( z(x z( z( z(z    .   ,       DR8 R8 R8 R8 R8( R8 R8 R8j7 7 7 7 7 7 7 7>+ + + + +( + + +\E. E. E. E. E.h E. E. E.PH8 H8 H8 H8 H8 H8 H8 H8V]F ]F ]F ]F ]Fh ]F ]F ]F@!% !% !% !% !%x !% !% !%Fn* n* n* n* n*( n* n* n*b zHMA r   