
    Xhȏ                        d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlZd dl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mZmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZ d d	l m!Z! d d
l"m#Z#m$Z$ d dlm%Z% d dl&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3  G d de/      Z4 G d de/      Z5 G d de/      Z6 G d de/      Z7 G d de/      Z8 G d de/      Z9 G d de/      Z: G d de/      Z; G d  d!e/      Z< G d" d#e/      Z= G d$ d%e/      Z> G d& d'e/      Z? G d( d)e/      Z@ G d* d+e/      ZA G d, d-e/      ZB G d. d/e/      ZC G d0 d1e'      ZD G d2 d3ej                        ZF G d4 d5ej                        ZG G d6 d7ej                        ZH G d8 d9ej                        ZI G d: d;ej                        ZJ G d< d=ej                        ZKy)>    N)closing)BytesIO)utf8
native_str
to_unicode)gen)HTTPRequestHTTPResponse_RequestProxy	HTTPError
HTTPClient)
HTTPServer)IOLoop)IOStream)gen_logapp_log)netutil)AsyncHTTPTestCasebind_unused_portgen_test	ExpectLog)ignore_deprecation)ApplicationRequestHandlerurl)format_timestampHTTPHeadersc                       e Zd Zd Zy)HelloWorldHandlerc                 t    | j                  dd      }| j                  dd       | j                  d|z         y )NnameworldContent-Type
text/plainz	Hello %s!)get_argument
set_headerfinish)selfr!   s     P/var/www/html/myenv/lib/python3.12/site-packages/tornado/test/httpclient_test.pygetzHelloWorldHandler.get%   s3      15K$&'    N__name__
__module____qualname__r*    r+   r)   r   r   $   s    (r+   r   c                       e Zd Zd Zy)PostHandlerc                 n    | j                  d| j                  d      d| j                  d             y )NzPost arg1: arg1z, arg2: arg2)r'   r%   r(   s    r)   postzPostHandler.post,   s/      ($*;*;F*CE	
r+   Nr-   r.   r/   r7   r0   r+   r)   r2   r2   +       
r+   r2   c                       e Zd Zd Zy)
PutHandlerc                 p    | j                  d       | j                  | j                  j                         y )Nz
Put body: writerequestbodyr6   s    r)   putzPutHandler.put4   s$    

< 

4<<$$%r+   N)r-   r.   r/   rA   r0   r+   r)   r;   r;   3       &r+   r;   c                       e Zd Zd Zy)RedirectHandlerc           	          | j                  d       | j                  | j                  d      t        | j                  dd                   y )Nzredirects can have bodies toor   status302)rF   )r>   redirectr%   intr6   s    r)   preparezRedirectHandler.prepare:   sB    

23e$S1B1B8U1S-T 	 	
r+   Nr-   r.   r/   rJ   r0   r+   r)   rD   rD   9   r9   r+   rD   c                       e Zd Zd Zy)RedirectWithoutLocationHandlerc                 F    | j                  d       | j                          y )N-  )
set_statusr'   r6   s    r)   rJ   z&RedirectWithoutLocationHandler.prepareB   s    r+   NrK   r0   r+   r)   rM   rM   A   s    r+   rM   c                   0    e Zd Zej                  d        Zy)ChunkHandlerc              #      K   | j                  d       | j                          t        j                  d       | j                  d       y w)Nasdf{Gz?qwer)r>   flushr   sleepr6   s    r)   r*   zChunkHandler.getI   s5     

6

iio

6s   AAN)r-   r.   r/   r   	coroutiner*   r0   r+   r)   rR   rR   H   s    ]] r+   rR   c                       e Zd Zd Zy)AuthHandlerc                 T    | j                  | j                  j                  d          y )NAuthorization)r'   r?   headersr6   s    r)   r*   zAuthHandler.getS   s    DLL((9:r+   Nr,   r0   r+   r)   r[   r[   R   s    ;r+   r[   c                       e Zd Zd Zy)CountdownHandlerc                     t        |      }|dkD  r%| j                  | j                  d|dz
               y | j                  d       y )Nr   	countdown   Zero)rI   rH   reverse_urlr>   )r(   counts     r)   r*   zCountdownHandler.getX   s;    E
19MM$**;	BCJJvr+   Nr,   r0   r+   r)   r`   r`   W   s    r+   r`   c                       e Zd Zd Zy)EchoPostHandlerc                 N    | j                  | j                  j                         y Nr=   r6   s    r)   r7   zEchoPostHandler.posta   s    

4<<$$%r+   Nr8   r0   r+   r)   rh   rh   `   s    &r+   rh   c                       e Zd Zd Zy)UserAgentHandlerc                 n    | j                  | j                  j                  j                  dd             y )N
User-AgentzUser agent not set)r>   r?   r^   r*   r6   s    r)   r*   zUserAgentHandler.getf   s&    

