K i`.ddlmZmZmZmZmZmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZdeeeeefeeee fffdZ Gd d ejBZ"Gd d ejBZ#Gd dejBZ$GddejBZ%GddejBZ&GddejBZ'GddejBZ(GddejBZ)y)) url_concatparse_multipart_form_data HTTPHeadersformat_timestampHTTPServerRequestparse_request_start_line parse_cookie qs_to_qslHTTPInputErrorHTTPFile)utf8 native_str)gen_log)ignore_deprecationN)TupleDictListreturnc iifS)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`/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tornado/test/httputil_test.pyform_data_argsrs r6MrcTeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy ) TestUrlConcatcDtdddg}|j|dy)Nhttps://localhost/pathyrzr!https://localhost/path?y=y&z=zr assertEqualselfurls rtest_url_concat_no_query_paramsz-TestUrlConcat.test_url_concat_no_query_params&s%1J 3KL >?rcDtdddg}|j|dy)Nr)rz/yr z!https://localhost/path?y=%2Fy&z=zr#r%s rtest_url_concat_encode_argsz)TestUrlConcat.test_url_concat_encode_args*s%1K3LM ABrcDtdddg}|j|dy)Nzhttps://localhost/path?rr r"r#r%s rtest_url_concat_trailing_qz(TestUrlConcat.test_url_concat_trailing_q.s%2Z4LM >?rcDtdddg}|j|dy)Nzhttps://localhost/path?xrr !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_amp2s%3j*5MN ABrcDtdddg}|j|dy)Nzhttps://localhost/path?x&rr r.r#r%s rtest_url_concat_trailing_ampz*TestUrlConcat.test_url_concat_trailing_amp6s%4z:6NO ABrcDtdddg}|j|dy)Nzhttps://localhost/path?a=1&b=2rr z&https://localhost/path?a=1&b=2&y=y&z=zr#r%s rtest_url_concat_mult_paramsz)TestUrlConcat.test_url_concat_mult_params:s%9J ;ST FGrc@tdg}|j|dyNzhttps://localhost/path?r=1&t=2r#r%s rtest_url_concat_no_paramsz'TestUrlConcat.test_url_concat_no_params>s 92> >?rc@tdd}|j|dyr5r#r%s rtest_url_concat_none_paramsz)TestUrlConcat.test_url_concat_none_paramsBs 94@ >?rcBtddg}|j|dy)Nzhttps://localhost/path#tabrzhttps://localhost/path?y=y#tabr#r%s rtest_url_concat_with_fragz'TestUrlConcat.test_url_concat_with_fragFs"5 |D >?rcDtdddg}|j|dy)Nr)ry1)ry2z https://localhost/path?y=y1&y=y2r#r%s r!test_url_concat_multi_same_paramsz/TestUrlConcat.test_url_concat_multi_same_paramsJs%1K3MN @ArcBtddg}|j|dy)Nzhttps://localhost/path?r=1&r=2rz"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_paramsNs"9J<H BCrcTtdtd}|j|dy)Nrr)rzhttps://localhost/path?y=y)rdictr$r%s rtest_url_concat_dict_paramsz)TestUrlConcat.test_url_concat_dict_paramsRs$14#;? :;rN)__name__ __module__ __qualname__r(r*r,r/r1r3r6r8r:r>r@rCrrrrr%sI@C@CCH@@@BD!$D   T*-x 8   T&\6 2# 3rcdjdd}t\}}td||||dd}|j|dd|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_rr`uáb.txtrbrcrdrfs rtest_non_ascii_filename_rfc5987z5MultipartFormDataTest.test_non_ascii_filename_rfc5987sp G 7 %& e!'4u=W~a  j)95 fv.rcdjdjdd}t\}}td||||dd}|j |dd |j |d d y) NuX--1234 Content-Disposition: form-data; name="files"; filename="测试.txt" Foo --1234--zutf-8r\r]r^r_rr`u 测试.txtrbrc)encodererrr$rfs rtest_non_ascii_filename_rawz1MultipartFormDataTest.test_non_ascii_filename_raws} F  ' 7  %& e!'4u=W~a  j)<8 fv.rcdjdd}t\}}td||||dd}|j|dd|j|d d y) Nr[r\r]s"1234"r_rr`rarbrcrdrfs r)test_boundary_starts_and_ends_with_quotesz?MultipartFormDataTest.test_boundary_starts_and_ends_with_quotessp G 7 %& e!)T4?W~a  j)84 fv.rcdjdd}t\}}|jtd5t d|||ddd|j |iy#1swYxYw)Ns--1234 Foo --1234--r\r]z#multipart/form-data missing headersmsgr^rer assertRaisesr rr$r&rgrhr_s rtest_missing_headersz*MultipartFormDataTest.test_missing_headerss  G 7 %& e     E  B >T5 A B #  B B A!!A*cdjdd}t\}}|jtd5t d|||ddd|j |iy#1swYxYw)NsR--1234 Content-Disposition: invalid; name="files"; filename="ab.txt" Foo --1234--r\r]Invalid multipart/form-datarr^rrs r test_invalid_content_dispositionz6MultipartFormDataTest.test_invalid_content_dispositionsv G 7 %& e   ~3P  Q B %gtT5 A B # B Brcdjdd}t\}}|jtd5t d|||ddd|j |iy#1swYxYw)NsS--1234 Content-Disposition: form-data; name="files"; filename="ab.txt" Foo--1234--r\r]rrr^rrs r.test_line_does_not_end_with_correct_line_breakzDMultipartFormDataTest.test_line_does_not_end_with_correct_line_breaksvw 7 %& e   ~3P  Q B %gtT5 A B # B Brcdjdd}t\}}|jtd5t d|||ddd|j |iy#1swYxYw)NsF--1234 Content-Disposition: form-data; filename="ab.txt" Foo --1234--r\r]z&multipart/form-data value missing namerr^rrs r6test_content_disposition_header_without_name_parameterzLMultipartFormDataTest.test_content_disposition_header_without_name_parameters G 7 %& e     H  B >T5 A B #  B Brcdjdd}t\}}td||||dd}|j|dd|j|d d y) NsU--1234 Content-Disposition: form-data; name="files"; filename="ab.txt" Foo --1234-- r\r]r^r_rr`rarbrcrdrfs rtest_data_after_final_boundaryz4MultipartFormDataTest.test_data_after_final_boundarysp  G 7 %& e!'4u=W~a  j)84 fv.rN)rDrErFrjrlrwryr|r~rrrrrrrrrYrYas9 // 3: //" / $ $ $$ /rrYcNeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) HTTPHeadersTestcdjdd}tj|}|j|dd|j|j ddg|j|dd|j|j dd d g|jt t |jgd y) Nz>Foo: bar baz Asdf: qwer zxcv Foo: even more lines rqrrasdf qwer zxcvFoozbar baz,even more linesfoobar bazeven more lines))Asdfr)rr)rr)rerrPr$get_listsortedrRget_allr&rgheaderss rtest_multi_linezHTTPHeadersTest.test_multi_lines  G &  ##D) +6 ))&1K=A )BC ))%09>O2PQ  4)* + S rcd}tj|}|j|ddd}|jttj|d}|jttj|y)NzFoo: bar asdfrzbar asdfz Foo: barzFoo: bar asdf)rrPr$rr rs rtest_continuationz!HTTPHeadersTest.test_continuation6si###D) 4  .+*;*;TB$ .+*;*;TBrctdD]}}dt|d}|dk(s |dk\r=|dk7r8tj|}|j |ddt|d Y|j t tj|y) NzFoo: barzbaz rbarbaz)rangechrrrPr$rr )r&crgrs rtest_forbidden_ascii_charactersz/HTTPHeadersTest.test_forbidden_ascii_charactersFst KAc!fXW-DDyQ$Y19%++D1  3s1vhc1BC!!.+2C2CTJ  Krc gd}|D]}dD]} |j|}d|zdz}tjt |j d}ddt |j dzdzfg}|j |t|jy#t$rYwxYw#t$rtjd ||wxYw) N)…u
u
)r latin1s Cookie: foo=sbarrCookiezfoo=rzfailed while trying %r in %s) r{UnicodeEncodeErrorrrPrdecoder$rRr Exceptionrwarning)r&newlinesnewlineencodingencodedrgrexpecteds rtest_unicode_newlinesz%HTTPHeadersTest.test_unicode_newlinesQs    G. !")..":+W4v=D*// 4;;x;P0QRG%"Zx0H%IIEQ H $$XtGOO4E/FG#   .! !!OO$BGXVs)B(BB7( B41B73B44B77"Ccgd}|D]T\}}tjd|z}|rdg}ndd|zfg}|j|t|j Vy)N)) T) T) F)rFzTransfer-Encoding: %schunked)Transfer-Encodingchunkedrz %schunked)rrPr$rRr)r& whitespacerstrippedrrs rtest_unicode_whitespacez'HTTPHeadersTest.test_unicode_whitespace|sn  & @KAx!''(F(JKG<=0+/BC   XtGOO,='> ?  @rc|jt5tjddddtjd}|j t |j gdy#1swYJxYw)Nz&CRLF: crlf LF: lf CR: cr More: more zCRLF: crlf LF: lf More: more ))Crlfcrlf)Lflf)Moremore)rr rrPr$rrr&rs rtest_optional_crz HTTPHeadersTest.test_optional_crsk   ~ . N   L M N ##$JK  7??$ % >  N Ns A55A>c gd}t}|D]\}}|j|||j}tj|}tj|}||||fD]4}|j t t |j|6|||fD]D}|j|||j|jd|jdFy)N))ArK)rrN)Brr) raddcopydeepcopyr$rRrr assertIsNotr) r& all_pairsh1kvh2h3h4rs r test_copyzHTTPHeadersTest.test_copys8 ] DAq FF1aL  WWY YYr] ]]2 BB' IG   T&):";y#1swYIxYw)N)zfoo barzfoo barzfoo barzfoobarzfoo z fooér)rrr r)r& invalid_namesnamers rtest_invalid_header_namesz)HTTPHeadersTest.test_invalid_header_namessW  " )D!mG"">2 ) D%( ) ) ) ) )s AA N)rDrErFrrrrrrrrrrrrrrrrs@ 4C K)V@&  F"M Y,)rrcJeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) FormatTimestampTestg*; R]AAzSun, 27 Jan 2013 18:43:20 GMTcN|jt||jyN)r$rEXPECTED)r&values rcheckzFormatTimestampTest.checks )%0$--@rc:|j|jyr)r TIMESTAMPr&s rtest_unix_time_floatz(FormatTimestampTest.test_unix_time_floats 4>>"rcL|jt|jyr)rintrrs rtest_unix_time_intz&FormatTimestampTest.test_unix_time_ints 3t~~&'rc`|jtj|jyr)rtimegmtimerrs rtest_struct_timez$FormatTimestampTest.test_struct_times 4;;t~~./rcttj|j}|j dt ||j |y)Nr)tuplerrrr$lenr)r&tups rtest_time_tuplez#FormatTimestampTest.test_time_tuples8DKK/0 CH% 3rc|jtjj|jtjj j dy)N)tzinfo)rdatetime fromtimestamprtimezoneutcrers rtest_utc_naive_datetimez+FormatTimestampTest.test_utc_naive_datetimesC    + + 1 1 5 5 gTg" rct5|jtjj|jdddy#1swYyxYwr)rrr utcfromtimestamprrs r"test_utc_naive_datetime_deprecatedz6FormatTimestampTest.test_utc_naive_datetime_deprecatedsB  ! K JJx((99$..I J K K Ks 9A  Ac|jtjj|jtjj yr)rr rrrrrs rtest_utc_aware_datetimez+FormatTimestampTest.test_utc_aware_datetimes4    + +DNNH@:/[]?{}=d " =e,f gza b,c<>@:/[]?{}z d " =e,f gusaint=André BessettesaintuAndré Bessettez = b ; ; = ; c = ; r)rrN)rSr keysr$rrs rtest_invalid_cookiesz$ParseCookieTest.test_invalid_cookiesPs  ? @ E E G m4CSs6ST  . /9C1P   9 : . 1  0 1 j!23 4   9 :2rqs    ,0  $$d3U #34d3X;N6OOP/