HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/customizations/__pycache__/s3uploader.cpython-38.pyc
U

<�^j�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZe�
e�ZGdd�de�ZGdd�de�ZGd	d
�d
e
�ZdS)�N)�TransferManager)�BaseSubscriber)�collections_abcc@seZdZdd�ZdZdS)�NoSuchBucketErrorcKs$|jjf|�}t�||�||_dS�N)�fmt�format�	Exception�__init__�kwargs)�selfr�msg�r�B/usr/lib/python3/dist-packages/awscli/customizations/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
rrrrrrsrc@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)rrrr�artifact_metadata1szS3Uploader.artifact_metadatacCs&|dk	rt|tj�std��||_dS)Nz(Artifact metadata should be in dict type)�
isinstancer�Mapping�	TypeErrorr)r�valrrrr8sNFcCsB||_||_|pd|_||_||_||_|s8t|j�|_d|_dSr)�bucket_name�prefix�
kms_key_id�force_upload�s3�transfer_managerrr)rZ	s3_clientrrrrrrrrr
>s
zS3Uploader.__init__c
Cs|jr"t|j�dkr"d�|j|�}|jsL|�|�rLt�d�|��|�|�Szfddi}|jrnd|d<|j|d<|j	r~|j	|d<t
||�}|j�||j
|||g�}|��|�|�WStjjk
�r}z*|jd	d
}|dkr�t|j
d��|�W5d
}~XYnXd
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�future�exZ
error_coderrrr'Ps>�
�

��zS3Uploader.uploadcCs*|�|�}|}|r|d|}|�||�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')rr,�	extensionZfilemd5r-rrr�upload_with_dedup�s

zS3Uploader.upload_with_dedupcCs8z|jj|j|d�WdStjjk
r2YdSXdS)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+)rr-rrrr"�s�zS3Uploader.file_existscCsd�|j|�S)Nzs3://{0}/{1})rr)rZobj_pathrrrr%�s�zS3Uploader.make_urlc
Cs~t|d��j}t��}d}|��}|�d�|�|�}t|�dkrV|�|�|�|�}q4|�|�|��W5QR�SQRXdS)N�rbir)	�open�hashlib�md5�tell�seek�readr!�updateZ	hexdigest)rr,Zfile_handler7Z
block_sizeZcurposZbufrrrr1�s



zS3Uploader.file_checksumcCs.|jjj}d�||j|�}|r*d�||�}|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(rrr�to_path_style_s3_url�s

zS3Uploader.to_path_style_s3_url)NNFN)N)N)rrr�__doc__�propertyr�setterr
r'r3r"r%r1r@rrrrr+s 

�
1
rc@seZdZdd�Zdd�ZdS)r&cCs2||_||_ttj�|��|_d|_t�	�|_
dS)Nr)Z	_filename�_remote_path�float�os�path�getsize�_size�_seen_so_far�	threadingZLock�_lock)r�filenamer-rrrr
�s
zProgressPercentage.__init__c	Ks\|j�L|j|7_|j|jd}tj�d|j|j|j|f�tj��W5QRXdS)N�dz#
Uploading to %s  %s / %s  (%.2f%%))rLrJrI�sys�stdout�writerD�flush)rr.Zbytes_transferredrZ
percentagerrr�on_progress�s���zProgressPercentage.on_progressN)rrrr
rSrrrrr&�sr&)r6ZloggingrKrFrOr)Zbotocore.exceptionsZs3transfer.managerrZs3transfer.subscribersrZ
awscli.compatrZ	getLoggerrr#r	r�objectrr&rrrr�<module>s

$