<s> import base64 <EOL> import hmac <EOL> import time <EOL> import sys <EOL> from hashlib import sha1 <EOL> try : <EOL> from lxml . etree import Element , SubElement <EOL> except ImportError : <EOL> from xml . etree . ElementTree import Element , SubElement <EOL> from libcloud . utils . py3 import httplib <EOL> from libcloud . utils . py3 import urlquote <EOL> from libcloud . utils . py3 import urlencode <EOL> from libcloud . utils . py3 import b <EOL> from libcloud . utils . py3 import tostring <EOL> from libcloud . utils . xml import fixxpath , findtext <EOL> from libcloud . utils . files import read_in_chunks <EOL> from libcloud . common . types import InvalidCredsError , LibcloudError <EOL> from libcloud . common . base import ConnectionUserAndKey , RawResponse <EOL> from libcloud . common . aws import AWSBaseResponse , AWSDriver , AWSTokenConnection , SignedAWSConnection <EOL> from libcloud . storage . base import Object , Container , StorageDriver <EOL> from libcloud . storage . types import ContainerError <EOL> from libcloud . storage . types import ContainerIsNotEmptyError <EOL> from libcloud . storage . types import InvalidContainerNameError <EOL> from libcloud . storage . types import ContainerDoesNotExistError <EOL> from libcloud . storage . types import ObjectDoesNotExistError <EOL> from libcloud . storage . types import ObjectHashMismatchError <EOL> EXPIRATION_SECONDS = <NUM_LIT:15> * <NUM_LIT> <EOL> S3_US_STANDARD_HOST = '<STR_LIT>' <EOL> S3_US_WEST_HOST = '<STR_LIT>' <EOL> S3_US_WEST_OREGON_HOST = '<STR_LIT>' <EOL> S3_EU_WEST_HOST = '<STR_LIT>' <EOL> S3_AP_SOUTHEAST_HOST = '<STR_LIT>' <EOL> S3_AP_NORTHEAST1_HOST = '<STR_LIT>' <EOL> S3_AP_NORTHEAST2_HOST = '<STR_LIT>' <EOL> S3_AP_NORTHEAST_HOST = S3_AP_NORTHEAST1_HOST <EOL> S3_SA_EAST_HOST = '<STR_LIT>' <EOL> S3_RGW_OUTSCALE_HOSTS_BY_REGION = { '<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> S3_RGW_OUTSCALE_DEFAULT_REGION = '<STR_LIT>' <EOL> API_VERSION = '<STR_LIT>' <EOL> NAMESPACE = '<STR_LIT>' % ( API_VERSION ) <EOL> CHUNK_SIZE = <NUM_LIT:5> * <NUM_LIT> * <NUM_LIT> <EOL> RESPONSES_PER_REQUEST = <NUM_LIT:100> <EOL> class S3Response ( AWSBaseResponse ) : <EOL> namespace = None <EOL> valid_response_codes = [ httplib . NOT_FOUND , httplib . CONFLICT , <EOL> httplib . BAD_REQUEST ] <EOL> def success ( self ) : <EOL> i = int ( self . status ) <EOL> return i >= <NUM_LIT:200> and i <= <NUM_LIT> or i in self . valid_response_codes <EOL> def parse_error ( self ) : <EOL> if self . status in [ httplib . UNAUTHORIZED , httplib . FORBIDDEN ] : <EOL> raise InvalidCredsError ( self . body ) <EOL> elif self . status == httplib . MOVED_PERMANENTLY : <EOL> raise LibcloudError ( '<STR_LIT>' + <EOL> '<STR_LIT>' , <EOL> driver = S3StorageDriver ) <EOL> raise LibcloudError ( '<STR_LIT>' % ( self . status ) , <EOL> driver = S3StorageDriver ) <EOL> class S3RawResponse ( S3Response , RawResponse ) : <EOL> pass <EOL> class BaseS3Connection ( ConnectionUserAndKey ) : <EOL> """<STR_LIT>""" <EOL> host = '<STR_LIT>' <EOL> responseCls = S3Response <EOL> rawResponseCls = S3RawResponse <EOL> @ staticmethod <EOL> def get_auth_signature ( method , headers , params , expires , secret_key , path , <EOL> vendor_prefix ) : <EOL> """<STR_LIT>""" <EOL> special_headers = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:date>' : '<STR_LIT>' } <EOL> vendor_headers = { } <EOL> for key , value in list ( headers . items ( ) ) : <EOL> key_lower = key . lower ( ) <EOL> if key_lower in special_headers : <EOL> special_headers [ key_lower ] = value . strip ( ) <EOL> elif key_lower . startswith ( vendor_prefix ) : <EOL> vendor_headers [ key_lower ] = value . strip ( ) <EOL> if expires : <EOL> special_headers [ '<STR_LIT:date>' ] = str ( expires ) <EOL> buf = [ method ] <EOL> for _ , value in sorted ( special_headers . items ( ) ) : <EOL> buf . append ( value ) <EOL> string_to_sign = '<STR_LIT:\n>' . join ( buf ) <EOL> buf = [ ] <EOL> for key , value in sorted ( vendor_headers . items ( ) ) : <EOL> buf . append ( '<STR_LIT>' % ( key , value ) ) <EOL> header_string = '<STR_LIT:\n>' . join ( buf ) <EOL> values_to_sign = [ ] <EOL> for value in [ string_to_sign , header_string , path ] : <EOL> if value : <EOL> values_to_sign . append ( value ) <EOL> string_to_sign = '<STR_LIT:\n>' . join ( values_to_sign ) <EOL> b64_hmac = base64 . b64encode ( <EOL> hmac . new ( b ( secret_key ) , b ( string_to_sign ) , digestmod = sha1 ) . digest ( ) <EOL> ) <EOL> return b64_hmac . decode ( '<STR_LIT:utf-8>' ) <EOL> def add_default_params ( self , params ) : <EOL> expires = str ( int ( time . time ( ) ) + EXPIRATION_SECONDS ) <EOL> params [ '<STR_LIT>' ] = self . user_id <EOL> params [ '<STR_LIT>' ] = expires <EOL> return params <EOL> def pre_connect_hook ( self , params , headers ) : <EOL> params [ '<STR_LIT>' ] = self . get_auth_signature ( <EOL> method = self . method , headers = headers , params = params , <EOL> expires = params [ '<STR_LIT>' ] , secret_key = self . key , path = self . action , <EOL> vendor_prefix = self . driver . http_vendor_prefix ) <EOL> return params , headers <EOL> class S3Connection ( AWSTokenConnection , BaseS3Connection ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class S3MultipartUpload ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , key , id , created_at , initiator , owner ) : <EOL> """<STR_LIT>""" <EOL> self . key = key <EOL> self . id = id <EOL> self . created_at = created_at <EOL> self . initiator = initiator <EOL> self . owner = owner <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' % ( self . key ) ) <EOL> class BaseS3StorageDriver ( StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> website = '<STR_LIT>' <EOL> connectionCls = BaseS3Connection <EOL> hash_type = '<STR_LIT>' <EOL> supports_chunked_encoding = False <EOL> supports_s3_multipart_upload = True <EOL> ex_location_name = '<STR_LIT>' <EOL> namespace = NAMESPACE <EOL> http_vendor_prefix = '<STR_LIT>' <EOL> def iterate_containers ( self ) : <EOL> response = self . connection . request ( '<STR_LIT:/>' ) <EOL> if response . status == httplib . OK : <EOL> containers = self . _to_containers ( obj = response . object , <EOL> xpath = '<STR_LIT>' ) <EOL> return containers <EOL> raise LibcloudError ( '<STR_LIT>' % ( response . status ) , <EOL> driver = self ) <EOL> def list_container_objects ( self , container , ex_prefix = None ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iterate_container_objects ( container , <EOL> ex_prefix = ex_prefix ) ) <EOL> def iterate_container_objects ( self , container , ex_prefix = None ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> if ex_prefix : <EOL> params [ '<STR_LIT>' ] = ex_prefix <EOL> last_key = None <EOL> exhausted = False <EOL> container_path = self . _get_container_path ( container ) <EOL> while not exhausted : <EOL> if last_key : <EOL> params [ '<STR_LIT>' ] = last_key <EOL> response = self . connection . request ( container_path , <EOL> params = params ) <EOL> if response . status != httplib . OK : <EOL> raise LibcloudError ( '<STR_LIT>' % <EOL> ( response . status ) , driver = self ) <EOL> objects = self . _to_objs ( obj = response . object , <EOL> xpath = '<STR_LIT>' , container = container ) <EOL> is_truncated = response . object . findtext ( fixxpath ( <EOL> xpath = '<STR_LIT>' , namespace = self . namespace ) ) . lower ( ) <EOL> exhausted = ( is_truncated == '<STR_LIT:false>' ) <EOL> last_key = None <EOL> for obj in objects : <EOL> last_key = obj . name <EOL> yield obj <EOL> def get_container ( self , container_name ) : <EOL> try : <EOL> response = self . connection . request ( '<STR_LIT>' % container_name , <EOL> method = '<STR_LIT>' ) <EOL> if response . status == httplib . NOT_FOUND : <EOL> raise ContainerDoesNotExistError ( value = None , driver = self , <EOL> container_name = container_name ) <EOL> except InvalidCredsError : <EOL> pass <EOL> return Container ( name = container_name , extra = None , driver = self ) <EOL> def get_object ( self , container_name , object_name ) : <EOL> container = self . get_container ( container_name = container_name ) <EOL> object_path = self . _get_object_path ( container , object_name ) <EOL> response = self . connection . request ( object_path , method = '<STR_LIT>' ) <EOL> if response . status == httplib . OK : <EOL> obj = self . _headers_to_object ( object_name = object_name , <EOL> container = container , <EOL> headers = response . headers ) <EOL> return obj <EOL> raise ObjectDoesNotExistError ( value = None , driver = self , <EOL> object_name = object_name ) <EOL> def _get_container_path ( self , container ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( container . name ) <EOL> def _get_object_path ( self , container , object_name ) : <EOL> """<STR_LIT>""" <EOL> container_url = self . _get_container_path ( container ) <EOL> object_name_cleaned = self . _clean_object_name ( object_name ) <EOL> object_path = '<STR_LIT>' % ( container_url , object_name_cleaned ) <EOL> return object_path <EOL> def create_container ( self , container_name ) : <EOL> if self . ex_location_name : <EOL> root = Element ( '<STR_LIT>' ) <EOL> child = SubElement ( root , '<STR_LIT>' ) <EOL> child . text = self . ex_location_name <EOL> data = tostring ( root ) <EOL> else : <EOL> data = '<STR_LIT>' <EOL> response = self . connection . request ( '<STR_LIT>' % ( container_name ) , <EOL> data = data , <EOL> method = '<STR_LIT>' ) <EOL> if response . status == httplib . OK : <EOL> container = Container ( name = container_name , extra = None , driver = self ) <EOL> return container <EOL> elif response . status == httplib . CONFLICT : <EOL> raise InvalidContainerNameError ( <EOL> value = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> container_name = container_name , driver = self ) <EOL> elif response . status == httplib . BAD_REQUEST : <EOL> raise ContainerError ( <EOL> value = '<STR_LIT>' % <EOL> response . body , <EOL> container_name = container_name , driver = self ) <EOL> raise LibcloudError ( '<STR_LIT>' % ( response . status ) , <EOL> driver = self ) <EOL> def delete_container ( self , container ) : <EOL> response = self . connection . request ( '<STR_LIT>' % ( container . name ) , <EOL> method = '<STR_LIT>' ) <EOL> if response . status == httplib . NO_CONTENT : <EOL> return True <EOL> elif response . status == httplib . CONFLICT : <EOL> raise ContainerIsNotEmptyError ( <EOL> value = '<STR_LIT>' , <EOL> container_name = container . name , driver = self ) <EOL> elif response . status == httplib . NOT_FOUND : <EOL> raise ContainerDoesNotExistError ( value = None , <EOL> driver = self , <EOL> container_name = container . name ) <EOL> return False <EOL> def download_object ( self , obj , destination_path , overwrite_existing = False , <EOL> delete_on_failure = True ) : <EOL> obj_path = self . _get_object_path ( obj . container , obj . name ) <EOL> response = self . connection . request ( obj_path , method = '<STR_LIT:GET>' , raw = True ) <EOL> return self . _get_object ( obj = obj , callback = self . _save_object , <EOL> response = response , <EOL> callback_kwargs = { <EOL> '<STR_LIT>' : obj , <EOL> '<STR_LIT>' : response . response , <EOL> '<STR_LIT>' : destination_path , <EOL> '<STR_LIT>' : overwrite_existing , <EOL> '<STR_LIT>' : delete_on_failure } , <EOL> success_status_code = httplib . OK ) <EOL> def download_object_as_stream ( self , obj , chunk_size = None ) : <EOL> obj_path = self . _get_object_path ( obj . container , obj . name ) <EOL> response = self . connection . request ( obj_path , method = '<STR_LIT:GET>' , raw = True ) <EOL> return self . _get_object ( obj = obj , callback = read_in_chunks , <EOL> response = response , <EOL> callback_kwargs = { '<STR_LIT>' : response . response , <EOL> '<STR_LIT>' : chunk_size } , <EOL> success_status_code = httplib . OK ) <EOL> def upload_object ( self , file_path , container , object_name , extra = None , <EOL> verify_hash = True , ex_storage_class = None ) : <EOL> """<STR_LIT>""" <EOL> upload_func = self . _upload_file <EOL> upload_func_kwargs = { '<STR_LIT>' : file_path } <EOL> return self . _put_object ( container = container , object_name = object_name , <EOL> upload_func = upload_func , <EOL> upload_func_kwargs = upload_func_kwargs , <EOL> extra = extra , file_path = file_path , <EOL> verify_hash = verify_hash , <EOL> storage_class = ex_storage_class ) <EOL> def _upload_multipart ( self , response , data , iterator , container , <EOL> object_name , calculate_hash = True ) : <EOL> """<STR_LIT>""" <EOL> object_path = self . _get_object_path ( container , object_name ) <EOL> response . body = response . response . read ( ) <EOL> body = response . parse_body ( ) <EOL> upload_id = body . find ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) . text <EOL> try : <EOL> result = self . _upload_from_iterator ( iterator , object_path , <EOL> upload_id , calculate_hash ) <EOL> ( chunks , data_hash , bytes_transferred ) = result <EOL> etag = self . _commit_multipart ( object_path , upload_id , chunks ) <EOL> except Exception : <EOL> exc = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . _abort_multipart ( object_path , upload_id ) <EOL> raise exc <EOL> response . headers [ '<STR_LIT>' ] = etag <EOL> return ( True , data_hash , bytes_transferred ) <EOL> def _upload_from_iterator ( self , iterator , object_path , upload_id , <EOL> calculate_hash = True ) : <EOL> """<STR_LIT>""" <EOL> data_hash = None <EOL> if calculate_hash : <EOL> data_hash = self . _get_hash_function ( ) <EOL> bytes_transferred = <NUM_LIT:0> <EOL> count = <NUM_LIT:1> <EOL> chunks = [ ] <EOL> params = { '<STR_LIT>' : upload_id } <EOL> for data in read_in_chunks ( iterator , chunk_size = CHUNK_SIZE , <EOL> fill_size = True , yield_empty = True ) : <EOL> bytes_transferred += len ( data ) <EOL> if calculate_hash : <EOL> data_hash . update ( data ) <EOL> chunk_hash = self . _get_hash_function ( ) <EOL> chunk_hash . update ( data ) <EOL> chunk_hash = base64 . b64encode ( chunk_hash . digest ( ) ) . decode ( '<STR_LIT:utf-8>' ) <EOL> headers = { '<STR_LIT>' : chunk_hash } <EOL> params [ '<STR_LIT>' ] = count <EOL> request_path = '<STR_LIT:?>' . join ( ( object_path , urlencode ( params ) ) ) <EOL> resp = self . connection . request ( request_path , method = '<STR_LIT>' , <EOL> data = data , headers = headers ) <EOL> if resp . status != httplib . OK : <EOL> raise LibcloudError ( '<STR_LIT>' , driver = self ) <EOL> server_hash = resp . headers [ '<STR_LIT>' ] <EOL> chunks . append ( ( count , server_hash ) ) <EOL> count += <NUM_LIT:1> <EOL> if calculate_hash : <EOL> data_hash = data_hash . hexdigest ( ) <EOL> return ( chunks , data_hash , bytes_transferred ) <EOL> def _commit_multipart ( self , object_path , upload_id , chunks ) : <EOL> """<STR_LIT>""" <EOL> root = Element ( '<STR_LIT>' ) <EOL> for ( count , etag ) in chunks : <EOL> part = SubElement ( root , '<STR_LIT>' ) <EOL> part_no = SubElement ( part , '<STR_LIT>' ) <EOL> part_no . text = str ( count ) <EOL> etag_id = SubElement ( part , '<STR_LIT>' ) <EOL> etag_id . text = str ( etag ) <EOL> data = tostring ( root ) <EOL> params = { '<STR_LIT>' : upload_id } <EOL> request_path = '<STR_LIT:?>' . join ( ( object_path , urlencode ( params ) ) ) <EOL> response = self . connection . request ( request_path , data = data , <EOL> method = '<STR_LIT:POST>' ) <EOL> if response . status != httplib . OK : <EOL> element = response . object <EOL> code , message = response . _parse_error_details ( element = element ) <EOL> msg = '<STR_LIT>' % ( message , code ) <EOL> raise LibcloudError ( msg , driver = self ) <EOL> body = response . parse_body ( ) <EOL> server_hash = body . find ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) . text <EOL> return server_hash <EOL> def _abort_multipart ( self , object_path , upload_id ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : upload_id } <EOL> request_path = '<STR_LIT:?>' . join ( ( object_path , urlencode ( params ) ) ) <EOL> resp = self . connection . request ( request_path , method = '<STR_LIT>' ) <EOL> if resp . status != httplib . NO_CONTENT : <EOL> raise LibcloudError ( '<STR_LIT>' % <EOL> ( resp . status ) , driver = self ) <EOL> def upload_object_via_stream ( self , iterator , container , object_name , <EOL> extra = None , ex_storage_class = None ) : <EOL> """<STR_LIT>""" <EOL> method = '<STR_LIT>' <EOL> params = None <EOL> if self . supports_s3_multipart_upload : <EOL> upload_func = self . _upload_multipart <EOL> upload_func_kwargs = { '<STR_LIT>' : iterator , <EOL> '<STR_LIT>' : container , <EOL> '<STR_LIT:object_name>' : object_name } <EOL> method = '<STR_LIT:POST>' <EOL> iterator = iter ( '<STR_LIT>' ) <EOL> params = '<STR_LIT>' <EOL> elif self . supports_chunked_encoding : <EOL> upload_func = self . _stream_data <EOL> upload_func_kwargs = { '<STR_LIT>' : iterator } <EOL> else : <EOL> upload_func = self . _upload_data <EOL> upload_func_kwargs = { } <EOL> return self . _put_object ( container = container , object_name = object_name , <EOL> upload_func = upload_func , <EOL> upload_func_kwargs = upload_func_kwargs , <EOL> extra = extra , method = method , query_args = params , <EOL> iterator = iterator , verify_hash = False , <EOL> storage_class = ex_storage_class ) <EOL> def delete_object ( self , obj ) : <EOL> object_path = self . _get_object_path ( obj . container , obj . name ) <EOL> response = self . connection . request ( object_path , method = '<STR_LIT>' ) <EOL> if response . status == httplib . NO_CONTENT : <EOL> return True <EOL> elif response . status == httplib . NOT_FOUND : <EOL> raise ObjectDoesNotExistError ( value = None , driver = self , <EOL> object_name = obj . name ) <EOL> return False <EOL> def ex_iterate_multipart_uploads ( self , container , prefix = None , <EOL> delimiter = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . supports_s3_multipart_upload : <EOL> raise LibcloudError ( '<STR_LIT>' , driver = self ) <EOL> request_path = '<STR_LIT>' % ( self . _get_container_path ( container ) ) <EOL> params = { '<STR_LIT>' : RESPONSES_PER_REQUEST } <EOL> if prefix : <EOL> params [ '<STR_LIT>' ] = prefix <EOL> if delimiter : <EOL> params [ '<STR_LIT>' ] = delimiter <EOL> def finder ( node , text ) : <EOL> return node . findtext ( fixxpath ( xpath = text , <EOL> namespace = self . namespace ) ) <EOL> while True : <EOL> response = self . connection . request ( request_path , params = params ) <EOL> if response . status != httplib . OK : <EOL> raise LibcloudError ( '<STR_LIT>' <EOL> '<STR_LIT>' % response . status , <EOL> driver = self ) <EOL> body = response . parse_body ( ) <EOL> for node in body . findall ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) : <EOL> initiator = node . find ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) <EOL> owner = node . find ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) <EOL> key = finder ( node , '<STR_LIT>' ) <EOL> upload_id = finder ( node , '<STR_LIT>' ) <EOL> created_at = finder ( node , '<STR_LIT>' ) <EOL> initiator = finder ( initiator , '<STR_LIT>' ) <EOL> owner = finder ( owner , '<STR_LIT>' ) <EOL> yield S3MultipartUpload ( key , upload_id , created_at , <EOL> initiator , owner ) <EOL> is_truncated = body . findtext ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) <EOL> if is_truncated . lower ( ) == '<STR_LIT:false>' : <EOL> break <EOL> upload_marker = body . findtext ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) <EOL> key_marker = body . findtext ( fixxpath ( xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) <EOL> params [ '<STR_LIT>' ] = key_marker <EOL> params [ '<STR_LIT>' ] = upload_marker <EOL> def ex_cleanup_all_multipart_uploads ( self , container , prefix = None ) : <EOL> """<STR_LIT>""" <EOL> for upload in self . ex_iterate_multipart_uploads ( container , prefix , <EOL> delimiter = None ) : <EOL> object_path = '<STR_LIT>' % ( container . name , upload . key ) <EOL> self . _abort_multipart ( object_path , upload . id ) <EOL> def _clean_object_name ( self , name ) : <EOL> name = urlquote ( name ) <EOL> return name <EOL> def _put_object ( self , container , object_name , upload_func , <EOL> upload_func_kwargs , method = '<STR_LIT>' , query_args = None , <EOL> extra = None , file_path = None , iterator = None , <EOL> verify_hash = True , storage_class = None ) : <EOL> headers = { } <EOL> extra = extra or { } <EOL> storage_class = storage_class or '<STR_LIT>' <EOL> if storage_class not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % ( storage_class ) ) <EOL> key = self . http_vendor_prefix + '<STR_LIT>' <EOL> headers [ key ] = storage_class . upper ( ) <EOL> content_type = extra . get ( '<STR_LIT>' , None ) <EOL> meta_data = extra . get ( '<STR_LIT>' , None ) <EOL> acl = extra . get ( '<STR_LIT>' , None ) <EOL> if meta_data : <EOL> for key , value in list ( meta_data . items ( ) ) : <EOL> key = self . http_vendor_prefix + '<STR_LIT>' % ( key ) <EOL> headers [ key ] = value <EOL> if acl : <EOL> headers [ self . http_vendor_prefix + '<STR_LIT>' ] = acl <EOL> request_path = self . _get_object_path ( container , object_name ) <EOL> if query_args : <EOL> request_path = '<STR_LIT:?>' . join ( ( request_path , query_args ) ) <EOL> result_dict = self . _upload_object ( <EOL> object_name = object_name , content_type = content_type , <EOL> upload_func = upload_func , upload_func_kwargs = upload_func_kwargs , <EOL> request_path = request_path , request_method = method , <EOL> headers = headers , file_path = file_path , iterator = iterator ) <EOL> response = result_dict [ '<STR_LIT>' ] <EOL> bytes_transferred = result_dict [ '<STR_LIT>' ] <EOL> headers = response . headers <EOL> response = response . response <EOL> server_hash = headers [ '<STR_LIT>' ] . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> if ( verify_hash and result_dict [ '<STR_LIT>' ] != server_hash ) : <EOL> raise ObjectHashMismatchError ( <EOL> value = '<STR_LIT>' , <EOL> object_name = object_name , driver = self ) <EOL> elif response . status == httplib . OK : <EOL> obj = Object ( <EOL> name = object_name , size = bytes_transferred , hash = server_hash , <EOL> extra = { '<STR_LIT>' : acl } , meta_data = meta_data , container = container , <EOL> driver = self ) <EOL> return obj <EOL> else : <EOL> raise LibcloudError ( <EOL> '<STR_LIT>' % ( response . status ) , <EOL> driver = self ) <EOL> def _to_containers ( self , obj , xpath ) : <EOL> for element in obj . findall ( fixxpath ( xpath = xpath , <EOL> namespace = self . namespace ) ) : <EOL> yield self . _to_container ( element ) <EOL> def _to_objs ( self , obj , xpath , container ) : <EOL> return [ self . _to_obj ( element , container ) for element in <EOL> obj . findall ( fixxpath ( xpath = xpath , namespace = self . namespace ) ) ] <EOL> def _to_container ( self , element ) : <EOL> extra = { <EOL> '<STR_LIT>' : findtext ( element = element , xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) <EOL> } <EOL> container = Container ( name = findtext ( element = element , xpath = '<STR_LIT:Name>' , <EOL> namespace = self . namespace ) , <EOL> extra = extra , <EOL> driver = self <EOL> ) <EOL> return container <EOL> def _headers_to_object ( self , object_name , container , headers ) : <EOL> hash = headers [ '<STR_LIT>' ] . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> extra = { '<STR_LIT>' : headers [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : headers [ '<STR_LIT>' ] } <EOL> meta_data = { } <EOL> if '<STR_LIT>' in headers : <EOL> extra [ '<STR_LIT>' ] = headers [ '<STR_LIT>' ] <EOL> for key , value in headers . items ( ) : <EOL> if not key . lower ( ) . startswith ( self . http_vendor_prefix + '<STR_LIT>' ) : <EOL> continue <EOL> key = key . replace ( self . http_vendor_prefix + '<STR_LIT>' , '<STR_LIT>' ) <EOL> meta_data [ key ] = value <EOL> obj = Object ( name = object_name , size = headers [ '<STR_LIT>' ] , <EOL> hash = hash , extra = extra , <EOL> meta_data = meta_data , <EOL> container = container , <EOL> driver = self ) <EOL> return obj <EOL> def _to_obj ( self , element , container ) : <EOL> owner_id = findtext ( element = element , xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) <EOL> owner_display_name = findtext ( element = element , <EOL> xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) <EOL> meta_data = { '<STR_LIT>' : { '<STR_LIT:id>' : owner_id , <EOL> '<STR_LIT>' : owner_display_name } } <EOL> last_modified = findtext ( element = element , <EOL> xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) <EOL> extra = { '<STR_LIT>' : last_modified } <EOL> obj = Object ( name = findtext ( element = element , xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) , <EOL> size = int ( findtext ( element = element , xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) ) , <EOL> hash = findtext ( element = element , xpath = '<STR_LIT>' , <EOL> namespace = self . namespace ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) , <EOL> extra = extra , <EOL> meta_data = meta_data , <EOL> container = container , <EOL> driver = self <EOL> ) <EOL> return obj <EOL> class S3StorageDriver ( AWSDriver , BaseS3StorageDriver ) : <EOL> connectionCls = S3Connection <EOL> class S3USWestConnection ( S3Connection ) : <EOL> host = S3_US_WEST_HOST <EOL> class S3USWestStorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3USWestConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> class S3USWestOregonConnection ( S3Connection ) : <EOL> host = S3_US_WEST_OREGON_HOST <EOL> class S3USWestOregonStorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3USWestOregonConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> class S3EUWestConnection ( S3Connection ) : <EOL> host = S3_EU_WEST_HOST <EOL> class S3EUWestStorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3EUWestConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> class S3APSEConnection ( S3Connection ) : <EOL> host = S3_AP_SOUTHEAST_HOST <EOL> class S3APSEStorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3APSEConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> class S3APNE1Connection ( S3Connection ) : <EOL> host = S3_AP_NORTHEAST1_HOST <EOL> S3APNEConnection = S3APNE1Connection <EOL> class S3APNE1StorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3APNEConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> S3APNEStorageDriver = S3APNE1StorageDriver <EOL> class S3APNE2Connection ( SignedAWSConnection , BaseS3Connection ) : <EOL> host = S3_AP_NORTHEAST2_HOST <EOL> service_name = '<STR_LIT>' <EOL> version = API_VERSION <EOL> def __init__ ( self , user_id , key , secure = True , host = None , port = None , <EOL> url = None , timeout = None , proxy_url = None , token = None , <EOL> retry_delay = None , backoff = None ) : <EOL> super ( S3APNE2Connection , self ) . __init__ ( user_id , key , secure , host , <EOL> port , url , timeout , proxy_url , <EOL> token , retry_delay , backoff , <EOL> <NUM_LIT:4> ) <EOL> class S3APNE2StorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3APNE2Connection <EOL> ex_location_name = '<STR_LIT>' <EOL> region_name = '<STR_LIT>' <EOL> class S3SAEastConnection ( S3Connection ) : <EOL> host = S3_SA_EAST_HOST <EOL> class S3SAEastStorageDriver ( S3StorageDriver ) : <EOL> name = '<STR_LIT>' <EOL> connectionCls = S3SAEastConnection <EOL> ex_location_name = '<STR_LIT>' <EOL> class S3RGWOutscaleConnection ( S3Connection ) : <EOL> pass <EOL> class S3RGWOutscaleStorageDriver ( S3StorageDriver ) : <EOL> def __init__ ( self , key , secret = None , secure = True , host = None , port = None , <EOL> api_version = None , region = S3_RGW_OUTSCALE_DEFAULT_REGION , <EOL> ** kwargs ) : <EOL> if region not in S3_RGW_OUTSCALE_HOSTS_BY_REGION : <EOL> raise LibcloudError ( '<STR_LIT>' % ( region ) , driver = self ) <EOL> self . name = '<STR_LIT>' % ( region ) <EOL> self . ex_location_name = region <EOL> self . region_name = region <EOL> self . connectionCls = S3RGWOutscaleConnection <EOL> self . connectionCls . host = S3_RGW_OUTSCALE_HOSTS_BY_REGION [ region ] <EOL> super ( S3RGWOutscaleStorageDriver , self ) . __init__ ( key , secret , <EOL> secure , host , port , <EOL> api_version , region , <EOL> ** kwargs ) </s>
