<s> import socket <EOL> from functools import partial <EOL> from pprint import pformat <EOL> from marrow . server . http . testing import HTTPTestCase , CRLF , EOH <EOL> from marrow . util . compat import unicode <EOL> log = __import__ ( '<STR_LIT>' ) . getLogger ( __name__ ) <EOL> from applications import * <EOL> class TestHTTP11Protocol ( HTTPTestCase ) : <EOL> arguments = dict ( application = partial ( echo , False ) ) <EOL> def test_headers ( self ) : <EOL> response = self . request ( headers = [ ( b'<STR_LIT>' , b'<STR_LIT>' ) ] ) <EOL> self . assertEquals ( response . protocol , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . code , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . status , b"<STR_LIT:OK>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> def test_request ( self ) : <EOL> response = self . request ( headers = [ ( b'<STR_LIT>' , b'<STR_LIT>' ) ] ) <EOL> self . assertEquals ( response . protocol , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . code , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . status , b"<STR_LIT:OK>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> request = eval ( response . body ) <EOL> expect = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : b'<STR_LIT:/>' . decode ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : ( <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : b'<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' <EOL> } <EOL> self . assertEquals ( request , expect ) <EOL> def test_single ( self ) : <EOL> self . request ( headers = [ ( b'<STR_LIT>' , b'<STR_LIT>' ) ] ) <EOL> def try_again ( ) : <EOL> self . request ( headers = [ ( b'<STR_LIT>' , b'<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ( socket . error , IOError ) , try_again ) <EOL> def test_keepalive ( self ) : <EOL> one = self . request ( ) <EOL> two = self . request ( ) <EOL> self . assertEquals ( one , two ) <EOL> class TestChunkedHTTP11Protocol ( HTTPTestCase ) : <EOL> arguments = dict ( application = partial ( echo , True ) ) <EOL> maxDiff = None <EOL> def test_chunked ( self ) : <EOL> response = self . request ( ) <EOL> self . assertEquals ( response . protocol , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . code , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . status , b"<STR_LIT:OK>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> request = eval ( response . body ) <EOL> expect = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : b'<STR_LIT:/>' . decode ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : ( <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : b'<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' <EOL> } <EOL> self . assertEquals ( request , expect ) <EOL> class TestHTTP11BodyProtocol ( HTTPTestCase ) : <EOL> arguments = dict ( application = partial ( echo , True ) ) <EOL> maxDiff = None <EOL> def test_normal ( self ) : <EOL> body = b"<STR_LIT>" <EOL> response = self . request ( b"<STR_LIT>" , headers = [ ( b'<STR_LIT>' , unicode ( len ( body ) ) . encode ( '<STR_LIT:ascii>' ) ) ] , body = [ body ] ) <EOL> self . assertEquals ( response . protocol , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . code , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . status , b"<STR_LIT:OK>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> request = eval ( response . body ) <EOL> expect = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : b'<STR_LIT:/>' . decode ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : ( <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : b'<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> '<STR_LIT>' : b"<STR_LIT>" <EOL> } <EOL> self . assertEquals ( request , expect ) <EOL> def test_chunked ( self ) : <EOL> body = b"<STR_LIT>" <EOL> response = self . request ( b"<STR_LIT>" , body = [ body ] ) <EOL> self . assertEquals ( response . protocol , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . code , b"<STR_LIT>" ) <EOL> self . assertEquals ( response . status , b"<STR_LIT:OK>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> self . assertEquals ( response [ b'<STR_LIT>' ] , b"<STR_LIT>" ) <EOL> request = eval ( response . body ) <EOL> expect = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : b'<STR_LIT:/>' . decode ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : unicode ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:127.0.0.1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : ( <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : b'<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> '<STR_LIT>' : b'<STR_LIT>' <EOL> } <EOL> self . assertEquals ( request , expect ) </s>
