HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/awscli/customizations/__pycache__/s3uploader.cpython-36.pyc
3

�T_j�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZej
e�ZGdd�de�ZGdd�de�ZGd	d
�d
e
�ZdS)�N)�TransferManager)�BaseSubscriber)�collections_abcc@seZdZdd�ZdZdS)�NoSuchBucketErrorcKs$|jjf|�}tj||�||_dS)N)�fmt�format�	Exception�__init__�kwargs)�selfr
�msg�r
� /usr/lib/python3.6/s3uploader.pyr	szNoSuchBucketError.__init__zaS3 Bucket does not exist. Execute the command to create a new bucket
aws s3 mb s3://{bucket_name}N)�__name__�
__module__�__qualname__r	rr
r
r
rrsrc@sheZdZdZedd��Zejdd��Zddd�Zd	d
�Zddd�Z	d
d�Z
dd�Zdd�Zddd�Z
dS)�
S3Uploaderz�
    Class to upload objects to S3 bucket that use versioning. If bucket
    does not already use versioning, this class will turn on versioning.
    cCs|jS)zO
        Metadata to attach to the object(s) uploaded by the uploader.
        )�_artifact_metadata)rr
r
r�artifact_metadata1szS3Uploader.artifact_metadatacCs(|dk	rt|tj�rtd��||_dS)Nz(Artifact metadata should be in dict type)�
isinstancer�Mapping�	TypeErrorr)r�valr
r
rr8sNFcCsB||_||_|pd|_||_||_||_|s8t|j�|_d|_dS)N)�bucket_name�prefix�
kms_key_id�force_upload�s3�transfer_managerrr)rZ	s3_clientrrrrrr
r
rr	>s
zS3Uploader.__init__cCs|jr"t|j�dkr"dj|j|�}|jrN|j|�rNtjdj|��|j|�Sydddi}|jrpd|d<|j|d<|j	r�|j	|d<t
||�}|jj||j
|||g�}|j�|j|�Stjjk
�r}z,|jd	d
}|dkr�t|j
d��|�WYd
d
}~XnXd
S)z�
        Uploads given file to S3
        :param file_name: Path to the file that will be uploaded
        :param remote_path:  be uploaded
        :return: VersionId of the latest upload
        rz{0}/{1}z:File with same data already exists at {0}. Skipping uploadZServerSideEncryptionZAES256zaws:kmsZSSEKMSKeyIdZMetadata�ErrorZCodeZNoSuchBucket)rN)r�lenrr�file_exists�LOG�debug�make_urlrr�ProgressPercentager�uploadr�result�botocore�
exceptions�ClientErrorZresponser)r�	file_name�remote_pathZadditional_argsZprint_progress_callback�futureZexZ
error_coder
r
rr&Ps4




zS3Uploader.uploadcCs*|j|�}|}|r|d|}|j||�S)z�
        Makes and returns name of the S3 object based on the file's MD5 sum

        :param file_name: file to upload
        :param extension: String of file extension to append to the object
        :return: S3 URL of the uploaded object
        �.)�
file_checksumr&)rr+�	extensionZfilemd5r,r
r
r�upload_with_dedup�s

zS3Uploader.upload_with_dedupcCs4y|jj|j|d�dStjjk
r.dSXdS)z�
        Check if the file we are trying to upload already exists in S3

        :param remote_path:
        :return: True, if file exists. False, otherwise
        )ZBucketZKeyTFN)rZhead_objectrr(r)r*)rr,r
r
rr!�szS3Uploader.file_existscCsdj|j|�S)Nzs3://{0}/{1})rr)rZobj_pathr
r
rr$�szS3Uploader.make_urlc	Csvt|d��b}tj�}d}|j�}|jd�|j|�}x$t|�dkrX|j|�|j|�}q6W|j|�|j�SQRXdS)N�rbir)	�open�hashlib�md5�tell�seek�readr �updateZ	hexdigest)rr+Zfile_handler5Z
block_sizeZcurposZbufr
r
rr/�s



zS3Uploader.file_checksumcCs.|jjj}dj||j|�}|r*dj||�}|S)z�
            This link describes the format of Path Style URLs
            http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
        z{0}/{1}/{2}z{0}?versionId={1})r�metaZendpoint_urlrr)r�key�version�baser'r
r
r�to_path_style_s3_url�s

zS3Uploader.to_path_style_s3_url)NNFN)N)N)rrr�__doc__�propertyr�setterr	r&r1r!r$r/r>r
r
r
rr+s

1
rc@seZdZdd�Zdd�ZdS)r%cCs2||_||_ttjj|��|_d|_tj	�|_
dS)Nr)Z	_filename�_remote_path�float�os�path�getsize�_size�_seen_so_far�	threadingZLock�_lock)r�filenamer,r
r
rr	�s
zProgressPercentage.__init__c
Ks\|j�L|j|7_|j|jd}tjjd|j|j|j|f�tjj�WdQRXdS)N�dz#
Uploading to %s  %s / %s  (%.2f%%))rJrHrG�sys�stdout�writerB�flush)rr-Zbytes_transferredr
Z
percentager
r
r�on_progress�szProgressPercentage.on_progressN)rrrr	rQr
r
r
rr%�sr%)r4ZloggingrIrDrMr(Zbotocore.exceptionsZs3transfer.managerrZs3transfer.subscribersrZ
awscli.compatrZ	getLoggerrr"rr�objectrr%r
r
r
r�<module>s

$