<s> from __future__ import absolute_import , division , print_function , with_statement <EOL> from tornado . httputil import url_concat , parse_multipart_form_data , HTTPHeaders , format_timestamp <EOL> from tornado . escape import utf8 <EOL> from tornado . log import gen_log <EOL> from tornado . testing import ExpectLog <EOL> from tornado . test . util import unittest <EOL> import datetime <EOL> import logging <EOL> import time <EOL> class TestUrlConcat ( unittest . TestCase ) : <EOL> def test_url_concat_no_query_params ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT:y>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_encode_args ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_trailing_q ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT:y>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_q_with_no_trailing_amp ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT:y>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_trailing_amp ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT:y>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_mult_params ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ( '<STR_LIT:y>' , '<STR_LIT:y>' ) , ( '<STR_LIT:z>' , '<STR_LIT:z>' ) ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> def test_url_concat_no_params ( self ) : <EOL> url = url_concat ( <EOL> "<STR_LIT>" , <EOL> [ ] , <EOL> ) <EOL> self . assertEqual ( url , "<STR_LIT>" ) <EOL> class MultipartFormDataTest ( unittest . TestCase ) : <EOL> def test_file_upload ( self ) : <EOL> data = b"""<STR_LIT>""" . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> file = files [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( file [ "<STR_LIT:filename>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( file [ "<STR_LIT:body>" ] , b"<STR_LIT>" ) <EOL> def test_unquoted_names ( self ) : <EOL> data = b"""<STR_LIT>""" . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> file = files [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( file [ "<STR_LIT:filename>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( file [ "<STR_LIT:body>" ] , b"<STR_LIT>" ) <EOL> def test_special_filenames ( self ) : <EOL> filenames = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> for filename in filenames : <EOL> logging . debug ( "<STR_LIT>" , filename ) <EOL> data = """<STR_LIT>""" % filename . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> data = utf8 ( data . replace ( "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) ) <EOL> args = { } <EOL> files = { } <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> file = files [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( file [ "<STR_LIT:filename>" ] , filename ) <EOL> self . assertEqual ( file [ "<STR_LIT:body>" ] , b"<STR_LIT>" ) <EOL> def test_boundary_starts_and_ends_with_quotes ( self ) : <EOL> data = b'''<STR_LIT>''' . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> parse_multipart_form_data ( b'<STR_LIT>' , data , args , files ) <EOL> file = files [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( file [ "<STR_LIT:filename>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( file [ "<STR_LIT:body>" ] , b"<STR_LIT>" ) <EOL> def test_missing_headers ( self ) : <EOL> data = b'''<STR_LIT>''' . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> with ExpectLog ( gen_log , "<STR_LIT>" ) : <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> self . assertEqual ( files , { } ) <EOL> def test_invalid_content_disposition ( self ) : <EOL> data = b'''<STR_LIT>''' . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> with ExpectLog ( gen_log , "<STR_LIT>" ) : <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> self . assertEqual ( files , { } ) <EOL> def test_line_does_not_end_with_correct_line_break ( self ) : <EOL> data = b'''<STR_LIT>''' . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> with ExpectLog ( gen_log , "<STR_LIT>" ) : <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> self . assertEqual ( files , { } ) <EOL> def test_content_disposition_header_without_name_parameter ( self ) : <EOL> data = b"""<STR_LIT>""" . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> with ExpectLog ( gen_log , "<STR_LIT>" ) : <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> self . assertEqual ( files , { } ) <EOL> def test_data_after_final_boundary ( self ) : <EOL> data = b"""<STR_LIT>""" . replace ( b"<STR_LIT:\n>" , b"<STR_LIT:\r\n>" ) <EOL> args = { } <EOL> files = { } <EOL> parse_multipart_form_data ( b"<STR_LIT>" , data , args , files ) <EOL> file = files [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( file [ "<STR_LIT:filename>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( file [ "<STR_LIT:body>" ] , b"<STR_LIT>" ) <EOL> class HTTPHeadersTest ( unittest . TestCase ) : <EOL> def test_multi_line ( self ) : <EOL> data = """<STR_LIT>""" . replace ( "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) <EOL> headers = HTTPHeaders . parse ( data ) <EOL> self . assertEqual ( headers [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( headers . get_list ( "<STR_LIT>" ) , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( headers [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( headers . get_list ( "<STR_LIT:foo>" ) , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( sorted ( list ( headers . get_all ( ) ) ) , <EOL> [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] ) <EOL> class FormatTimestampTest ( unittest . TestCase ) : <EOL> TIMESTAMP = <NUM_LIT> <EOL> EXPECTED = '<STR_LIT>' <EOL> def check ( self , value ) : <EOL> self . assertEqual ( format_timestamp ( value ) , self . EXPECTED ) <EOL> def test_unix_time_float ( self ) : <EOL> self . check ( self . TIMESTAMP ) <EOL> def test_unix_time_int ( self ) : <EOL> self . check ( int ( self . TIMESTAMP ) ) <EOL> def test_struct_time ( self ) : <EOL> self . check ( time . gmtime ( self . TIMESTAMP ) ) <EOL> def test_time_tuple ( self ) : <EOL> tup = tuple ( time . gmtime ( self . TIMESTAMP ) ) <EOL> self . assertEqual ( <NUM_LIT:9> , len ( tup ) ) <EOL> self . check ( tup ) <EOL> def test_datetime ( self ) : <EOL> self . check ( datetime . datetime . utcfromtimestamp ( self . TIMESTAMP ) ) </s>
