
    [4%eeJ                     .   d dl mZmZmZmZmZmZmZmZm	Z	m
Z
 d dlmZmZ d dlm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Zd dlmZmZmZ deeeee         f         eeee
         f         f         fdZ  G d	 d
ej!                  Z" G d dej!                  Z# G d dej!                  Z$ G d dej!                  Z% G d dej!                  Z& G d dej!                  Z' G d dej!                  Z( G d dej!                  Z)dS )    )

url_concatparse_multipart_form_dataHTTPHeadersformat_timestampHTTPServerRequestparse_request_start_lineparse_cookie	qs_to_qslHTTPInputErrorHTTPFile)utf8
native_str)gen_log)	ExpectLogN)TupleDictListreturnc                  
    i i fS )zReturn two empty dicts suitable for use with parse_multipart_form_data.

    mypy insists on type annotations for dict literals, so this lets us avoid
    the verbose types throughout this test.
     r       :lib/python3.11/site-packages/tornado/test/httputil_test.pyform_data_argsr      s     r6Mr   c                   V    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S )TestUrlConcatc                 V    t          dddg          }|                     |d           d S )Nhttps://localhost/pathyr   zr!   https://localhost/path?y=y&z=zr   assertEqualselfurls     r   test_url_concat_no_query_paramsz-TestUrlConcat.test_url_concat_no_query_params&   s4    1J
3KLL>?????r   c                 V    t          dddg          }|                     |d           d S )Nr   )r   z/yr    z!https://localhost/path?y=%2Fy&z=zr#   r%   s     r   test_url_concat_encode_argsz)TestUrlConcat.test_url_concat_encode_args*   s4    1K3LMMABBBBBr   c                 V    t          dddg          }|                     |d           d S )Nzhttps://localhost/path?r   r    r"   r#   r%   s     r   test_url_concat_trailing_qz(TestUrlConcat.test_url_concat_trailing_q.   s4    2Z4LMM>?????r   c                 V    t          dddg          }|                     |d           d S )Nzhttps://localhost/path?xr   r    !https://localhost/path?x=&y=y&z=zr#   r%   s     r   &test_url_concat_q_with_no_trailing_ampz4TestUrlConcat.test_url_concat_q_with_no_trailing_amp2   s4    3j*5MNNABBBBBr   c                 V    t          dddg          }|                     |d           d S )Nzhttps://localhost/path?x&r   r    r.   r#   r%   s     r   test_url_concat_trailing_ampz*TestUrlConcat.test_url_concat_trailing_amp6   s4    4z:6NOOABBBBBr   c                 V    t          dddg          }|                     |d           d S )Nzhttps://localhost/path?a=1&b=2r   r    z&https://localhost/path?a=1&b=2&y=y&z=zr#   r%   s     r   test_url_concat_mult_paramsz)TestUrlConcat.test_url_concat_mult_params:   s4    9J
;STTFGGGGGr   c                 R    t          dg           }|                     |d           d S Nzhttps://localhost/path?r=1&t=2r#   r%   s     r   test_url_concat_no_paramsz'TestUrlConcat.test_url_concat_no_params>   s/    92>>>?????r   c                 R    t          dd           }|                     |d           d S r5   r#   r%   s     r   test_url_concat_none_paramsz)TestUrlConcat.test_url_concat_none_paramsB   s/    94@@>?????r   c                 T    t          ddg          }|                     |d           d S )Nzhttps://localhost/path#tabr   zhttps://localhost/path?y=y#tabr#   r%   s     r   test_url_concat_with_fragz'TestUrlConcat.test_url_concat_with_fragF   s1    5
|DD>?????r   c                 V    t          dddg          }|                     |d           d S )Nr   )r   y1)r   y2z https://localhost/path?y=y1&y=y2r#   r%   s     r   !test_url_concat_multi_same_paramsz/TestUrlConcat.test_url_concat_multi_same_paramsJ   s4    1K3MNN@AAAAAr   c                 T    t          ddg          }|                     |d           d S )Nzhttps://localhost/path?r=1&r=2r   z"https://localhost/path?r=1&r=2&y=yr#   r%   s     r   'test_url_concat_multi_same_query_paramsz5TestUrlConcat.test_url_concat_multi_same_query_paramsN   s1    9J<HHBCCCCCr   c                 n    t          dt          d                    }|                     |d           d S )Nr   r   )r   zhttps://localhost/path?y=y)r   dictr$   r%   s     r   test_url_concat_dict_paramsz)TestUrlConcat.test_url_concat_dict_paramsR   s7    14#;;;??:;;;;;r   N)__name__
__module____qualname__r(   r*   r,   r/   r1   r3   r6   r8   r:   r>   r@   rC   r   r   r   r   r   %   s        @ @ @C C C@ @ @C C CC C CH H H@ @ @@ @ @@ @ @B B BD D D< < < < <r   r   c                       e Zd Zd ZdS )QsParseTestc                    d}t           j                            |          }t          t	          |                    }|                     d|           |                     d|           |                     d|           d S )Nza=1&b=2&a=3)a1)rJ   3)b2)urllibparseparse_qslistr
   assertIn)r&   qsstringqsqsls       r   test_parsingzQsParseTest.test_parsingX   sq     \""8,,9R==!!j#&&&j#&&&j#&&&&&r   N)rD   rE   rF   rW   r   r   r   rH   rH   W   s#        ' ' ' ' 'r   rH   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 )MultipartFormDataTestc                    d                     dd          }t                      \  }}t          d|||           |d         d         }|                     |d         d           |                     |d	         d
           d S )NT   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"

