
    	Pjo                     2   d dl mZ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jD                        Z# G d dejD                        Z$ G d dejD                        Z% G d dejD                        Z& G d dejD                        Z' G d dejD                        Z( G d dejD                        Z) G d dejD                        Z*y)    )
url_concatparse_multipart_form_dataHTTPHeadersformat_timestampHTTPServerRequestparse_request_start_lineparse_cookie	qs_to_qslHTTPInputErrorHTTPFileParseMultipartConfig)utf8
native_str)gen_log)ignore_deprecationN)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       M/root/.hermes/venv/lib/python3.12/site-packages/tornado/test/httputil_test.pyform_data_argsr      s     r6Mr   c                   T    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y)TestUrlConcatc                 D    t        dddg      }| j                  |d       y )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'   s%    1J
3KL>?r   c                 D    t        dddg      }| j                  |d       y )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+   s%    1K3LMABr   c                 D    t        dddg      }| j                  |d       y )Nzhttps://localhost/path?r   r!   r#   r$   r&   s     r   test_url_concat_trailing_qz(TestUrlConcat.test_url_concat_trailing_q/   s%    2Z4LM>?r   c                 D    t        dddg      }| j                  |d       y )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_amp3   s%    3j*5MNABr   c                 D    t        dddg      }| j                  |d       y )Nzhttps://localhost/path?x&r   r!   r/   r$   r&   s     r   test_url_concat_trailing_ampz*TestUrlConcat.test_url_concat_trailing_amp7   s%    4z:6NOABr   c                 D    t        dddg      }| j                  |d       y )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;   s%    9J
;STFGr   c                 @    t        dg       }| j                  |d       y 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                 @    t        dd       }| j                  |d       y r6   r$   r&   s     r   test_url_concat_none_paramsz)TestUrlConcat.test_url_concat_none_paramsC   s     94@>?r   c                 B    t        ddg      }| j                  |d       y )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_fragG   s"    5
|D>?r   c                 D    t        dddg      }| j                  |d       y )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_paramsK   s%    1K3MN@Ar   c                 B    t        ddg      }| j                  |d       y )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_paramsO   s"    9J<HBCr   c                 T    t        dt        d            }| j                  |d       y )Nr   r    )r    zhttps://localhost/path?y=y)r   dictr%   r&   s     r   test_url_concat_dict_paramsz)TestUrlConcat.test_url_concat_dict_paramsS   s$    14#;?:;r   N)__name__
__module____qualname__r)   r+   r-   r0   r2   r4   r7   r9   r;   r?   rA   rD   r   r   r   r   r   &   sI    @C@CCH@@@BD<r   r   c                       e Zd Zd Zy)QsParseTestc                     d}t         j                  j                  |      }t        t	        |            }| j                  d|       | j                  d|       | j                  d|       y )Nza=1&b=2&a=3)a1)rK   3)b2)urllibparseparse_qslistr
   assertIn)r'   qsstringqsqsls       r   test_parsingzQsParseTest.test_parsingY   sS     \\""8,9R=!j#&j#&j#&r   N)rE   rF   rG   rX   r   r   r   rI   rI   X   s    'r   rI   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y)MultipartFormDataTestc                     dj                  dd      }t               \  }}t        d|||       |d   d   }| j                  |d   d       | j                  |d	   d
       y )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_uploadc   sp    
 G7
 	 %&e!'4u=W~a j)84fv.r   c                     dj                  dd      }t               \  }}t        d|||       |d   d   }| j                  |d   d       | j                  |d	   d
       y )NsP   --1234
Content-Disposition: form-data; name=files; filename=ab.txt

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

Foo
--1234--\\\"\"

