HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/lib/python3.6/site-packages/S3/__pycache__/MultiPart.cpython-36.opt-1.pyc
3

�9peQ5�@s�ddlmZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZdd	lmZd
ZGdd�de�ZdS)�)�absolute_importN)�debug�info�warning�error�)�calculateChecksum)�ParameterError)�S3UriS3)�getTextFromXml�getTreeFromXml�s3_quote�
parseNodes)�
formatSizeic@sleZdZdZdZdZdZddd�Zdd�Zd	d
�Z	dd�Z
ddd�Zddd�Zddd�Z
dd�Zdd�ZdS)�MultiPartUploadz<Supports MultiPartUpload and MultiPartUpload(Copy) operation�iNcCs�||_d|_d|_||_||_i|_|p*i|_t|t�rZ||_|sJt	d��|jj
jt}n||_|jj
j
t}||_|j�|_dS)Nz8Source size is missing for MultipartUploadCopy operation)�s3�file_stream�src_uri�src_size�dst_uri�parts�headers_baseline�
isinstancer
r	�configZmultipart_copy_chunk_size_mb�SIZE_1MBZmultipart_chunk_size_mb�
chunk_size�initiate_multipart_upload�	upload_id)�selfr�srcrrrZc_size�r!�/usr/lib/python3.6/MultiPart.py�__init__s 

zMultiPartUpload.__init__cCs^|jj||�}t�}xD|D]<}y"|d|dd�|t|d�<Wqtk
rTYqXqW|S)N�ETagZSize)�checksum�sizeZ
PartNumber)rZlist_multipart�dict�int�KeyError)r�urirZ	part_listr�elemr!r!r"�get_parts_information3s

z%MultiPartUpload.get_parts_informationcCs�d}|jj|�}xv|D]n}yT|d}|d}td||j�f�||j�krl|rhtd|tjd|f��|}Wqtk
r�YqXqW|S)N��UploadIdZKeyzmp_path: %s, object: %sz�More than one UploadId for URI %s.  Disable multipart upload, or use
 %s multipart %s
to list the Ids, then pass a unique --upload-id into the put command.r)rZ
get_multipartr�object�
ValueError�sys�argvr))rr*rZmultipart_listZmpuploadZmp_upload_idZmp_pathr!r!r"�get_unique_upload_idBs 

z$MultiPartUpload.get_unique_upload_idcCs�|jjjr|jjj|_n |jjjr2|j|j�|_nd|_|jsz|jjd|j|jddid�}|jj|�}|d}t	|d�|_|jS)z�
        Begin a multipart upload
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadInitiate.html
        r-�OBJECT_POSTZuploadsN)r*�headers�
uri_params�datar.)
rrr�put_continuer3r�create_requestr�send_requestr)r�request�responser7r!r!r"rWs

z)MultiPartUpload.initiate_multipart_uploadr-cCsZ|jstd��i}|jr$|jj�}n|jj}|jjjrF|j	|j
|j�}|rRd|}||j
j�d�}d}|j�r�|j}|j|j|j|jo�d}t
d||f�x�|dk�r||j|d}t|j||j�}	||	8}d||dt|	d	d
�|f|d<yB|j�r|j|||	||j|�d�n|j|||	||j|�d�Wn:td
||tjd|j
|jtjd|jf��YnX|d7}q�Wt
d|d�dSt
d|�x�|jj|j�}
d}t|
�}	d|dt|	d	d
�|f|d<|
�s�Py |j|||	||
|j|�d�Wn:td||tjd|j
|jtjd|jf��YnX|d7}�q�Wt
d|d�dS)z�
        Execute a full multipart upload on a file
        Returns the seq/etag dict
        TODO use num_processes to thread it
        zAAttempting to use a multipart upload that has not been initiated.� )�sourceZdestinationrz#MultiPart: Uploading %s in %d partsrz[part %d of %d, %s]%sz%d%sBT)Zhuman_readableZextra)�
remote_statusz�
Upload of '%s' part %d failed. Use
  %s abortmp %s %s