Foo
--1234--   
   
   1234filesr   filenameab.txtbody   Fooreplacer   r   r$   r&   dataargsr_   files        r   test_file_uploadz&MultipartFormDataTest.test_file_uploadb   s    
 G7
 
 	 %&&e!'4u===W~a j)8444fv.....r   c                    d                     dd          }t                      \  }}t          d|||           |d         d         }|                     |d         d           |                     |d	         d
           d S )NsP   --1234
Content-Disposition: form-data; name=files; filename=ab.txt

Foo
--1234--r\   r]   r^   r_   r   r`   ra   rb   rc   rd   rf   s        r   test_unquoted_namesz)MultipartFormDataTest.test_unquoted_namesq   s    
 G7
 
 	 %&&e!'4u===W~a j)8444fv.....r   c                    g d}|D ]}t          j        d|           d|                    dd                              dd          z  }t          |                    dd	                    }t	                      \  }}t          d
|||           |d         d         }|                     |d         |           |                     |d         d           d S )N)za;b.txtza"b.txtza";b.txtza;"b.txtz	a";";.txtza\"b.txtza\b.txtztrying filename %rzP--1234
Content-Disposition: form-data; name="files"; filename="%s"

Foo
--1234--\z\\"z\"

r^   r_   r   r`   rb   rc   )loggingdebugre   r   r   r   r$   )r&   	filenamesr`   str_datarg   rh   r_   ri   s           r   test_special_filenamesz,MultipartFormDataTest.test_special_filenames   s   
 
 
	 " 	3 	3HM.999
 f gU 	H ((v6677D(**KD%%gtT5AAA>!$DT*-x888T&\62222#	3 	3r   c                    d                     dd          }t                      \  }}t          d|||           |d         d         }|                     |d         d           |                     |d	         d
           d S )Nsr   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"; filename*=UTF-8''%C3%A1b.txt

Foo
--1234--r\   r]   r^   r_   r   r`   u   áb.txtrb   rc   rd   rf   s        r   test_non_ascii_filenamez-MultipartFormDataTest.test_non_ascii_filename   s    
 G7
 
 	 %&&e!'4u===W~a j)9555fv.....r   c                    d                     dd          }t                      \  }}t          d|||           |d         d         }|                     |d         d           |                     |d	         d
           d S )Nr[   r\   r]   s   "1234"r_   r   r`   ra   rb   rc   rd   rf   s        r   )test_boundary_starts_and_ends_with_quotesz?MultipartFormDataTest.test_boundary_starts_and_ends_with_quotes   s    
 G7
 
 	 %&&e!)T4???W~a j)8444fv.....r   c                     d                     dd          }t                      \  }}t          t          d          5  t	          d|||           d d d            n# 1 swxY w Y   |                     |i            d S )Ns   --1234

Foo
--1234--r\   r]   z#multipart/form-data missing headersr^   re   r   r   r   r   r$   r&   rg   rh   r_   s       r   test_missing_headersz*MultipartFormDataTest.test_missing_headers   s     G7
 
	 	 %&&ew EFF 	B 	B%gtT5AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B#####   AA #A c                     d                     dd          }t                      \  }}t          t          d          5  t	          d|||           d d d            n# 1 swxY w Y   |                     |i            d S )NsR   --1234
Content-Disposition: invalid; name="files"; filename="ab.txt"

Foo
--1234--r\   r]   Invalid multipart/form-datar^   r|   r}   s       r    test_invalid_content_dispositionz6MultipartFormDataTest.test_invalid_content_disposition   s    
 G7
 
 	 %&&ew =>> 	B 	B%gtT5AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B#####r   c                     d                     dd          }t                      \  }}t          t          d          5  t	          d|||           d d d            n# 1 swxY w Y   |                     |i            d S )NsS   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"

Foo--1234--r\   r]   r   r^   r|   r}   s       r   .test_line_does_not_end_with_correct_line_breakzDMultipartFormDataTest.test_line_does_not_end_with_correct_line_break   s     w7
 
	 	 %&&ew =>> 	B 	B%gtT5AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B#####r   c                     d                     dd          }t                      \  }}t          t          d          5  t	          d|||           d d d            n# 1 swxY w Y   |                     |i            d S )NsF   --1234
Content-Disposition: form-data; filename="ab.txt"

Foo
--1234--r\   r]   z&multipart/form-data value missing namer^   r|   r}   s       r   6test_content_disposition_header_without_name_parameterzLMultipartFormDataTest.test_content_disposition_header_without_name_parameter   s    
 G7
 
 	 %&&ew HII 	B 	B%gtT5AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B#####r   c                    d                     dd          }t                      \  }}t          d|||           |d         d         }|                     |d         d           |                     |d	         d
           d S )NsU   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"

Foo
--1234--
r\   r]   r^   r_   r   r`   ra   rb   rc   rd   rf   s        r   test_data_after_final_boundaryz4MultipartFormDataTest.test_data_after_final_boundary   s     G7
 
 	 %&&e!'4u===W~a j)8444fv.....r   N)rD   rE   rF   rj   rl   rv   rx   rz   r~   r   r   r   r   r   r   r   rY   rY   a   s        / / // / / 3 3 3:/ / // / /$ $ $$ $ $$ $ $$ $ $/ / / / /r   rY   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
