o ckF[/@sjddlmZddlmZddlmZddlZGdddeZGdddeZ d d d Z Gd d d eZ dS))user)key)handlerNc@2eZdZdZd ddZddZddZd d ZdS) CompleteMultiPartUploada Represents a completed MultiPart Upload. Contains the following useful attributes: * location - The URI of the completed upload * bucket_name - The name of the bucket in which the upload is contained * key_name - The name of the new, completed key * etag - The MD5 hash of the completed, combined upload * version_id - The version_id of the completed upload * encrypted - The value of the encryption header NcCs.||_d|_d|_d|_d|_d|_d|_dSN)bucketlocation bucket_namekey_nameetag version_id encryptedselfrr3/usr/lib/python3/dist-packages/boto/s3/multipart.py__init__-s z CompleteMultiPartUpload.__init__cCsd|j|jfS)Nz )r r rrrr__repr__6sz CompleteMultiPartUpload.__repr__cCdSrrrnameattrs connectionrrr startElement:z$CompleteMultiPartUpload.startElementcCsX|dkr ||_dS|dkr||_dS|dkr||_dS|dkr$||_dSt|||dS)NLocationBucketKeyETag)r r r r setattrrrvaluerrrr endElement=s    z"CompleteMultiPartUpload.endElementr__name__ __module__ __qualname____doc__rrrr$rrrrrs    rc@r) Parta Represents a single part in a MultiPart upload. Attributes include: * part_number - The integer part number * last_modified - The last modified date of this part * etag - The MD5 hash of this part * size - The size, in bytes, of this part NcCs"||_d|_d|_d|_d|_dSr)r part_number last_modifiedr sizerrrrrUs  z Part.__init__cCst|jtr d|jSddS)Nz z ) isinstancer+intrrrrr\s  z Part.__repr__cCrrrrrrrrbrzPart.startElementcCs`|dkr t||_dS|dkr||_dS|dkr||_dS|dkr(t||_dSt|||dS)N PartNumber LastModifiedr Size)r/r+r,r r-r!r"rrrr$es  zPart.endElementrr%rrrrr*Js   r*ccsBd}d}|r|d|}|D]}|Vq|j}|j}|sdSdS)zG A generator function for listing parts of a multipart upload. TN) get_all_partsnext_part_number_marker is_truncated)mpuploadpart_number_marker more_resultspartpartsrrr part_listerrs  r;c@s|eZdZdZdddZddZddZd d Zd d Zd dZ  dddZ  dddZ  dddZ ddZ ddZdS)MultiPartUploadz2 Represents a MultiPart Upload operation. NcCsR||_d|_d|_t|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ dS)NF) rr r id initiatorowner storage_class initiatedr7r4 max_partsr5_partsrrrrrs zMultiPartUpload.__init__cCs d|jS)Nz)r rrrrrs zMultiPartUpload.__repr__cCst|Sr)r;rrrr__iter__szMultiPartUpload.__iter__cCsFd}|D]}|d7}|d|j7}|d|j7}|d7}q|d7}|S)Nz z z %d z %s z z)r+r )rsr9rrrto_xmls zMultiPartUpload.to_xmlcCsZ|dkr t||_|jS|dkrt||_|jS|dkr+t|j}|j||SdS)N InitiatorOwnerr*)rUserr>r?r*rrCappend)rrrrr9rrrrs    zMultiPartUpload.startElementcCs|dkr ||_dS|dkr||_dS|dkr||_dS|dkr$||_dS|dkr-||_dS|dkr6||_dS|dkrAt||_dS|dkrS|d krNd |_dSd |_dS|d kr\||_ dSt |||dS) NrrUploadId StorageClassPartNumberMarkerNextPartNumberMarkerMaxParts IsTruncatedtrueTF Initiated) r r r=r@r7r4r/rBr5rAr!r"rrrr$s*         zMultiPartUpload.endElementcCsg|_d|j}|r|d|7}|r|d|7}|r |d|7}|jjjd|jj|j|d}|}|jdkrGt ||}t j |||jSdS) a@ Return the uploaded parts of this MultiPart Upload. This is a lower-level method that requires you to manually page through results. To simplify this process, you can just use the object itself as an iterator and it will automatically handle all of the paging with S3. z uploadId=%sz &max-parts=%dz&part-number-marker=%sz&encoding-type=%sGET) query_argsN)rCr=rr make_requestrr readstatusr XmlHandlerxmlsax parseString)rrBr7 encoding_typerTresponsebodyhrrrr3s$      zMultiPartUpload.get_all_partsT c CsL|dkrtdd|j|f} |j|j} | j||||||d| |d | S)a_ Upload another part of this MultiPart Upload. .. note:: After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. Only after you either complete or abort multipart upload, Amazon S3 frees up the parts storage and stops charging you for the parts storage. :type fp: file :param fp: The file object you want to upload. :type part_num: int :param part_num: The number of this part. The other parameters are exactly as defined for the :class:`boto.s3.key.Key` set_contents_from_file method. :rtype: :class:`boto.s3.key.Key` or subclass :returns: The uploaded part containing the etag. &Part numbers must be greater than zerouploadId=%s&partNumber=%dF)headersreplacecbnum_cbmd5reduced_redundancyrTr-) ValueErrorr=rnew_keyr set_contents_from_file) rfppart_numrerfrgrhrir-rTrrrrupload_part_from_files z%MultiPartUpload.upload_part_from_filec Cs|dkrtdd|j|f}|dur2|dur2d||f} |jjj} |dur)i}n|}| || j<|jj|j|||d||dS)a Copy another part of this MultiPart Upload. :type src_bucket_name: string :param src_bucket_name: Name of the bucket containing the source key :type src_key_name: string :param src_key_name: Name of the source key :type part_num: int :param part_num: The number of this part. :type start: int :param start: Zero-based byte offset to start copying from :type end: int :param end: Zero-based byte offset to copy to :type src_version_id: string :param src_version_id: version_id of source object to copy from :type headers: dict :param headers: Any headers to pass along in the request rbrcrdNz bytes=%s-%s)src_version_idr@rerT) rkr=rrprovidercopycopy_source_range_headercopy_keyr ) rsrc_bucket_name src_key_namerostartendrqrerTrngrrrrrcopy_part_from_keys"    z"MultiPartUpload.copy_part_from_keycCs|}|j|j|j|S)a. Complete the MultiPart Upload operation. This method should be called when all parts of the file have been successfully uploaded to S3. :rtype: :class:`boto.s3.multipart.CompletedMultiPartUpload` :returns: An object representing the completed upload. )rFrcomplete_multipart_uploadr r=)rrZrrrcomplete_upload4s zMultiPartUpload.complete_uploadcCs|j|j|jdS)a Cancels a MultiPart Upload operation. The storage consumed by any previously uploaded parts will be freed. However, if any part uploads are currently in progress, those part uploads might or might not succeed. As a result, it might be necessary to abort a given multipart upload multiple times in order to completely free all storage consumed by all parts. N)rcancel_multipart_uploadr r=rrrr cancel_uploadAs zMultiPartUpload.cancel_uploadr)NNN)NTNraNN)NNNN)r&r'r(r)rrrDrFrr$r3rpr{r}rrrrrr<s&     $ - r<r) boto.s3rrbotorxml.saxrZobjectrr*r;r<rrrrs   + (