r_   r`   r   ra   rc   rd   )loggingdebugrf   r   r   r   r%   )r'   	filenamesra   str_datarh   ri   r`   rj   s           r   test_special_filenamesz,MultipartFormDataTest.test_special_filenames   s    

	 " 	3HMM.9
 fgU	H ((v67D(*KD%%gtT5A>!$DT*-x8T&\62#	3r   c                 n   g d}|D ]  }d|j                  dd      j                  dd      z  }t        |j                  dd            }t               \  }}| j                  t              5 }t        d	|||       d d d        | j                  d
t        j                                y # 1 sw Y   1xY w)N)zab.txtza b.txtzab.txtro   rp   rq   rr   rs   rt   ru   r_   zInvalid header value)	rf   r   r   assertRaisesr   r   rT   str	exception)r'   rx   ra   ry   rh   ri   r`   cms           r   test_invalid_charsz(MultipartFormDataTest.test_invalid_chars   s    
	
 " 	EH
 fgU	H ((v67D(*KD%"">2 Fb)'4uEFMM0#bll2CD	EF Fs   ,B++B4	c                     dj                  dd      }t               \  }}t        d|||       |d   d   }| j                  |d   d       | j                  |d	   d
       y )Nsr   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"; filename*=UTF-8''%C3%A1b.txt

Foo
--1234--r]   r^   r_   r`   r   ra   u   áb.txtrc   rd   re   rg   s        r   test_non_ascii_filename_rfc5987z5MultipartFormDataTest.test_non_ascii_filename_rfc5987   sp    
 G7
 	 %&e!'4u=W~a j)95fv.r   c                     dj                  d      j                  dd      }t               \  }}t        d|||       |d   d   }| j	                  |d   d	       | j	                  |d
   d       y )NuX   --1234
Content-Disposition: form-data; name="files"; filename="测试.txt"

Foo
--1234--zutf-8r]   r^   r_   r`   r   ra   u
   测试.txtrc   rd   )encoderf   r   r   r%   rg   s        r   test_non_ascii_filename_rawz1MultipartFormDataTest.test_non_ascii_filename_raw   s}    
 F

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

Foo
--1234--r]   r^   z#multipart/form-data missing headersmsgr_   rf   r   r|   r   r   r%   r'   rh   ri   r`   s       r   test_missing_headersz*MultipartFormDataTest.test_missing_headers   s     G7
	 	 %&e E  
 	B &gtT5A	B 	#		B 	B   A!!A*c                     dj                  dd      }t               \  }}| j                  t        d      5  t	        d|||       d d d        | j                  |i        y # 1 sw Y   xY w)NsR   --1234
Content-Disposition: invalid; name="files"; filename="ab.txt"

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

Foo--1234--r]   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  sv     w7
	 	 %&e~3PQ 	B%gtT5A	B#	B 	Br   c                     dj                  dd      }t               \  }}| j                  t        d      5  t	        d|||       d d d        | j                  |i        y # 1 sw Y   xY w)NsF   --1234
Content-Disposition: form-data; filename="ab.txt"

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

Foo
--1234--
r]   r^   r_   r`   r   ra   rb   rc   rd   re   rg   s        r   test_data_after_final_boundaryz4MultipartFormDataTest.test_data_after_final_boundary!  sp     G7
 	 %&e!'4u=W~a j)84fv.r   c                 j    d } |d      } |d      }||z  dkD  r| j                  d|d|       y y )Nc                     t        j                         }dd| z  z   dz   dz   }i }i }t        d|||       t        j                         |z
  S )Ns+   --1234
Content-Disposition: form-data; x="   ;s   "; s1   name="files"; filename="a.txt"

Foo
--1234--
r_   )timeperf_counterr   )nstartmessageri   r`   s        r   fzJMultipartFormDataTest.test_disposition_param_linear_performance.<locals>.f8  sj    %%'E(  O	O  ,.D/1E%gweD$$&..r   i  '     z,Disposition param parsing is not linear: d1= vs d2=failr'   r   d1d2s       r   )test_disposition_param_linear_performancez?MultipartFormDataTest.test_disposition_param_linear_performance4  sE    	/ uXvY7R<IIE"h2%PQ r   c                 2   d}dj                  dd      }t               }t               \  }}t        |||||       | j	                  |d   d   d   d	       t        d
      }| j                  t              5 }t        |||||       d d d        | j                  dt        j                               t        d      }| j                  t              5 }t        |||||       d d d        | j                  dt        |j                               t        d      }	| j                  t              5 }t        |||||	       d d d        | j                  dt        |j                               y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   GxY w)Nr_   sP   --1234