to abort the upload, or
  %s --upload-id %s put ...
to continue the upload.z$MultiPart: Upload finished: %d partsNzMultiPart: Uploading from %sz[part %d of -, %s]%szw
Upload of '%s' part %d failed. Use
  %s abortmp %s %s
to abort, or
  %s --upload-id %s put ...
to continue the upload.)rr	rr*rZstream_namerrr8r,rrrr�minr�upload_part�get�	copy_partrr1r2�read�len)rZextra_labelZremote_statuses�filename�labels�seqZ	size_leftZnr_parts�offsetZcurrent_chunk_size�bufferr!r!r"�upload_all_partsms�



z MultiPartUpload.upload_all_partsc
Cs td||j|f�|dk	r�t|d�|kr�t||j|||jjj�}|djd�}||kr~t	d|j
|f�|d|j|<dSt	d|||j
|f�nt	dt|d�||j
|f�d	t|�i}	d
||jd�}
|jj
d|j
|	|
d
�}|jj||j||||d�}|djdd�jd�|j|<|S)z�
        Upload a file chunk
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadUploadPart.html
        z"Uploading part %i of %r (%s bytes)Nr&r%z"'z:MultiPart: size and md5sum match for %s part %d, skipping.zJMultiPart: checksum (%s vs %s) does not match for %s part %d, reuploading.zFMultiPart: size (%d vs %d) does not match for %s part %d, reuploading.zcontent-lengthz%s)�
partNumber�uploadId�
OBJECT_PUT)r*r5r6)rIrr5�etagr-)rrr(rrrrZ
send_chunk�striprrr�strr9Z	send_filerB)
rrHrIrrGrJr?r%Zremote_checksumr5�query_string_paramsr;r<r!r!r"rA�s8





zMultiPartUpload.upload_partc
Cs�td||j|f�dtd|jj�|jj�fddd�i}d|||df|d	<d
||jd�}|jjd|j||d
�}d|d<|jj	|||�}	t
|	dd�p�d|j|<|	S)z�
        Copy a remote file chunk
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadUploadPart.html
        http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadUploadPartCopy.html
        z Copying part %i of %r (%s bytes)zx-amz-copy-sourcez/%s/%sFT)Zquote_backslashesZunicode_outputzbytes=%d-%drzx-amz-copy-source-rangez%s)rLrMrN)r*r5r6zremote copy�actionr7r$r-)rrr
rZbucketr/rr9rZsend_request_with_progressrr)
rrHrIrrGr?r5rRr;r<r!r!r"rC�s"




zMultiPartUpload.copy_partc	Cs�td|j�g}d}x(|jj�D]\}}|j|||f�q"Wddj|�}dtt|��i}|jj	d|j
||d|jid�}|jj|�}|S)	z�
        Finish a multipart upload
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadComplete.html
        z MultiPart: Completing upload: %sz7<Part><PartNumber>%i</PartNumber><ETag>%s</ETag></Part>z5<CompleteMultipartUpload>%s</CompleteMultipartUpload>r-zcontent-lengthr4rM)r*r5�bodyr6)rrr�items�append�joinrQrErr9rr:)	rZ	parts_xmlZpart_xmlrHrOrTr5r;r<r!r!r"�complete_multipart_upload$s
z)MultiPartUpload.complete_multipart_uploadcCstd|j�d}|S)z�
        Abort multipart upload
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadAbort.html
        zMultiPart: Aborting upload: %sN)rr)rr<r!r!r"�abort_upload:szMultiPartUpload.abort_uploadiiiP)NN)r-)r-N)N)�__name__�
__module__�__qualname__�__doc__ZMIN_CHUNK_SIZE_MBZMAX_CHUNK_SIZE_MBZ
MAX_FILE_SIZEr#r,r3rrKrArCrXrYr!r!r!r"rs

`
(
.ri)Z
__future__rr1ZloggingrrrrZCryptorZ
Exceptionsr	ZS3Urir
Z	BaseUtilsrrr
rZUtilsrrr/rr!r!r!r"�<module>s