<s> """<STR_LIT:U+0020>""" <EOL> import httplib <EOL> import json <EOL> from errors import * <EOL> class Connection ( object ) : <EOL> def __init__ ( self , host = '<STR_LIT>' , secure = True , port = None , root = '<STR_LIT>' , <EOL> timeout = <NUM_LIT> ) : <EOL> self . host = host <EOL> self . secure = secure <EOL> self . port = port <EOL> self . root = root <EOL> self . timeout = timeout <EOL> self . authenticator = None <EOL> self . http_conn = None <EOL> def request ( self , method , path , body = None , headers = { } ) : <EOL> if not self . port : <EOL> self . port = <NUM_LIT> if self . secure else <NUM_LIT> <EOL> if self . secure : <EOL> self . http_conn = httplib . HTTPSConnection ( self . host , self . port , <EOL> timeout = self . timeout ) <EOL> else : <EOL> self . http_conn = httplib . HTTPConnection ( self . host , self . port , <EOL> timeout = self . timeout ) <EOL> if self . authenticator : <EOL> self . authenticator . add_auth ( headers ) <EOL> self . http_conn . request ( method , self . root + path , body , headers = headers ) <EOL> response = self . http_conn . getresponse ( ) <EOL> body = response . read ( ) <EOL> try : <EOL> data = json . loads ( body ) <EOL> except ValueError : <EOL> data = body <EOL> if response . status == <NUM_LIT> : <EOL> raise AuthenticationError ( ) <EOL> elif response . status == <NUM_LIT> : <EOL> raise InternalServerError ( ) <EOL> elif response . status == <NUM_LIT> : <EOL> raise BadRequestError ( body ) <EOL> elif response . status == <NUM_LIT> : <EOL> raise NotFoundError ( ) <EOL> return ( response , data ) </s>