Content-Disposition: form-data; name="files"; filename="ab.txt"

--1234--r]   r^   )configr`   r   ra   rb   )	max_partsztoo many parts
   )max_part_header_sizezheader too largeF)enabledz'multipart/form-data parsing is disabled)
rf   r   r   r   r%   r|   r   rT   r}   r~   )
r'   boundaryrc   r   ri   r`   config_no_partsr   config_small_headersconfig_disableds
             r   test_multipart_configz+MultipartFormDataTest.test_multipart_configL  s|    G7
 	 &'$&e!(D$fMw*:6A.;~. 	"%$eO	 	&BLL(9:3L~. 	"%$e4H	 	(#bll*;<.u=~. 	"%$eO	 	?R\\ARS%	 		 		 	s$   8E5F6F5E>F
FN)rE   rF   rG   rk   rm   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rZ   rZ   b   sK    // 3>E.//"/$$$$ /&R0 Tr   rZ   c                   T    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y)HTTPHeadersTestc                    dj                  dd      }t        j                  |      }| j                  |d   d       | j                  |j	                  d      dg       | j                  |d   d       | j                  |j	                  d      d	d
g       | j                  t        t        |j                                     g d       | j                  d|v        | j                  d|v        y )Nz>Foo: bar
 baz
Asdf: qwer
	zxcv
Foo: even
     more
     lines
rt   ru   asdf	qwer zxcvFoozbar baz,even more linesfoobar bazeven more lines))Asdfr   )r   r   )r   r   r   )	rf   r   rQ   r%   get_listsortedrS   get_all
assertTruer'   rh   headerss      r   test_multi_linezHTTPHeadersTest.test_multi_linep  s    
 G&
 	 ##D)+6))&1K=A)BC))%09>O2PQ4)*+S	

 	')*')*r   c                     d}t        j                  |      }| j                  |d   d       d}| j                  t        t         j                  |       d}| j                  t        t         j                  |       y )NzFoo: bar
	asdfr   zbar asdfz	 Foo: barzFoo: bar
asdf)r   rQ   r%   r|   r   r   s      r   test_continuationz!HTTPHeadersTest.test_continuation  si    ###D)4
 .+*;*;TB $.+*;*;TBr   c                    t        d      D ]}  }dt        |       d}|dk(  s
|dk\  r=|dk7  r8t        j                  |      }| j	                  |d   dt        |       d	       Y| j                  t        t        j                  |        y )
N   zFoo: barzbaz
	          r   barbaz)rangechrr   rQ   r%   r|   r   )r'   crh   r   s       r   test_forbidden_ascii_charactersz/HTTPHeadersTest.test_forbidden_ascii_characters  s     t 	KAc!fXW-DDyQ$Y19%++D1  3s1vhc1BC!!.+2C2CTJ	Kr   c           	         g d}|D ]  }dD ]  }	 	 |j                  |      }d|z   dz   }t        j                  t	        |j                  d                  }ddt	        |j                  d            z   dz   fg}| j                  |t        |j                                        y # t        $ r Y w xY w# t        $ r t        j                  d	||        w xY w)
N)   u    u    )r   latin1s   Cookie: foo=s   barr   Cookiezfoo=r   zfailed while trying %r in %s)r   UnicodeEncodeErrorr   rQ   r   decoder%   rS   r   	Exceptionr   warning)r'   newlinesnewlineencodingencodedrh   r   expecteds           r   test_unicode_newlinesz%HTTPHeadersTest.test_unicode_newlines  s    
   	G. !")..": +W4v=D *//