HTTPHeadersTestc                    d                     dd          }t          j        |          }|                     |d         d           |                     |                    d          dg           |                     |d         d           |                     |                    d          d	d
g           |                     t          t          |                                                    g d           d S )Nz>Foo: bar
 baz
Asdf: qwer
	zxcv
Foo: even
     more
     lines
rp   rq   asdf	qwer zxcvFoozbar baz,even more linesfoobar bazeven more lines))Asdfr   )r   r   )r   r   )re   r   rP   r$   get_listsortedrR   get_all)r&   rg   headerss      r   test_multi_linezHTTPHeadersTest.test_multi_line  s   
 G&
 
 	 #D))+666))&11K=AAA)BCCC))%009>O2PQQQ4))**++SSS	
 	
 	
 	
 	
r   c                 V    d}|                      t          t          j        |           d S )Nz	 Foo: bar)assertRaisesr   r   rP   )r&   rg   s     r   test_malformed_continuationz+HTTPHeadersTest.test_malformed_continuation!  s*     .+*;TBBBBBr   c           	         g d}|D ]}dD ]}	 	 |                     |          }n# t          $ r Y &w xY wd|z   dz   }t          j        t	          |                    d                              }ddt	          |                    d                    z   dz   fg}|                     |t          |                                                     # t          $ r t          j        d	||            w xY wd S )
N)   u    u    )r   latin1s   Cookie: foo=s   barr   Cookiezfoo=barzfailed while trying %r in %s)encodeUnicodeEncodeErrorr   rP   r   decoder$   rR   r   	Exceptionr   warning)r&   newlinesnewlineencodingencodedrg   r   expecteds           r   test_unicode_newlinesz%HTTPHeadersTest.test_unicode_newlines(  sH   
 
 
   	 	G.  !")..":":- ! ! ! ! +W4v=D */
4;;x;P;P0Q0QRRG %"Zx0H0H%I%IIEQ H $$XtGOO4E4E/F/FGGGG    O$BGXVVV%	 	s"   %C
2C2BC"C4c                     t          j        d          }|                     t          |                                          g d           d S )Nz&CRLF: crlf
LF: lf
CR: crMore: more
))CrzcrMore: more)Crlfcrlf)Lflf)r   rP   r$   r   r   r&   r   s     r   test_optional_crz HTTPHeadersTest.test_optional_crP  sU     #$RSS7??$$%%FFF	
 	
 	
 	
 	
r   c           	      (   g d}t                      }|D ]\  }}|                    ||           |                                }t          j        |          }t          j        |          }||||fD ]D}|                     t          t          |                                                    |           E|||fD ]T}|                     ||           |                     |	                    d          |	                    d                     Ud S )N))ArK   )r   rN   )Bcr   )
r   addcopydeepcopyr$   rR   r   r   assertIsNotr   )	r&   	all_pairsh1kvh2h3h4r   s	            r   	test_copyzHTTPHeadersTest.test_copyZ  s    888	]] 	 	DAqFF1aLLLLWWYYYr]]]2BB' 	I 	IG T&):):";";<<iHHHHB| 	F 	FGWb)))W--c22BKK4D4DEEEE	F 	Fr   c                 F   t                      }|                    dd           |                    dd           |                    dd           t          j        |          }t          j        |          }|                     t          |                                          t          |                                                     |                     t          |                                          t          |                                                     d S )Nz
Set-Cookieza=bzc=dzContent-Typez	text/html)	r   r   pickledumpsloadsr$   r   r   items)r&   r   pickled	unpickleds       r   test_pickle_roundtripz%HTTPHeadersTest.test_pickle_roundtripk  s    --L%(((L%(((NK000,w''L))	 1 122F9;L;L;N;N4O4OPPP00&9J9J2K2KLLLLLr   c                    t                      }d|d<   |                     |                    dd          d           |                     |d         d           |                     |                    dd          d           |                     |d         d           |                     t          |                                          ddg           d S )Nr   r   bazquuxxyzzy)r   r   )Quuxr   )r   r$   
setdefaultr   r   r   s     r   test_setdefaultzHTTPHeadersTest.test_setdefaultu  s    --++E5995AAA///++FG<<gFFF'222 1 122^EV4WXXXXXr   c                    t                      }|                    dd           |                    dd           |                    dd           t          j        t          |                    }|                     ||           d S )Nr   rK   rN   rL   )r   r   rP   strr$   )r&   r   headers2s      r   test_stringzHTTPHeadersTest.test_string  sy    --E3E3E3$S\\22(+++++r   N)rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r     s        
 
 
4C C C& & &P
 
 
F F F"M M M	Y 	Y 	Y, , , , ,r   r   c                   :    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	S )
FormatTimestampTestg*; R]AAzSun, 27 Jan 2013 18:43:20 GMTc                 V    |                      t          |          | j                   d S N)r$   r   EXPECTED)r&   values     r   checkzFormatTimestampTest.check  s)    )%00$-@@@@@r   c                 :    |                      | j                   d S r   )r   	TIMESTAMPr&   s    r   test_unix_time_floatz(FormatTimestampTest.test_unix_time_float  s    

4>"""""r   c                 T    |                      t          | j                             d S r   )r   intr   r   s    r   test_unix_time_intz&FormatTimestampTest.test_unix_time_int  s$    

3t~&&'''''r   c                 ^    |                      t          j        | j                             d S r   )r   timegmtimer   r   s    r   test_struct_timez$FormatTimestampTest.test_struct_time  s&    

4;t~../////r   c                     t          t          j        | j                            }|                     dt          |                     |                     |           d S )N	   )tupler   r   r   r$   lenr   )r&   tups     r   test_time_tuplez#FormatTimestampTest.test_time_tuple  sJ    DK//00CHH%%%

3r   c                 t    |                      t          j                            | j                             d S r   )r   datetimeutcfromtimestampr   r   s    r   test_datetimez!FormatTimestampTest.test_datetime  s-    

8$55dnEEFFFFFr   N)rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r     s        !I.HA A A# # #( ( (0 0 0  
G G G G Gr   r   c                        e Zd Zd Zd Zd ZdS )HTTPServerRequestTestc                 &    t          d           d S N/)uri)r   r   s    r   test_default_constructorz.HTTPServerRequestTest.test_default_constructor  s     	c""""""r   c                 f    t          d          }|                     |j        t                     d S r   )r   assertIsInstancerb   bytes)r&   requetss     r   test_body_is_a_byte_stringz0HTTPServerRequestTest.test_body_is_a_byte_string  s0    #,,,glE22222r   c                     t          dt          ddgi                    }|                     dt          |          v           d S )Nr   Canaryz	Coal Mine)r   r   )r   r   
assertTruerepr)r&   requests     r   "test_repr_does_not_contain_headersz8HTTPServerRequestTest.test_repr_does_not_contain_headers  sO    #[([M)BCC
 
 
 	W566666r   N)rD   rE   rF   r   r  r  r   r   r   r   r     sA        # # #3 3 37 7 7 7 7r   r   c                        e Zd ZdZdZdZd ZdS )ParseRequestStartLineTestGETz/foozHTTP/1.1c                 2   d                     | j        | j        | j        g          }t	          |          }|                     |j        | j                   |                     |j        | j                   |                     |j        | j                   d S )N )	joinMETHODPATHVERSIONr   r$   methodpathversion)r&   
start_lineparsed_start_lines      r   test_parse_request_start_linez7ParseRequestStartLineTest.test_parse_request_start_line  s    XXt{DIt|DEE
4Z@@*14;???*/;;;*2DLAAAAAr   N)rD   rE   rF   r  r  r  r  r   r   r   r	  r	    s7        FDGB B B B Br   r	  c                        e Zd Zd Zd Zd ZdS )ParseCookieTestc                    |                      t          d          ddd           |                      t          d          dddd	d
           |                      t          d          ddi           |                      t          d          ddi           |                      t          d          ddddd           dS )zO
        Test cases copied from Python's Lib/test/test_http_cookies.py
        zchips=ahoy; vienna=fingerahoyfinger)chipsviennaz)keebler="E=mc2; L=\"Loves\"; fudge=\012;"z"E=mc2z	\"Loves\"z\012ro   )keeblerLfudge zkeebler=E=mc2r  zE=mc2zkey:term=value:termzkey:termz
value:termza=b; c=[; d=r; f=hrM   [rh)rJ   r   dfNr$   r	   r   s    r   test_python_cookiesz#ParseCookieTest.test_python_cookies  s     	45511	
 	
 	
 	GHH }wCPP	
 	
 	

 	o66G8LMMM.//*l1K	
 	
 	
 	-..c#TW0X0X	
 	
 	
 	
 	
r   c                     |                      t          d          ddd           |                      t          d          ddd           d S )	Nza=b; Domain=example.comrM   zexample.com)rJ   Domainza=b; h=i; a=cr   i)rJ   r$  r'  r   s    r   test_cookie_edgecasesz%ParseCookieTest.test_cookie_edgecases  s^    2333-5X5X	
 	
 	

 	o66c8L8LMMMMMr   c                    |                      dt          d                                                     |                     t          d          dddd           |                     t          d          d	d
d           |                     t          d          ddi           |                     t          d          dt	          d          i           |                     t          d          ddd           dS )zs
        Cookie strings that go against RFC6265 but browsers will send if set
        via document.cookie.
        django_languagez$abc=def; unnamed; django_language=enza=b; "; c=drM   ro   r%  )rJ   r!  r   za b c=d e = f; gh=izd e = fr+  )za b cghza   b,c<>@:/[]?{}=d  "  =e,f gza   b,c<>@:/[]?{}zd  "  =e,f gu   saint=André Bessettesaintu   André Bessettez  =  b  ;  ;  =  ;   c  =  ;  r!  )r!  r   N)rS   r	   keysr$   r   r   s    r   test_invalid_cookiesz$ParseCookieTest.test_invalid_cookies  s,    	?@@EEGG	
 	
 	

 	m44CSs6S6STTT.//9C1P1P	
 	
 	
 	9:: .1	
 	
 	

 	011j!2334	
 	
 	
 	9::2<N<N	
 	
 	
 	
 	
r   N)rD   rE   rF   r(  r,  r2  r   r   r   r  r    sD        
 
 
2N N N 
  
  
  
  
r   r  )*tornado.httputilr   r   r   r   r   r   r	   r
   r   r   tornado.escaper   r   tornado.logr   tornado.testingr   r   r   rr   r   r   urllib.parserO   unittesttypingr   r   r   r   r   r   TestCaser   rH   rY   r   r   r   r	  r  r   r   r   <module>r;     s                          , + + + + + + +       % % % % % %           $ $ $ $ $ $ $ $ $ $d3U#34d3X;N6OOP    /< /< /< /< /<H% /< /< /<d' ' ' ' '(# ' ' 'b/ b/ b/ b/ b/H- b/ b/ b/J@, @, @, @, @,h' @, @, @,FG G G G G(+ G G G87 7 7 7 7H- 7 7 7$
B 
B 
B 
B 
B 1 
B 
B 
BE
 E
 E
 E
 E
h' E
 E
 E
 E
 E
r   