4<<''++L:NOPr+   Nr,   r0   r+   r)   rl   rl   e   s    Qr+   rl   c                       e Zd Zd Zd Zy)ContentLength304Handlerc                 J    | j                  d       | j                  dd       y )N0  Content-Length*   )rP   r&   r6   s    r)   r*   zContentLength304Handler.getk   s    ("-r+   c                      y rj   r0   r6   s    r)   _clear_representation_headersz5ContentLength304Handler._clear_representation_headerso   s     	r+   N)r-   r.   r/   r*   rv   r0   r+   r)   rp   rp   j   s    .r+   rp   c                       e Zd Zd Zy)PatchHandlerc                 N    | j                  | j                  j                         y)z=Return the request payload - so we can check it is being keptNr=   r6   s    r)   patchzPatchHandler.patchv   s    

4<<$$%r+   N)r-   r.   r/   rz   r0   r+   r)   rx   rx   u   rB   r+   rx   c                   P    e Zd Zej                  dz   Zd ZexZxZxZxZ	xZ
xZxZZy)AllMethodsHandler)OTHERc                 ~    | j                   j                  J | j                  | j                   j                         y rj   )r?   methodr>   r6   s    r)   r   zAllMethodsHandler.method~   s.    ||""...

4<<&&'r+   N)r-   r.   r/   r   SUPPORTED_METHODSr   r*   headr7   rA   deleteoptionsrz   otherr0   r+   r)   r|   r|   {   sD    &88:E( BHGCG$GGGfGwGr+   r|   c                       e Zd Zd Zy)SetHeaderHandlerc                     t        | j                  d      | j                  j                  d         D ]  \  }}| j	                  ||        y )Nkv)zipget_argumentsr?   	argumentsr&   )r(   r   r   s      r)   r*   zSetHeaderHandler.get   sF     **3/1G1G1LM 	"DAqOOAq!	"r+   Nr,   r0   r+   r)   r   r      s    "r+   r   c                       e Zd ZddZy)InvalidGzipHandlerNc                    | j                  dd       | j                  dd       dj                  d t        d      D              d d }t        j                  |j                         d	
      dz   }| j                  |       y )Nr#   r$   Content-Encodinggzip c              3   (   K   | ]
  }d | d  yw)zHello World 
Nr0   ).0is     r)   	<genexpr>z)InvalidGzipHandler.get.<locals>.<genexpr>   s     AaS+As   i(#  i;F    )compresslevel    )r&   joinranger   compressencoder>   )r(   textr@   s      r)   r*   zInvalidGzipHandler.get   sg    5*F3 wwAU4[AA'6J}}T[[]!<vE

4r+   )returnNr,   r0   r+   r)   r   r      s    	r+   r   c                       e Zd Zd Zy)HeaderEncodingHandlerc                 r    | j                  | j                  j                  d   j                  d             y )NFoo	ISO8859-1)r'   r?   r^   r   r6   s    r)   r*   zHeaderEncodingHandler.get   s(    DLL((/66{CDr+   Nr,   r0   r+   r)   r   r      s    Er+   r   c                   R   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ed        Zd Zd Zed        Zd Zed        Z ed        Z!ed        Z"ed         Z#ed!        Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*ed(        Z+d) Z,y*)+HTTPClientCommonTestCasec                     t        t        dt              t        dt              t        dt              t        dt
              t        dt              t        dt              t        dt              t        dt        d	
      t        dt              t        dt              t        dt              t        dt              t        dt              t        dt              t        dt               t        dt"              gd      S )N/hello/postz/putz	/redirect/redirect_without_location/chunk/authz/countdown/([0-9]+)rb   )r!   	/echopost/user_agent/304_with_content_length/all_methods/patchz/set_header/invalid_gzip/header-encodingT)r   )r   r   r   r2   r;   rD   rM   rR   r[   r`   rh   rl   rp   r|   rx   r   r   r   r6   s    r)   get_appz HTTPClientCommonTestCase.get_app   s    H/0G[)FJ'K102PQHl+G[))+;+NK1M#34.0GHN$56Hl+M#34O%78&(=>!$ '
 	
r+   c                     d}| j                  dd|      }| j                  |j                  d       | j                  |j                  |       y )Ns   some patch datar   PATCHr   r@      fetchassertEqualcoder@   )r(   r@   responses      r)   test_patch_receives_payloadz4HTTPClientCommonTestCase.test_patch_receives_payload   sC    !::hwT:B,-r+   c                    | j                  d      }| j                  |j                  d       | j                  |j                  d   d       | j                  |j                  d       |j
                  J | j                  t        |j
                        d       | j                  d      }| j                  |j                  d       y )	Nr   r   r#   r$      Hello world!r   z/hello?name=Bens
   Hello Ben!)r   r   r   r^   r@   request_timerI   r(   r   s     r)   test_hello_worldz)HTTPClientCommonTestCase.test_hello_world   s    ::h',)).9<H8$$000X223Q7::/06r+   c                     g }| j                  d|j                        }| j                  |dg       | j                  |j                         y )Nr   streaming_callbackr   )r   appendr   assertFalser@   )r(   chunksr   s      r)   test_streaming_callbackz0HTTPClientCommonTestCase.test_streaming_callback   sB    ::h6==:I/!23'r+   c                     | j                  ddd      }| j                  |j                  d       | j                  |j                  d       y )Nr   POSTzarg1=foo&arg2=barr   r   s   Post arg1: foo, arg2: barr   r   s     r)   	test_postz"HTTPClientCommonTestCase.test_post   s@    ::gf;N:O,(DEr+   c                     | j                  d      }| j                  |j                  d       g }| j                  d|j                        }| j                  |ddg       | j	                  |j                         y )Nr      asdfqwerr      asdf   qwer)r   r   r@   r   r   )r(   r   r   s      r)   test_chunkedz%HTTPClientCommonTestCase.test_chunked   sf    ::h'4::h6==:I'7!34'r+   c                     t               \  }}t        |      5  t        j                   fd       }t	        j
                  ||        j                  d|z        }|j                           j                  |j                  d        j                  j                  |j                                d d d        y # 1 sw Y   y xY w)Nc              3      K   t        |       }|j                  d      }d|vrj                  d       |j                  dj	                  dd             |j                          y w)N   

   HTTP/1.requires HTTP/1.xs7   HTTP/1.1 200 OK