4;;x;P0QRG %"Zx0H%IIEQ H $$XtGOO4E/FG#	 . ! ! ! OO$BGXVs)   B(BB7(	B41B73B44B77"Cc                     g d}|D ]T  \  }}t        j                  d|z        }|rdg}ndd|z  fg}| j                  |t        |j	                                      V y )N)) T)	T)    F)r   FzTransfer-Encoding: %schunked)Transfer-Encodingchunkedr   z	%schunked)r   rQ   r%   rS   r   )r'   
whitespacer   strippedr   r   s         r   test_unicode_whitespacez'HTTPHeadersTest.test_unicode_whitespace  sn    


 & 	@KAx!''(F(JKG<=0+/BCXtGOO,='>?	@r   c                    | j                  t              5  t        j                  d       d d d        t        j                  d      }| j	                  t        |j                               g d       y # 1 sw Y   JxY w)Nz&CRLF: crlf
LF: lf
CR: crMore: more
zCRLF: crlf
LF: lf
More: more
))Crlfcrlf)Lflf)Moremore)r|   r   r   rQ   r%   r   r   r'   r   s     r   test_optional_crz HTTPHeadersTest.test_optional_cr  sk    ~. 	NLM	N
 ##$JK7??$%>	
	N 	Ns   A55A>c           	         g d}t               }|D ]  \  }}|j                  ||        |j                         }t        j                  |      }t        j                  |      }||||fD ]4  }| j	                  t        t        |j                                     |       6 |||fD ]D  }| j                  ||       | j                  |j                  d      |j                  d             F y )N))ArL   )r   rO   )Br   r   )
r   addcopydeepcopyr%   rS   r   r   assertIsNotr   )	r'   	all_pairsh1kvh2h3h4r   s	            r   	test_copyzHTTPHeadersTest.test_copy  s    8	] 	DAqFF1aL	WWYYYr]]]2BB' 	IG T&):";<iH	I B| 	FGWb)W--c2BKK4DE	Fr   c                    t               }|j                  dd       |j                  dd       |j                  dd       t        j                  |      }t        j                  |      }| j                  t        |j                               t        |j                                      | j                  t        |j                               t        |j                                      y )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_roundtrip  s    -L%(L%(NK0,,w'LL)	 12F9;L;L;N4OP0&9J2KLr   c                 T   t               }d|d<   | j                  |j                  dd      d       | j                  |d   d       | j                  |j                  dd      d       | j                  |d   d       | j                  t        |j	                               ddg       y )Nr   r   r   quuxxyzzy)r   r   )Quuxr  )r   r%   
setdefaultr   r   r   s     r   test_setdefaultzHTTPHeadersTest.test_setdefault  s    -++E595A/++FG<gF'2 12^EV4WXr   c                     t               }|j                  dd       |j                  dd       |j                  dd       t        j                  t        |            }| j	                  ||       y )Nr   rL   rO   rM   )r   r   rQ   r}   r%   )r'   r   headers2s      r   test_stringzHTTPHeadersTest.test_string  sW    -E3E3E3$$S\2(+r   c                     g d}|D ]<  }t               }| j                  t              5  |j                  |d       d d d        > y # 1 sw Y   IxY w)N) zfoo barzfoo	barzfoo
barzfoo barzfoo z foo   ér   )r   r|   r   r   )r'   invalid_namesnamer   s       r   test_invalid_header_namesz)HTTPHeadersTest.test_invalid_header_names!  sW    	
 " 	)D!mG"">2 )D%() )	)) )s   AA	c                 j    d } |d      } |d      }||z  dkD  r| j                  d|d|       y y )Nc                     t        j                         }t               }t        |       D ]  }|j	                  dd        t        j                         |z
  S )NzX-Foor   )r   r   r   r   r   )r   r   r   is       r   r   z2HTTPHeadersTest.test_linear_performance.<locals>.f2  sL    %%'E!mG1X ,GU+,$$&..r   r   順 r   z.HTTPHeaders.add() does not scale linearly: d1=r   r   r   s       r   test_linear_performancez'HTTPHeadersTest.test_linear_performance1  sE    	/ vYwZ7R<IIGB5RERS r   N)rE   rF   rG   r   r   r   r   r   r   r  r	  r  r  r  r  r   r   r   r   r   o  sF    +:C 	K)V@&
