<s> from . auth import S3Auth <EOL> from . request_factory import UploadRequest , UpdateMetadataRequest , CopyRequest , DeleteRequest , GetRequest , ListRequest <EOL> class Base ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , access_key , secret_key , default_bucket = None , tls = False , endpoint = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> self . default_bucket = default_bucket <EOL> self . auth = S3Auth ( access_key , secret_key ) <EOL> self . tls = tls <EOL> self . endpoint = endpoint <EOL> def bucket ( self , bucket ) : <EOL> """<STR_LIT>""" <EOL> b = bucket or self . default_bucket <EOL> if not b : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return b <EOL> def get ( self , key , bucket = None ) : <EOL> """<STR_LIT>""" <EOL> r = GetRequest ( self , key , self . bucket ( bucket ) ) <EOL> return self . run ( r ) <EOL> def list ( self , prefix = '<STR_LIT>' , bucket = None ) : <EOL> """<STR_LIT>""" <EOL> r = ListRequest ( self , prefix , self . bucket ( bucket ) ) <EOL> return self . run ( r ) <EOL> def upload ( self , key , local_file , <EOL> bucket = None , expires = None , content_type = None , <EOL> public = True , headers = None , rewind = True , close = False ) : <EOL> """<STR_LIT>""" <EOL> r = UploadRequest ( self , key , local_file , self . bucket ( bucket ) , expires = expires , content_type = content_type , <EOL> public = public , extra_headers = headers , rewind = rewind , close = close ) <EOL> return self . run ( r ) <EOL> def copy ( self , from_key , from_bucket , to_key , to_bucket = None , metadata = None , public = True ) : <EOL> """<STR_LIT>""" <EOL> to_bucket = self . bucket ( to_bucket or from_bucket ) <EOL> r = CopyRequest ( self , from_key , from_bucket , to_key , to_bucket , metadata = metadata , public = public ) <EOL> return self . run ( r ) <EOL> def update_metadata ( self , key , metadata = None , bucket = None , public = True ) : <EOL> """<STR_LIT>""" <EOL> r = UpdateMetadataRequest ( self , key , self . bucket ( bucket ) , metadata , public ) <EOL> return self . run ( r ) <EOL> def delete ( self , key , bucket = None ) : <EOL> """<STR_LIT>""" <EOL> r = DeleteRequest ( self , key , self . bucket ( bucket ) ) <EOL> return self . run ( r ) <EOL> def run ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . _handle_request ( request ) <EOL> def _handle_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Connection ( Base ) : <EOL> """<STR_LIT>""" <EOL> def _handle_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return request . run ( ) </s>