Transfer-Encoding: chunked

1
1
1
2
0

   
   
r   
read_untilskipTestr>   replacecloseconnaddressstreamrequest_datar(   s       r)   accept_callbackzDHTTPClientCommonTestCase.test_chunked_close.<locals>.accept_callback   sl      "$%+%6%6{%CC\1MM"56ll
 Gw     A(A+http://127.0.0.1:%d/s   12)r   r   r   rY   r   add_accept_handlerr   rethrowr   r@   io_loopremove_handlerfilenor(   sockportr   resps   `    r)   test_chunked_closez+HTTPClientCommonTestCase.test_chunked_close   s     &'
dT] 	7]] 0 &&t_=::4t;<DLLNTYY.LL''6?	7 	7 	7s   BB;;Cc                 `    | j                  | j                  ddd      j                  d       y )Nr   Aladdinopen sesameauth_usernameauth_password"   Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==r   r   r@   r6   s    r)   test_basic_authz(HTTPClientCommonTestCase.test_basic_auth  s0    JJy  d1		
r+   c                 b    | j                  | j                  dddd      j                  d       y )Nr   r   r   basic)r   r   	auth_moder   r   r6   s    r)   test_basic_auth_explicit_modez6HTTPClientCommonTestCase.test_basic_auth_explicit_mode  s7    JJ'+!	  
 d1	
r+   c                     | j                  | j                  ddd      j                  d       t        j                  dd      }| j                  | j                  d|d      j                  d	       y )
Nr   testu   123£r   s   Basic dGVzdDoxMjPCow==NFDu   joséu   səcrəts   Basic am9zw6k6c8mZY3LJmXQ=)r   r   r@   unicodedata	normalize)r(   usernames     r)   test_basic_auth_unicodez0HTTPClientCommonTestCase.test_basic_auth_unicode  sh    JJwfGJLQQ%	
 ((8JJwhjJQVV)	
r+   c           	          t        t        dd      5  | j                  t        t        f      5  | j                  ddddd	       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
Nzuncaught exceptionFrequiredr   r   r   rT   T)r   r   r   raise_error)r   r   assertRaises
ValueErrorr   r   r6   s    r)   test_unsupported_auth_modez3HTTPClientCommonTestCase.test_unsupported_auth_mode+  ss     w 4uE 	""J	#:; 

"+"/$ $  	 	 	 	s"   A#AA#A 	A##A,c                    | j                  dd      }| j                  d|j                         | j                  |j                  d   j                  d             | j                  d      }| j                  d|j                         | j                  |j                  j                  d             | j                  d	|j                         y )
Nz/countdown/2Ffollow_redirects.  Locationz/countdown/1r   z/countdown/0s   Zero)r   r   r   
assertTruer^   endswitheffective_urlr@   r   s     r)   test_follow_redirectz-HTTPClientCommonTestCase.test_follow_redirect9  s    ::nu:Ehmm,((4==nMN::n-hmm,..77GH(--0r+   c                 b    | j                  dd      }| j                  d|j                         y )Nr   Tr  rO   r   r   r   r   s     r)   test_redirect_without_locationz7HTTPClientCommonTestCase.test_redirect_without_locationC  s+    :::T:R
 	hmm,r+   c                 d    | j                  ddd      }| j                  |j                  d       y )N/redirect?url=/put&status=307PUThellor      Put body: hellor   r   r@   r   s     r)   test_redirect_put_with_bodyz4HTTPClientCommonTestCase.test_redirect_put_with_bodyK  s3    ::+E  
 	(:;r+   c                 d    | j                  ddd      }| j                  |j                  d       y )Nr  r  Tr   allow_nonstandard_methodss
   Put body: r  r   s     r)   test_redirect_put_without_bodyz7HTTPClientCommonTestCase.test_redirect_put_without_bodyQ  s4    ::+&*  

 	6r+   c                    dD ]  }d|z  }| j                  |dd      }| j                  d|j                         dD ]g  }| j                  ||d	      }|d
v r&| j                  t        |      |j                         A| j	                  |j                  t        |      dg       i | j                  |d      }| j                  d|j
                         | j                  d|j                          dD ]  }d}dD ];  }| j                  ||d	      }| j                  |t        |j                               = | j                  |d      }| j                  d|j
                         | j                  d|j                          y )N)rO   r  i/  z$/redirect?url=/all_methods&status=%dr   r+   r   s   GET)GETOPTIONSr  DELETETr!  )rO   r  HEADr   r   )i3  i4  z%/redirect?url=/all_methods&status=307)r%  r&  r   r  r'  )r   r   r@   r   assertInr   r   )r(   rF   r   r   r   s        r)   test_method_after_redirectz3HTTPClientCommonTestCase.test_method_after_redirectZ  ss   % 	-F86AC::c&s:;DVTYY/ > Ezz#fPTzUZ'$$T&\499=MM$))d6lF-CDE ::c&:1DS$)),S$)),!	-& ! 	-F9CE @zz#fPTzU  DII)>?@ ::c&:1DS$)),S$)),	-r+   c                     | j                  d      j                  dd      }| j                  |      }| j                  dt	        j
                  d      z   |j                         y )Nr   zhttp://zhttp://me:secret@s   Basic s	   me:secret)get_urlr   r   r   base64	b64encoder@   )r(   r   r   s      r)   test_credentials_in_urlz0HTTPClientCommonTestCase.test_credentials_in_urlx  sO    ll7#++I7JK::c?V%5%5l%CCX]]Sr+   c                 2   d}t        j                  d      }| j                  dd|ddi      }| j                  |j                  d   d	       | j                  |j
                  t        |             | j                  dd|ddi      }| j                  |j                  d   d
       | j                  |j
                  |       | j                  dd|ddid      }| j                  |j                  d   d
       | j                  |j
                  |       y )N   és   e9r   r   r#   zapplication/blah)r   r@   r^   rs   21foo)r   r@   r^   
user_agent)binasciia2b_hexr   r   r^   r@   r   )r(   unicode_body	byte_bodyr   s       r)   test_body_encodingz+HTTPClientCommonTestCase.test_body_encoding}  s*   $$U+	 ::#%78	  
 	))*:;SA\(:; ::#%78	  
 	))*:;SA	2 ::#%78  
 	))*:;SA	2r+   c                 t   | j                  d      }| j                  t        |j                        t               | j                  t        |j
                  d         t               | j                  t        |j                        t               | j                  t        |j                        t               y )Nr   r#   )
r   r   typer@   bytesr^   strr   rI   r  r   s     r)   
test_typesz#HTTPClientCommonTestCase.test_types  s}    ::h'hmm,e4h..~>?Ehmm,c2h445s;r+   c                 r   | j                  ddddi      }| j                  |j                  d   d       | j                  |j                  d       | j                  t        |j                        d       t        j                  d	|j                  
      }| j                  |j                         d       y )Nr   FzAccept-Encodingr   )decompress_responser^   r   r   "   r)modefileobj)
r   r   r^   assertNotEqualr@   lenr   GzipFilebufferread)r(   r   fs      r)   	test_gzipz"HTTPClientCommonTestCase.test_gzip  s     ::%:KV9T  
 	))*<=vFHMM;7 	X]]+R0MMsHOO<;/r+   c                 
   t        t        dd      5  	 | j                  d      }| j                  |j                  d       | j                  |j
                  d d d       d d d        y # t        $ r Y w xY w# 1 sw Y   y xY w)Nz..*Malformed HTTP message.*unconsumed gzip dataFr  r   r      s   Hello World 0
)r   r   r   r   r   r@   r   r   s     r)   test_invalid_gzipz*HTTPClientCommonTestCase.test_invalid_gzip  s     EPU
 	::o6  4  s!35GH	 	  	 	s)   A9AA**	A63A95A66A99Bc                      g i g fd} fd} j                  d||        j                  t              d        j                  d   d        j                  dd	g       y )
Nc                     | j                  d      ry | j                  d      rj                  |        y | dk7  r7| j                  dd      \  }}|j                         |j	                         <   y y )NzHTTP/1.1 101HTTP/z
:rc   )
startswithr   splitstriplower)header_liner   r   
first_liner^   s      r)   header_callbackzFHTTPClientCommonTestCase.test_header_callback.<locals>.header_callback  si    %%n5''0!!+.&"((a01%&WWY	" 'r+   c                 R    j                  d   d       j                  |        y )Nzcontent-typeztext/html; charset=UTF-8)r   r   )chunkr   r^   r(   s    r)   r   zIHTTPClientCommonTestCase.test_header_callback.<locals>.streaming_callback  s'     W^46PQMM% r+   r   )r[  r   rc   r   zHTTP/[0-9]\.[0-9] 200.*
r   r   )r   r   rH  assertRegex)r(   r[  r   r   rZ  r^   s   `  @@@r)   test_header_callbackz-HTTPClientCommonTestCase.test_header_callback  sz    
	/	! 	