F"M	Y,) Tr   r   c                   J    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)FormatTimestampTestg*; R]AAzSun, 27 Jan 2013 18:43:20 GMTc                 N    | j                  t        |      | j                         y N)r%   r   EXPECTED)r'   values     r   checkzFormatTimestampTest.checkF  s    )%0$--@r   c                 :    | j                  | j                         y r!  )r$  	TIMESTAMPr'   s    r   test_unix_time_floatz(FormatTimestampTest.test_unix_time_floatI  s    

4>>"r   c                 L    | j                  t        | j                               y r!  )r$  intr&  r'  s    r   test_unix_time_intz&FormatTimestampTest.test_unix_time_intL  s    

3t~~&'r   c                 `    | j                  t        j                  | j                               y r!  )r$  r   gmtimer&  r'  s    r   test_struct_timez$FormatTimestampTest.test_struct_timeO  s    

4;;t~~./r   c                     t        t        j                  | j                              }| j	                  dt        |             | j                  |       y )Nr   )tupler   r-  r&  r%   lenr$  )r'   tups     r   test_time_tuplez#FormatTimestampTest.test_time_tupleR  s8    DKK/0CH%

3r   c                     | j                  t        j                  j                  | j                  t        j                  j
                        j                  d              y )N)tzinfo)r$  datetimefromtimestampr&  timezoneutcrf   r'  s    r   test_utc_naive_datetimez+FormatTimestampTest.test_utc_naive_datetimeW  sC    

++ 1 1 5 5gTg"	
r   c                     t               5  | j                  t        j                  j                  | j                               d d d        y # 1 sw Y   y xY wr!  )r   r$  r6  utcfromtimestampr&  r'  s    r   "test_utc_naive_datetime_deprecatedz6FormatTimestampTest.test_utc_naive_datetime_deprecated^  sB    ! 	KJJx((99$..IJ	K 	K 	Ks   9AAc                     | j                  t        j                  j                  | j                  t        j                  j
                               y r!  )r$  r6  r7  r&  r8  r9  r'  s    r   test_utc_aware_datetimez+FormatTimestampTest.test_utc_aware_datetimeb  s4    

++DNNH<M<M<Q<QR	
r   c           
          | j                  t        j                  j                  | j                  t        j                  t        j
                  d                         y )N)hours)r$  r6  r7  r&  r8  	timedeltar'  s    r   test_other_aware_datetimez-FormatTimestampTest.test_other_aware_datetimeg  sA    

++ 1 1(2D2D22N O	
r   N)rE   rF   rG   r&  r"  r$  r(  r+  r.  r3  r:  r=  r?  rD  r   r   r   r  r  A  s;    !I.HA#(0

K


r   r  c                       e Zd Zd Zd Zd Zy)HTTPServerRequestTestc                     t        d       y N/)uri)r   r'  s    r   test_default_constructorz.HTTPServerRequestTest.test_default_constructors  s     	c"r   c                 \    t        d      }| j                  |j                  t               y rH  )r   assertIsInstancerc   bytesr'   requests     r   test_body_is_a_byte_stringz0HTTPServerRequestTest.test_body_is_a_byte_stringy  s     #,gllE2r   c                 l    t        dt        ddgi            }| j                  dt        |             y )NrI  Canaryz	Coal Mine)rJ  r   )r   r   assertNotInreprrO  s     r   "test_repr_does_not_contain_headersz8HTTPServerRequestTest.test_repr_does_not_contain_headers}  s3    #[([M)BC
 	4=1r   N)rE   rF   rG   rK  rQ  rV  r   r   r   rF  rF  r  s    #32r   rF  c                       e Zd ZdZdZdZd Zy)ParseRequestStartLineTestGETz/foozHTTP/1.1c                 b   dj                  | j                  | j                  | j                  g      }t	        |      }| j                  |j                  | j                         | j                  |j                  | j                         | j                  |j                  | j                         y )Nr   )	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{{DIIt||DE
