<s> import httplib2 <EOL> from urlparse import urlsplit <EOL> from django_dust . settings import getsetting <EOL> class HTTPError ( Exception ) : <EOL> pass <EOL> class HTTPTransport ( object ) : <EOL> '''<STR_LIT>''' <EOL> timeout = getsetting ( '<STR_LIT>' ) <EOL> def __init__ ( self , base_url ) : <EOL> scheme , host , path , query , fragment = urlsplit ( base_url ) <EOL> self . scheme = scheme or '<STR_LIT:http>' <EOL> self . url_path = path or '<STR_LIT:/>' <EOL> def _get_url ( self , host , name ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( self . scheme , host , self . url_path , name ) <EOL> def _headers ( self , host , name ) : <EOL> '''<STR_LIT>''' <EOL> http = httplib2 . Http ( timeout = self . timeout ) <EOL> url = self . _get_url ( host , name ) <EOL> response , response_body = http . request ( url , '<STR_LIT>' ) <EOL> if response . status >= <NUM_LIT> and response . status != <NUM_LIT> : <EOL> raise HTTPError ( '<STR_LIT>' , url , response . status ) <EOL> return response <EOL> def put ( self , host , name , body ) : <EOL> http = httplib2 . Http ( timeout = self . timeout ) <EOL> url = self . _get_url ( host , name ) <EOL> response , response_body = http . request ( url , '<STR_LIT>' , <EOL> body = body , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> if response . status >= <NUM_LIT> : <EOL> raise HTTPError ( '<STR_LIT>' , url , response . status ) <EOL> def delete ( self , host , name ) : <EOL> http = httplib2 . Http ( timeout = self . timeout ) <EOL> url = self . _get_url ( host , name ) <EOL> response , response_body = http . request ( url , '<STR_LIT>' ) <EOL> if response . status >= <NUM_LIT> and response . status != <NUM_LIT> : <EOL> raise HTTPError ( '<STR_LIT>' , url , response . status ) <EOL> def get ( self , host , name ) : <EOL> http = httplib2 . Http ( timeout = self . timeout ) <EOL> url = self . _get_url ( host , name ) <EOL> response , response_body = http . request ( url , '<STR_LIT:GET>' ) <EOL> if response . status >= <NUM_LIT> : <EOL> raise HTTPError ( '<STR_LIT:GET>' , url , response . status ) <EOL> return response_body <EOL> def exists ( self , host , name ) : <EOL> response = self . _headers ( host , name ) <EOL> return response . status == <NUM_LIT:200> <EOL> def size ( self , host , name ) : <EOL> response = self . _headers ( host , name ) <EOL> try : <EOL> return int ( response [ '<STR_LIT>' ] ) <EOL> except ( KeyError , ValueError ) : <EOL> raise Exception ( '<STR_LIT>' % ( <EOL> name , <EOL> response . get ( '<STR_LIT>' ) , <EOL> ) ) </s>