+1 	 	

 	Z!Z8A(FG'7!34r+   c                     t               fd}| j                  d|       j                         D ]*  \  }}| j                  ||j	                         k(  ||f       , y )Nc                 L    | j                  d      ry j                  |        y )NrS  )rU  
parse_line)liner^   s    r)   r[  zTHTTPClientCommonTestCase.test_header_callback_to_parse_line.<locals>.header_callback  s     w't$r+   r   )r[  )r   r   get_allr  rW  )r(   r[  r   r   r^   s       @r)   "test_header_callback_to_parse_linez;HTTPClientCommonTestCase.test_header_callback_to_parse_line  sY    
 -	% 	

8_
=OO% 	4DAqOOANQF3	4r+   c              #   (  K   t        dd      }| j                  j                  d|      }	 |j                  | j	                  d            }| j                  |j                  d       |j                          y # |j                          w xY ww)NTestDefaultUserAgentF)r6  
allow_ipv6T)force_instancedefaultsr   s   TestDefaultUserAgent)dicthttp_client	__class__r   r-  r   r@   r   )r(   rj  clientr   s       r)   test_configure_defaultsz0HTTPClientCommonTestCase.test_configure_defaults  st     #9eL!!++4(+S	#\\$,,}*EFFHX]],CDLLNFLLNs   +B>A= ,B=BBc                     dD ]b  }t         t        fD ]Q  } |       }||d<   | j                  d|      }| j                  |j                  dd|j                  d|d|       S d y )	N)MyUserAgent   MyUserAgentrn   r   r^   rr  z	response=z, value=z, container=)rk  r   r   r   r@   )r(   value	containerr^   r   s        r)   test_header_typesz*HTTPClientCommonTestCase.test_header_types  sr    
 5 
	E"K0 		#+(-%zz-zA  II"yy%4		
	r+   c                     t               \  }}t        |      5  t        j                   fd       }t	        j
                  ||       	  j                  d|z        }|j                           j                  |j                  d   d        j                  j                  |j                                	 d d d        y #  j                  j                  |j                                w xY w# 1 sw Y   y xY w)Nc              3      K   t        |       }|j                  d      }d|vrj                  d       |j                  dj	                  dd             |j                          y w)Nr   r   r   s2   HTTP/1.1 200 OK