4Z@*114;;?*//;*22DLLAr   N)rE   rF   rG   r\  r]  r^  rd  r   r   r   rX  rX    s    FDGBr   rX  c                   *    e Zd Zd Zd Zd Zd Zd Zy)ParseCookieTestc                 4   | j                  t        d      ddd       | j                  t        d      dddd	d
       | j                  t        d      ddi       | j                  t        d      ddi       | j                  t        d      ddddd       y)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\012rr   )keeblerLfudger  zkeebler=E=mc2rl  zE=mc2zkey:term=value:termzkey:termz
value:termza=b; c=[; d=r; f=hrN   [rh)rK   r   dr   Nr%   r	   r'  s    r   test_python_cookiesz#ParseCookieTest.test_python_cookies  s     	451	
 	GH }wCP	

 	o6G8LM./*l1K	
 	-.c#TW0X	
r   c                 |    | j                  t        d      ddd       | j                  t        d      ddd       y )	Nza=b; Domain=example.comrN   zexample.com)rK   Domainza=b; h=i; a=cr   r  )rK   rq  rs  r'  s    r   test_cookie_edgecasesz%ParseCookieTest.test_cookie_edgecases  s<    233-5X	

 	o6c8LMr   c                    | j                  dt        d      j                                | j                  t        d      dddd       | j                  t        d      d	d
d       | j                  t        d      ddi       | j                  t        d      dt	        d      i       | j                  t        d      ddd       y)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=drN   rr   rr  )rK   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)rT   r	   keysr%   r   r'  s    r   test_invalid_cookiesz$ParseCookieTest.test_invalid_cookies  s     	?@EEG	

 	m4CSs6ST./9C1P	
 	9: .1	

 	01j!234	
 	9:2<N	
r   c                     g d}|D ]?  \  }}| j                  |      5  t        |      }| j                  |d   |       d d d        A y # 1 sw Y   LxY w)N))za="b=\""b=")za="b=\\"b=\)za="b=\="zb==)za="b=\n"zb=n)z
a="b=\042"r  )z
a="b=\134"r  )z
a="b=\377"u   b=ÿ)z
a="b=\400"zb=400)z	a="b=\42"zb=42)za="b=\\042"zb=\042)za="b=\\134"zb=\134)z
a="b=\\\""b=\")za="b=\\\042"r  )za="b=\134\""r  )za="b=\134\042"r  rK   )subTestr	   r%   )r'   casesr   decodedr   s        r   test_unquotezParseCookieTest.test_unquote  sc    
" !& 	2GWg& 2 )  312 2	22 2s   !A

A	c                    d}dD ]  }| j                  |      5  t        j                         }d||z  z   dz   }t        |      d   }t        j                         }| j                  |d d d       | j                  |dd  d	       | j                  t	        |      |d
z          | j                  ||z
  dd       d d d         y # 1 sw Y   xY w)Nr  )rq   z\134za="b=rr   rK      r  z\\\      zTest took too long)r  r   r	   r%   r1  
assertLess)r'   r   r   r   rh   r#  ends          r   test_unquote_largez"ParseCookieTest.test_unquote_large  s     % 	FGg& 
F		1,s2$T*3/iik  rF3  rsX6  UQU3 eQ0DE
F 
F	F
F 
Fs   B CC	N)rE   rF   rG   rt  rw  r}  r  r  r   r   r   rf  rf    s    
2N 
D22Fr   rf  )+tornado.httputilr   r   r   r   r   r   r	   r
   r   r   r   tornado.escaper   r   tornado.logr   tornado.test.utilr   r   r6  rv   r  r   urllib.parserP   unittesttypingr   r   r   r}   rN  r   TestCaser   rI   rZ   r   r  rF  rX  rf  r   r   r   <module>r     s      ,  0        $ $d3U#34d3X;N6OOP /<H%% /<d'(## 'JTH-- JTZOTh'' OTd,
(++ ,
b2H-- 2$
B 1 1 
BsFh'' sFr   