<s> import unittest <EOL> from pulsar . utils . httpurl import Headers , SimpleCookie <EOL> class TestHeaders ( unittest . TestCase ) : <EOL> def testServerHeader ( self ) : <EOL> h = Headers ( ) <EOL> self . assertEqual ( h . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:0> ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> def testHeaderBytes ( self ) : <EOL> h = Headers ( kind = None ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertTrue ( repr ( h ) . startswith ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( bytes ( h ) , b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> def testClientHeader ( self ) : <EOL> h = Headers ( kind = '<STR_LIT>' ) <EOL> self . assertEqual ( h . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:0> ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( h . get_all ( '<STR_LIT>' ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> del h [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( h . get_all ( '<STR_LIT>' , [ ] ) , [ ] ) <EOL> def test_non_standard_request_headers ( self ) : <EOL> h = Headers ( kind = '<STR_LIT>' ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> h [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:2> ) <EOL> headers = str ( h ) <EOL> self . assertTrue ( '<STR_LIT>' in headers ) <EOL> def test_multiple_entry ( self ) : <EOL> h = Headers ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] , <EOL> kind = '<STR_LIT>' ) <EOL> accept = h [ '<STR_LIT>' ] <EOL> self . assertEqual ( accept , '<STR_LIT>' ) <EOL> def test_init_int ( self ) : <EOL> h = Headers ( kind = <NUM_LIT:1> ) <EOL> self . assertEqual ( h . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( h . kind_number , <NUM_LIT:1> ) <EOL> h = Headers ( kind = <NUM_LIT:0> ) <EOL> self . assertEqual ( h . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( h . kind_number , <NUM_LIT:0> ) <EOL> h = Headers ( kind = <NUM_LIT> ) <EOL> self . assertEqual ( h . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( h . kind_number , <NUM_LIT:2> ) <EOL> def test_remove_header ( self ) : <EOL> h = Headers ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( h . remove_header ( '<STR_LIT:foo>' ) , None ) <EOL> self . assertEqual ( h . remove_header ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( h . remove_header ( '<STR_LIT>' ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:0> ) <EOL> def test_remove_header_value ( self ) : <EOL> h = Headers ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] , kind = <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( h . remove_header ( '<STR_LIT>' , '<STR_LIT:x>' ) , None ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( h . remove_header ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_override ( self ) : <EOL> h = Headers ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] , kind = <NUM_LIT:2> ) <EOL> h . override ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( len ( h ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_cookies ( self ) : <EOL> h = Headers ( ) <EOL> cookies = SimpleCookie ( { '<STR_LIT>' : '<STR_LIT:foo>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( len ( cookies ) , <NUM_LIT:2> ) <EOL> for c in cookies . values ( ) : <EOL> v = c . OutputString ( ) <EOL> h . add_header ( '<STR_LIT>' , v ) <EOL> h = str ( h ) <EOL> self . assertTrue ( <EOL> h in ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) </s>