X-XSS-Protection: 1;
	mode=block

r   r   r   r   s       r)   r   zIHTTPClientCommonTestCase.test_multi_line_headers.<locals>.accept_callback  sj     !$%+%6%6{%CC\1MM"56ll
 Gw	 	 r   r   zX-XSS-Protectionz1; mode=block)r   r   r   rY   r   r   r   r   r   r^   r   r   r   r   s   `    r)   test_multi_line_headersz0HTTPClientCommonTestCase.test_multi_line_headers  s     &'
dT] 	;]] " &&t_=;zz"84"?@  .@!A?S++DKKM:5	; 	;4 ++DKKM:5	; 	;s$   /C.
AC )C. +C++C..C7c              #      K   | j                   j                  | j                  d      ddi      }| j                  |j                  dj                  d             y w)Nr   r   u   bärrs  r   )rl  r   r-  r   r@   r   r   s     r)   test_header_encodingz-HTTPClientCommonTestCase.test_header_encoding2  s\     ))//LL+,x 0 
 
 	(DEs   AAc                     | j                  d      }| j                  |j                  d       | j                  |j                  d   d       y )Nr   rr   rs   42)r   r   r   r^   r   s     r)   test_304_with_content_lengthz5HTTPClientCommonTestCase.test_304_with_content_length<  sC    
 ::89,))*:;TBr+   c              #      K   | j                   j                  | j                  d            }| j                  |j                  d       y wNr   r   rl  r   r-  r   r@   r   s     r)   test_future_interfacez.HTTPClientCommonTestCase.test_future_interfaceE  s<     ))//X0FGG8s   A
Ac              #     K   | j                  t              5 }| j                  j                  | j	                  d             d d d        j
                  J |j
                  j                  J | j                  |j
                  j                  d       | j                  |j
                  j                  j                  d       y # 1 sw Y   xY wwN	/notfound  )	r
  r   rl  r   r-  	exceptionr   r   r   )r(   contexts     r)   test_future_http_errorz/HTTPClientCommonTestCase.test_future_http_errorJ  s     y) 	DW""((k)BCC	D  ,,,  ))555**//5**3388#>	D 	Ds   C-C
BC
CCc              #      K   | j                   j                  | j                  d      d      }| j                  |j                  d       y w)Nr  F)r	  r  )rl  r   r-  r   r   r   s     r)   test_future_http_error_no_raisez8HTTPClientCommonTestCase.test_future_http_error_no_raiseS  sJ     ))//LL%5 0 
 
 	,s   AAc              #     K   | j                  d      }| j                  j                  |      }| j                  |j                  j
                  |       | j                  t        |j                  t                     | j                  j                  |j                        }| j                  |j                  d       y wr  )
r-  rl  r   r   r?   r   r  
isinstancer	   r@   )r(   r   r   	response2s       r)    test_reuse_request_from_responsez9HTTPClientCommonTestCase.test_reuse_request_from_responseZ  s      ll8$))//44))--s3
8#3#3[AB**001A1ABB	9s   CCc              #     K   | j                  d      }t        |d      }| j                  j                  |      }| j	                  |j
                  d       | j                  t        t        f      5 }t        |d      }| j                  j                  |       d d d        | j                  dt        j                               y # 1 sw Y   /xY ww)Nr   z	127.0.0.1network_interfacer   znot-interface-or-ip)r-  r	   rl  r   r   r   r
  r  r   r*  r?  r  )r(   r   r?   r   r  s        r)   test_bind_source_ipz,HTTPClientCommonTestCase.test_bind_source_ipg  s     ll8$c[A))//88,
I67 	27!#9NOG""((11	2 	+S1B1B-CD	2 	2s   A3C5+C .CCCc                    dD ]:  }| j                  d|      }| j                  |j                  t        |             < dD ];  }| j                  d|d      }| j                  |j                  t        |             = | j                  dd      }| j                  |j                  d       | j                  ddd	
      }| j                  |j                  d       y )Nr%  r'  r&  r   r)  r   r  r   r+   r   r(  r}   Tr!  s   OTHER)r   r   r@   r   )r(   r   r   s      r)   test_all_methodsz)HTTPClientCommonTestCase.test_all_methodss  s    2 	:Fzz.z@HX]]DL9	: / 	:Fzz.czJHX]]DL9	: ::nV:<,::7d  
 	1r+   c                 ~   dD ]  }| j                  t              5 }| j                  d|d       d d d        | j                  dt	        j
                               | j                  d|d      }| j                  |j                  d        dD ]  }| j                  t              5 }| j                  d|d	d
       d d d        | j                  dt	        j
                               |dk7  sa| j                  d|d	dd       | j                  j                  d        y # 1 sw Y   xY w# 1 sw Y   uxY w)Nr  r   T)r   r	  zmust not be Noner!  r   r  r   )r   r@   r	  zmust be Noner%  )r   r@   r"  r	  )r
  r  r   r*  r?  r  r   r   )r(   r   r  r   s       r)   test_body_sanity_checksz0HTTPClientCommonTestCase.test_body_sanity_checks  s@   . 	-F"":. L'

>&d
KLMM,c'2C2C.DE::v  D TYY,	- 3 	1F"":. '

"6T   MM.#g.?.?*@A 

"! .2 $     C0#	1L L s   D')D3'D0	3D<	c                     | j                  ddd      }|j                          | j                  |j                  d       y )Nz/redirect?status=307&url=/putr  s   hellor   r  )r   r   r   r@   r   s     r)   test_put_307z%HTTPClientCommonTestCase.test_put_307  s?    ::+E  
 	(:;r+   c                     | j                  d      }|j                          | j                  |j                  d   t	        d             y )Nz/set_header?k=foo&v=%E9r   r2  )r   r   r   r^   r   r   s     r)   test_non_ascii_headerz.HTTPClientCommonTestCase.test_non_ascii_header  s=    ::78))%0*X2FGr+   c                 b   t        j                          }| j                  d      }|j                          | j                  |j                         |j                  J | j                  |j                  d       | j                  |j                  d       | j                  |j                         |j                  J | j                  t        |j                  |z
        d       |j                  j                         D ]+  \  }}| j                  d|cxk  xr dk  nc d| d|        - y )Nr   r   g      ?z
time_info[z] out of bounds: )timer   r   assertIsNotNoner   assertGreaterEqual
assertLess
start_timeabs	time_infoitemsr  )r(   r  r   r   r   s        r)   test_response_timesz,HTTPClientCommonTestCase.test_response_times  s    YY[
::h'X223$$000 5 5q9--s3 	X001""...H//*<=sC&&,,. 	PDAqOOALSLJqc9J1#*NO	Pr+   c                     | j                  dd      }| j                  |j                  d       | j                  dd      }| j                  |j                  d       | j                  ddd      }| j                  |j                  d       y )Nr   r   )connect_timeoutr   )request_timeout)r  r  r  r   s     r)   test_zero_timeoutz*HTTPClientCommonTestCase.test_zero_timeout  sv    ::h::,::h::,::h1:M,r+   c              #   R  K   | j                   j                  | j                  d            }| j                  |j	                                t        t        d      5 }t        d      D ]'  }t        j                  d       |j                  s' n d d d        y # 1 sw Y   y xY ww)Nz/404z$Exception after Future was cancelledd   rU   )rl  r   r-  r  cancelr   r   r   r   rX   logged_stack)r(   futelr   s       r)   test_error_after_cancelz0HTTPClientCommonTestCase.test_error_after_cancel  s     $$T\\&%9:

%w FG 	2
 3Z iio%??	 	 	s$   AB'2BB	B'B$ B'c                    dD ]  \  }}| j                  |d      5  | j                  t              5  | j                  dd|i       d d d        d d d        | j                  |d      5  | j                  t              5  | j                  d|di       d d d        d d d         y # 1 sw Y   cxY w# 1 sw Y   gxY w# 1 sw Y   ,xY w# 1 sw Y   xY w)N))zfoobar:cr)zfoo
bar:lf)z	foo
bar:crlfrt  )r!   positionr   r5  rs  key)subTestr
  r  r   )r(   headerr!   s      r)   test_header_crlfz)HTTPClientCommonTestCase.test_header_crlf  s    
 
	BLFD
 4': B&&z2 BJJx%JABB 4%8 B&&z2 BJJx&%JABB B
	BB BB BB BB BsF   B6B*B6+CCC*B3/B66B?	CCC	N)-r-   r.   r/   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r#  r+  r0  r;  r@  rM  rP  r_  re  r   ro  rv  ry  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r0   r+   r)   r   r      sU   
..	7(F
(#7J
	

1-<7-<T
"3H<0"5>4"  ";@ F FC 9 9 ? ? - - 
: 
: 	E 	E21`<HP(-  Br+   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)RequestProxyTestc                 z    t        t        dd      t                     }| j                  |j                  d       y )Nhttp://example.com/r5  )r6  )r   r	   rk  r   r6  r(   proxys     r)   test_request_setz!RequestProxyTest.test_request_set  s3    -%@$&
 	))51r+   c                 z    t        t        d      t        d            }| j                  |j                  d       y )Nr  r5  r  )r   r	   rk  r   r  r  s     r)   test_default_setz!RequestProxyTest.test_default_set  s4    -.u0M
 	00%8r+   c                 ~    t        t        dd      t        d            }| j                  |j                  d       y )Nr  r5  )
