<s> import user <EOL> import key <EOL> from boto import handler <EOL> import xml . sax <EOL> class CompleteMultiPartUpload ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bucket = None ) : <EOL> self . bucket = bucket <EOL> self . location = None <EOL> self . bucket_name = None <EOL> self . key_name = None <EOL> self . etag = None <EOL> self . version_id = None <EOL> self . encrypted = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . bucket_name , <EOL> self . key_name ) <EOL> def startElement ( self , name , attrs , connection ) : <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . location = value <EOL> elif name == '<STR_LIT>' : <EOL> self . bucket_name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . key_name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . etag = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> class Part ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bucket = None ) : <EOL> self . bucket = bucket <EOL> self . part_number = None <EOL> self . last_modified = None <EOL> self . etag = None <EOL> self . size = None <EOL> def __repr__ ( self ) : <EOL> if isinstance ( self . part_number , int ) : <EOL> return '<STR_LIT>' % self . part_number <EOL> else : <EOL> return '<STR_LIT>' % None <EOL> def startElement ( self , name , attrs , connection ) : <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . part_number = int ( value ) <EOL> elif name == '<STR_LIT>' : <EOL> self . last_modified = value <EOL> elif name == '<STR_LIT>' : <EOL> self . etag = value <EOL> elif name == '<STR_LIT>' : <EOL> self . size = int ( value ) <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def part_lister ( mpupload , part_number_marker = None ) : <EOL> """<STR_LIT>""" <EOL> more_results = True <EOL> part = None <EOL> while more_results : <EOL> parts = mpupload . get_all_parts ( None , part_number_marker ) <EOL> for part in parts : <EOL> yield part <EOL> part_number_marker = mpupload . next_part_number_marker <EOL> more_results = mpupload . is_truncated <EOL> class MultiPartUpload ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bucket = None ) : <EOL> self . bucket = bucket <EOL> self . bucket_name = None <EOL> self . key_name = None <EOL> self . id = id <EOL> self . initiator = None <EOL> self . owner = None <EOL> self . storage_class = None <EOL> self . initiated = None <EOL> self . part_number_marker = None <EOL> self . next_part_number_marker = None <EOL> self . max_parts = None <EOL> self . is_truncated = False <EOL> self . _parts = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . key_name <EOL> def __iter__ ( self ) : <EOL> return part_lister ( self ) <EOL> def to_xml ( self ) : <EOL> s = '<STR_LIT>' <EOL> for part in self : <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' % part . part_number <EOL> s += '<STR_LIT>' % part . etag <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> return s <EOL> def startElement ( self , name , attrs , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . initiator = user . User ( self ) <EOL> return self . initiator <EOL> elif name == '<STR_LIT>' : <EOL> self . owner = user . User ( self ) <EOL> return self . owner <EOL> elif name == '<STR_LIT>' : <EOL> part = Part ( self . bucket ) <EOL> self . _parts . append ( part ) <EOL> return part <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . bucket_name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . key_name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . id = value <EOL> elif name == '<STR_LIT>' : <EOL> self . storage_class = value <EOL> elif name == '<STR_LIT>' : <EOL> self . part_number_marker = value <EOL> elif name == '<STR_LIT>' : <EOL> self . next_part_number_marker = value <EOL> elif name == '<STR_LIT>' : <EOL> self . max_parts = int ( value ) <EOL> elif name == '<STR_LIT>' : <EOL> if value == '<STR_LIT:true>' : <EOL> self . is_truncated = True <EOL> else : <EOL> self . is_truncated = False <EOL> elif name == '<STR_LIT>' : <EOL> self . initiated = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def get_all_parts ( self , max_parts = None , part_number_marker = None ) : <EOL> """<STR_LIT>""" <EOL> self . _parts = [ ] <EOL> query_args = '<STR_LIT>' % self . id <EOL> if max_parts : <EOL> query_args += '<STR_LIT>' % max_parts <EOL> if part_number_marker : <EOL> query_args += '<STR_LIT>' % part_number_marker <EOL> response = self . bucket . connection . make_request ( '<STR_LIT:GET>' , self . bucket . name , <EOL> self . key_name , <EOL> query_args = query_args ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> h = handler . XmlHandler ( self , self ) <EOL> xml . sax . parseString ( body , h ) <EOL> return self . _parts <EOL> def upload_part_from_file ( self , fp , part_num , headers = None , replace = True , <EOL> cb = None , num_cb = <NUM_LIT:10> , policy = None , md5 = None , <EOL> size = None ) : <EOL> """<STR_LIT>""" <EOL> if part_num < <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> query_args = '<STR_LIT>' % ( self . id , part_num ) <EOL> key = self . bucket . new_key ( self . key_name ) <EOL> key . set_contents_from_file ( fp , headers , replace , cb , num_cb , policy , <EOL> md5 , reduced_redundancy = False , <EOL> query_args = query_args , size = size ) <EOL> def copy_part_from_key ( self , src_bucket_name , src_key_name , part_num , <EOL> start = None , end = None ) : <EOL> """<STR_LIT>""" <EOL> if part_num < <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> query_args = '<STR_LIT>' % ( self . id , part_num ) <EOL> if start is not None and end is not None : <EOL> rng = '<STR_LIT>' % ( start , end ) <EOL> provider = self . bucket . connection . provider <EOL> headers = { provider . copy_source_range_header : rng } <EOL> else : <EOL> headers = None <EOL> return self . bucket . copy_key ( self . key_name , src_bucket_name , <EOL> src_key_name , storage_class = None , <EOL> headers = headers , <EOL> query_args = query_args ) <EOL> def complete_upload ( self ) : <EOL> """<STR_LIT>""" <EOL> xml = self . to_xml ( ) <EOL> return self . bucket . complete_multipart_upload ( self . key_name , <EOL> self . id , xml ) <EOL> def cancel_upload ( self ) : <EOL> """<STR_LIT>""" <EOL> self . bucket . cancel_multipart_upload ( self . key_name , self . id ) </s>
