HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.30
Disabled: passthru,chgrp
Upload Files
File: //lib/python3.9/site-packages/S3/__pycache__/MultiPart.cpython-39.opt-1.pyc
a

�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	dd
�Z
ddd�Zddd�Zddd�Z
dd�Zdd�ZdS)�MultiPartUploadz<Supports MultiPartUpload and MultiPartUpload(Copy) operation�iiPNcCs�||_d|_d|_||_||_i|_|p*i|_t|t�rZ||_|sJt	d��|jj
jt}n||_|jj
j
t}||_|��|_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!�0/usr/lib/python3.9/site-packages/S3/MultiPart.py�__init__s 

zMultiPartUpload.__init__c	CsX|j�||�}t�}|D]:}z"|d|dd�|t|d�<WqtyPYq0q|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}|j�|�}|D]l}zT|d}|d}td||��f�||��krj|rftd|tjd|f��|}Wqty~Yq0q|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�|_nd|_|jsz|jjd|j|jddid�}|j�|�}|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�responser8r!r!r"rWs

�z)MultiPartUpload.initiate_multipart_uploadr-cCsT|jstd��i}|jr$|j��}n|jj}|jjjrF|�	|j
|j�}|rRd|}||j
��d�}d}|j�r�|j}|j|j|j|jo�d}t
d||f�|dk�rz|j|d}t|j||j�}	||	8}d||dt|	d	d
�|f|d<zB|j�r|j|||	||�|�d�n|j|||	||�|�d�Wn:td
||tjd|j
|jtjd|jf��Yn0|d7}q�t
d|d�dSt
d|�|j�|j�}
d}t|
�}	d|dt|	d	d
�|f|d<|
�sڐqBz |j|||	||
|�|�d�Wn:td||tjd|j
|jtjd|jf��Yn0|d7}�q�t
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_namerrr9r,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�|dur�t|d�|kr�t||j|||jjj�}|d�d�}||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�}|d�dd��d�|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.�content-length�%s�Z
partNumber�uploadId�
OBJECT_PUTr5)rJrr6�etagr-)rrr(rrrrZ
send_chunk�striprrr�strr:Z	send_filerC)
rrIrJrrHrKr@r%Zremote_checksumr6�query_string_paramsr<r=r!r!r"rB�sJ
�
���
�����zMultiPartUpload.upload_partc
Cs�td||j|f�dtd|j��|j��fddd�i}d|||df|d	<d
||jd�}|jjd|j||d
�}d|d<|j�	|||�}	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-rangerNrOrQr5zremote copy�actionr8r$r-)rrr
rZbucketr/rr:rZsend_request_with_progressrr)
rrIrJrrHr@r6rUr<r=r!r!r"rD�s2
����	���
�zMultiPartUpload.copy_partc	Cs�td|j�g}d}|j��D]\}}|�|||f�q dd�|�}dtt|��i}|jj	d|j
||d|jid�}|j�|�}|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-rMr4rP)r*r6�bodyr7)rrr�items�append�joinrTrFrr:rr;)	rZ	parts_xmlZpart_xmlrIrRrWr6r<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_upload)NN)r-)r-N)N)�__name__�
__module__�__qualname__�__doc__ZMIN_CHUNK_SIZE_MBZMAX_CHUNK_SIZE_MBZ
MAX_FILE_SIZEr#r,r3rrLrBrDr[r\r!r!r!r"rs"�

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