proxy_hostbar)r   r	   rk  r   r  r  s     r)   test_both_setzRequestProxyTest.test_both_set  s7    -%@$RWBX
 	))51r+   c                 t    t        t        d      t                     }| j                  |j                         y Nr  )r   r	   rk  assertIsNoner   r  s     r)   test_neither_setz!RequestProxyTest.test_neither_set  s*    k*?@$&I%--.r+   c                     t        t        d      t                     }| j                  t              5  |j
                   d d d        y # 1 sw Y   y xY wr  )r   r	   rk  r
  AttributeErrorr5  r  s     r)   test_bad_attributez#RequestProxyTest.test_bad_attribute  s@    k*?@$&I~. 	II	 	 	s   A		Ac                 d    t        t        d      d       }| j                  |j                         y r  )r   r	   r  r   r  s     r)   test_defaults_nonez#RequestProxyTest.test_defaults_none  s(    k*?@$G%--.r+   N)	r-   r.   r/   r  r  r  r  r  r  r0   r+   r)   r  r    s     292/
/r+   r  c                       e Zd Zd Zy)HTTPResponseTestCasec                     t        t        d      dt                     }t        |      }| j	                  |j                  d             | j                  d|       y )Nhttp://example.comr   )rJ  zHTTPResponse(zcode=200)r
   r	   r   r?  r  rU  r*  )r(   r   ss      r)   test_strzHTTPResponseTestCase.test_str  sI    ,-s79
 M_56j!$r+   N)r-   r.   r/   r  r0   r+   r)   r  r    s    %r+   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)SyncHTTPClientTestc                 :    t        d       _        t        j                         t        j
                   fd        fd}t        j                  |       _         j                  j                          j                          t                _        y )NF)make_currentc                      t               \  } _        t        dt        fg      }t	        |      _        j
                  j                  |        j                          y )N/)r   r   r   r   r   server
add_socketset)r   appeventr(   s     r)   init_serverz-SyncHTTPClientTest.setUp.<locals>.init_server+  sJ    .0OD$)%6789C$S/DKKK""4(IIKr+   c                  p    j                   j                          j                   j                          y rj   )server_iolooprun_syncstart)r  r(   s   r)   r  z'SyncHTTPClientTest.setUp.<locals>.start3  s)    ''4$$&r+   )target)r   r  	threadingEventr   rY   Threadserver_threadr  waitr   rl  )r(   r  r  r  s   ` @@r)   setUpzSyncHTTPClientTest.setUp'  sq    #7!		 
		' '--U;  "

%<r+   c                       fd} j                   j                  |        j                  j                           j                  j                           j                   j                  d       y )Nc                      j                   j                          t        j                  fd       } j                  j                  |        y )Nc               3      K   j                   j                          t        d      D ]  } d   j                  j	                          y w)N   )r  close_all_connectionsr   r  stop)r   r(   s    r)   	slow_stopzCSyncHTTPClientTest.tearDown.<locals>.stop_server.<locals>.slow_stopF  sD     kk7799 q A""'')s   AA)r  r  r   rY   r  add_callback)r  r(   s    r)   stop_serverz0SyncHTTPClientTest.tearDown.<locals>.stop_server>  sA    KK ]]* * ++I6r+   T)all_fds)r  r  r  r   rl  r   )r(   r  s   ` r)   tearDownzSyncHTTPClientTest.tearDown=  sY    	7& 	''4!    .r+   c                 $    d| j                   |fz  S )Nzhttp://127.0.0.1:%d%s)r   )r(   paths     r)   r-  zSyncHTTPClientTest.get_urlV  s    &$))T):::r+   c                     | j                   j                  | j                  d            }| j                  d|j                         y )Nr  r   r  r   s     r)   test_sync_clientz#SyncHTTPClientTest.test_sync_clientY  s5    ##))$,,s*;<(--8r+   c                     | j                  t              5 }| j                  j                  | j	                  d             d d d        | j                  j                  j                  d       y # 1 sw Y   0xY wr  )r
  r   rl  r   r-  r   r  r   )r(   	assertions     r)   test_sync_client_errorz)SyncHTTPClientTest.test_sync_client_error]  sb     y) 	>Y""4<<#<=	>,,1137	> 	>s   +A00A9N)r-   r.   r/   r  r  r-  r  r   r0   r+   r)   r  r  &  s    (,/2;98r+   r  c                       e Zd Zd Zy)SyncHTTPClientSubprocessTestc                 8   t        j                  t        j                  ddgt         j                  t         j
                  dd      }|j                  r)t        d       t        t        |j                               |j                  r| j                  d       y y )Nz-czMfrom tornado.httpclient import HTTPClient; f = lambda: None; c = HTTPClient()T   )stdoutstderrchecktimeoutzSTDOUT:z%subprocess produced unexpected output)

subprocessrunsys
executablePIPESTDOUTr  printr   fail)r(   procs     r)   test_destructor_logz0SyncHTTPClientSubprocessTest.test_destructor_logf  sw     ~~_
 ??$$

 ;;)*T[[)*;;II=> r+   N)r-   r.   r/   r  r0   r+   r)   r  r  e  s    ?r+   r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	HTTPRequestTestCasec                 ^    t        dddi      }| j                  |j                  ddi       y )Nr  r5  r  rs  )r	   r   r^   r(   r?   s     r)   test_headersz HTTPRequestTestCase.test_headers  s+    2UENK5%.9r+   c                 h    t        d      }ddi|_        | j                  |j                  ddi       y )Nr  r  bazr	   r^   r   r  s     r)   test_headers_setterz'HTTPRequestTestCase.test_headers_setter  s0    23 %.5%.9r+   c                 `    t        d      }d |_        | j                  |j                  i        y )Nr  r  r  s     r)   test_null_headers_setterz,HTTPRequestTestCase.test_null_headers_setter  s(    23"-r+   c                 h    t        dd      }| j                  |j                  t        d             y )Nr  r5  )r@   )r	   r   r@   r   r  s     r)   	test_bodyzHTTPRequestTestCase.test_body  s'    2?tE{3r+   c                 r    t        d      }d|_        | j                  |j                  t        d             y )Nr  r5  )r	   r@   r   r   r  s     r)   test_body_setterz$HTTPRequestTestCase.test_body_setter  s,    23tE{3r+   c                     t         j                   j                  t         j                  j                        }t	        d|      }| j                  |j                  dt        |      i       y Nr  )if_modified_sincezIf-Modified-Since)datetimenowtimezoneutcr	   r   r^   r   r(   	http_dater?   s      r)   test_if_modified_sincez*HTTPRequestTestCase.test_if_modified_since  sT    %%))(*;*;*?*?@	2iPOO13CI3NO	
r+   c                     t               5  t        j                  j                         }d d d        t        d      }| j	                  |j
                  dt        |      i       y # 1 sw Y   >xY wr#  )r   r%  utcnowr	   r   r^   r   r)  s      r)   'test_if_modified_since_naive_deprecatedz;HTTPRequestTestCase.test_if_modified_since_naive_deprecated  sa    ! 	3 ))002I	32iPOO13CI3NO	
	3 	3s   A''A0N)
r-   r.   r/   r  r  r  r  r!  r+  r.  r0   r+   r)   r  r    s%    ::
.
44


r+   r  c                       e Zd Zd Zd Zd Zy)HTTPErrorTestCasec                     t        d      }t        j                  |      }| j                  ||       | j                  |j                  |j                         y )N  )r   copyassertIsNotr   r   )r(   ee2s      r)   	test_copyzHTTPErrorTestCase.test_copy  s@    cNYYq\B)r+   c                     t        d      }| j                  t        |      d       | j                  t        |      d       y )Nr2  HTTP 403: Forbidden)r   r   r?  repr)r(   r5  s     r)   test_plain_errorz"HTTPErrorTestCase.test_plain_error  s5    cNQ!67a"78r+   c                 &   t        t        d      d      }| j                  t              5 }|j	                          d d d        j
                  }| j                  t        |      d       | j                  t        |      d       y # 1 sw Y   LxY w)Nr  r2  r9  )	r
   r	   r
  r   r   r  r   r?  r:  )r(   r   cmr5  s       r)   test_error_with_responsez*HTTPErrorTestCase.test_error_with_response  su    K(=>Dy) 	RLLN	LLQ!67a"78		 	s   BBN)r-   r.   r/   r7  r;  r>  r0   r+   r)   r0  r0    s    *9
9r+   r0  )Lr.  r7  
contextlibr   r3  r   r  r%  ior   r	  r  r  typingr  unittesttornado.escaper   r   r   tornador   tornado.httpclientr	   r
   r   r   r   tornado.httpserverr   tornado.ioloopr   tornado.iostreamr   tornado.logr   r   r   tornado.testingr   r   r   r   tornado.test.utilr   tornado.webr   r   r   tornado.httputilr   r   r   r2   r;   rD   rM   rR   r[   r`   rh   rl   rp   rx   r|   r   r   r   r   TestCaser  r  r  r  r  r0  r0   r+   r)   <module>rO     s            
     7 7   * ! % (  T T 0 8 8 :( (
. 
& &
n 
^ > ;. ;
~ &n &
Q~ Q
n &> &H H"~ "
 
EN ET	B0 T	Bn/x(( /B%8,, %<8** <8~?8#4#4 ?<%
(++ %
P9)) 9r+   