HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/site-packages/s3transfer/__pycache__/__init__.cpython-38.pyc
U

LD�g�s�@spdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZddlmZddlZddlmZmZdZdZGd	d
�d
ej�Ze�e�Ze�e��dZ e!�Z"d%d
d�Z#dd�Z$dd�Z%Gdd�de&�Z'Gdd�d�Z(Gdd�d�Z)Gdd�d�Z*Gdd�d�Z+Gdd�dej,�Z-Gdd �d �Z.Gd!d"�d"�Z/Gd#d$�d$�Z0dS)&a�Abstractions over S3's upload/download operations.

This module provides high level abstractions for efficient
uploads/downloads.  It handles several things for the user:

* Automatically switching to multipart transfers when
  a file is over a specific size threshold
* Uploading/downloading a file in parallel
* Throttling based on max bandwidth
* Progress callbacks to monitor transfers
* Retries.  While botocore handles retries for streaming uploads,
  it is not possible for it to handle retries for streaming
  downloads.  This module handles retries for both cases so
  you don't need to implement any retry logic yourself.

This module has a reasonable set of defaults.  It also allows you
to configure many aspects of the transfer process including:

* Multipart threshold size
* Max parallel downloads
* Max bandwidth
* Socket timeouts
* Retry amounts

There is no support for s3->s3 multipart copies at this
time.


.. _ref_s3transfer_usage:

Usage
=====

The simplest way to use this module is:

.. code-block:: python

    client = boto3.client('s3', 'us-west-2')
    transfer = S3Transfer(client)
    # Upload /tmp/myfile to s3://bucket/key
    transfer.upload_file('/tmp/myfile', 'bucket', 'key')

    # Download s3://bucket/key to /tmp/myfile
    transfer.download_file('bucket', 'key', '/tmp/myfile')

The ``upload_file`` and ``download_file`` methods also accept
``**kwargs``, which will be forwarded through to the corresponding
client operation.  Here are a few examples using ``upload_file``::

    # Making the object public
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         extra_args={'ACL': 'public-read'})

    # Setting metadata
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         extra_args={'Metadata': {'a': 'b', 'c': 'd'}})

    # Setting content type
    transfer.upload_file('/tmp/myfile.json', 'bucket', 'key',
                         extra_args={'ContentType': "application/json"})


The ``S3Transfer`` class also supports progress callbacks so you can
provide transfer progress to users.  Both the ``upload_file`` and
``download_file`` methods take an optional ``callback`` parameter.
Here's an example of how to print a simple progress percentage
to the user:

.. code-block:: python

    class ProgressPercentage(object):
        def __init__(self, filename):
            self._filename = filename
            self._size = float(os.path.getsize(filename))
            self._seen_so_far = 0
            self._lock = threading.Lock()

        def __call__(self, bytes_amount):
            # To simplify we'll assume this is hooked up
            # to a single filename.
            with self._lock:
                self._seen_so_far += bytes_amount
                percentage = (self._seen_so_far / self._size) * 100
                sys.stdout.write(
                    "
%s  %s / %s  (%.2f%%)" % (self._filename, self._seen_so_far,
                                                 self._size, percentage))
                sys.stdout.flush()


    transfer = S3Transfer(boto3.client('s3', 'us-west-2'))
    # Upload /tmp/myfile to s3://bucket/key and print upload progress.
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         callback=ProgressPercentage('/tmp/myfile'))



You can also provide a TransferConfig object to the S3Transfer
object that gives you more fine grained control over the
transfer.  For example:

.. code-block:: python

    client = boto3.client('s3', 'us-west-2')
    config = TransferConfig(
        multipart_threshold=8 * 1024 * 1024,
        max_concurrency=10,
        num_download_attempts=10,
    )
    transfer = S3Transfer(client, config)
    transfer.upload_file('/tmp/foo', 'bucket', 'key')


�N)�six)�IncompleteReadError�ResponseStreamingError)�ReadTimeoutError)�RetriesExceededError�S3UploadFailedErrorzAmazon Web Servicesz0.11.4c@seZdZdd�ZdS)�NullHandlercCsdS�N�)�self�recordr
r
�@/opt/cppython/lib/python3.8/site-packages/s3transfer/__init__.py�emit�szNullHandler.emitN)�__name__�
__module__�__qualname__rr
r
r
r
r�sri�cCsd�dd�t|�D��S)N�css|]}t�tj�VqdSr	)�random�choice�string�	hexdigits)�.0�_r
r
r
�	<genexpr>�sz(random_file_extension.<locals>.<genexpr>)�join�range)Z
num_digitsr
r
r
�random_file_extension�srcKs"|dkrt|jd�r|j��dS)N�Z	PutObjectZ
UploadPart�disable_callback)�hasattr�bodyr��requestZoperation_name�kwargsr
r
r
�disable_upload_callbacks�s

�r%cKs"|dkrt|jd�r|j��dS)Nr�enable_callback)r r!r&r"r
r
r
�enable_upload_callbacks�s

�r'c@seZdZdS)�QueueShutdownErrorN)rrrr
r
r
r
r(�sr(c@s~eZdZddd�Zeddd��Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS) �
ReadFileChunkNTcCsF||_||_|j|j|||d�|_|j�|j�d|_||_||_dS)a�

        Given a file object shown below:

            |___________________________________________________|
            0          |                 |                 full_file_size
                       |----chunk_size---|
                 start_byte

        :type fileobj: file
        :param fileobj: File like object

        :type start_byte: int
        :param start_byte: The first byte from which to start reading.

        :type chunk_size: int
        :param chunk_size: The max chunk size to read.  Trying to read
            pass the end of the chunk size will behave like you've
            reached the end of the file.

        :type full_file_size: int
        :param full_file_size: The entire content length associated
            with ``fileobj``.

        :type callback: function(amount_read)
        :param callback: Called whenever data is read from this object.

        )�requested_size�
start_byte�actual_file_sizerN)�_fileobj�_start_byte�_calculate_file_size�_size�seek�_amount_read�	_callback�_callback_enabled)r�fileobjr+�
chunk_sizeZfull_file_size�callbackr&r
r
r
�__init__�s%�zReadFileChunk.__init__cCs,t|d�}t�|���j}|||||||�S)aWConvenience factory function to create from a filename.

        :type start_byte: int
        :param start_byte: The first byte from which to start reading.

        :type chunk_size: int
        :param chunk_size: The max chunk size to read.  Trying to read
            pass the end of the chunk size will behave like you've
            reached the end of the file.

        :type full_file_size: int
        :param full_file_size: The entire content length associated
            with ``fileobj``.

        :type callback: function(amount_read)
        :param callback: Called whenever data is read from this object.

        :type enable_callback: bool
        :param enable_callback: Indicate whether to invoke callback
            during read() calls.

        :rtype: ``ReadFileChunk``
        :return: A new instance of ``ReadFileChunk``

        �rb)�open�os�fstat�fileno�st_size)�cls�filenamer+r6r7r&�f�	file_sizer
r
r
�
from_filename�s"
�zReadFileChunk.from_filenamecCs||}t||�Sr	)�min)rr5r*r+r,Zmax_chunk_sizer
r
r
r/sz"ReadFileChunk._calculate_file_sizecCsh|dkr|j|j}nt|j|j|�}|j�|�}|jt|�7_|jdk	rd|jrd|�t|��|Sr	)r0r2rDr-�read�lenr3r4)r�amountZamount_to_read�datar
r
r
rEszReadFileChunk.readcCs
d|_dS)NT�r4�rr
r
r
r&%szReadFileChunk.enable_callbackcCs
d|_dS�NFrIrJr
r
r
r(szReadFileChunk.disable_callbackcCs<|j�|j|�|jdk	r2|jr2|�||j�||_dSr	)r-r1r.r3r4r2)r�wherer
r
r
r1+szReadFileChunk.seekcCs|j��dSr	)r-�closerJr
r
r
rM2szReadFileChunk.closecCs|jSr	)r2rJr
r
r
�tell5szReadFileChunk.tellcCs|jSr	)r0rJr
r
r
�__len__8szReadFileChunk.__len__cCs|Sr	r
rJr
r
r
�	__enter__@szReadFileChunk.__enter__cOs|��dSr	)rM)r�argsr$r
r
r
�__exit__CszReadFileChunk.__exit__cCstg�Sr	)�iterrJr
r
r
�__iter__FszReadFileChunk.__iter__)NT)NT)N)rrrr8�classmethodrCr/rEr&rr1rMrNrOrPrRrTr
r
r
r
r)�s$�
2�'
r)c@s"eZdZdZddd�Zdd�ZdS)�StreamReaderProgressz<Wrapper for a read only stream that adds progress callbacks.NcCs||_||_dSr	)�_streamr3)r�streamr7r
r
r
r8RszStreamReaderProgress.__init__cOs*|jj||�}|jdk	r&|�t|��|Sr	)rWrEr3rF)rrQr$�valuer
r
r
rEVs
zStreamReaderProgress.read)N)rrr�__doc__r8rEr
r
r
r
rVOs
rVc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�OSUtilscCstj�|�Sr	)r;�path�getsize�rr@r
r
r
�
get_file_size^szOSUtils.get_file_sizecCstj||||dd�S)NF)r&)r)rC)rr@r+�sizer7r
r
r
�open_file_chunk_readeras�zOSUtils.open_file_chunk_readercCs
t||�Sr	)r:)rr@�moder
r
r
r:fszOSUtils.opencCs(zt�|�Wntk
r"YnXdS)z+Remove a file, noop if file does not exist.N)r;�remove�OSErrorr^r
r
r
�remove_fileiszOSUtils.remove_filecCstj�||�dSr	)�
s3transfer�compat�rename_file)rZcurrent_filenameZnew_filenamer
r
r
rhrszOSUtils.rename_fileN)rrrr_rar:rerhr
r
r
r
r[]s
	r[c@sHeZdZddddgZejjfdd�Zdd�Zd	d
�Z	dd�Z
d
d�ZdS)�MultipartUploader�SSECustomerKey�SSECustomerAlgorithm�SSECustomerKeyMD5�RequestPayercCs||_||_||_||_dSr	)�_client�_config�_os�
_executor_cls�r�client�config�osutilZexecutor_clsr
r
r
r8�szMultipartUploader.__init__cCs,i}|��D]\}}||jkr|||<q|Sr	)�items�UPLOAD_PART_ARGS)r�
extra_argsZupload_parts_args�keyrYr
r
r
�_extra_upload_part_args�s


z)MultipartUploader._extra_upload_part_argsc
Cs�|jjf||d�|��}|d}z|�||||||�}Wn^tk
r�}	z@tjddd�|jj|||d�td�|d�	||g�|	���W5d}	~	XYnX|jj
|||d	|id
�dS)N��Bucket�Key�UploadIdzBException raised while uploading parts, aborting multipart upload.T��exc_info)r|r}r~zFailed to upload {} to {}: {}�/ZParts)r|r}r~ZMultipartUpload)rnZcreate_multipart_upload�
_upload_parts�	Exception�logger�debugZabort_multipart_uploadr�formatrZcomplete_multipart_upload)
rr@�bucketryr7rx�response�	upload_id�parts�er
r
r
�upload_file�sN��������zMultipartUploader.upload_filecCs�|�|�}g}|jj}	tt�|j�|�t|	���}
|jj	}|j
|d��F}t�|j
|||||	||�}
|�|
td|
d��D]}|�|�qzW5QRX|S)N��max_workers�)rzro�multipart_chunksize�int�math�ceilrpr_�float�max_concurrencyrq�	functools�partial�_upload_one_part�mapr�append)rr�r@r�ryr7rxZupload_parts_extra_argsr��	part_size�	num_partsr��executorZupload_partial�partr
r
r
r��s*
��
zMultipartUploader._upload_partsc	

Csf|jj}	|	|||d||��>}
|jjf|||||
d�|��}|d}||d�W5QR�SQRXdS)Nr�)r|r}r~�
PartNumber�Body�ETag)r�r�)rprarnZupload_part)
rr@r�ryr�r�rxr7Zpart_number�open_chunk_readerr!r��etagr
r
r
r��s&
���z"MultipartUploader._upload_one_partN)rrrrw�
concurrent�futures�ThreadPoolExecutorr8rzr�r�r�r
r
r
r
rivs��
	ric@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
ShutdownQueueaYA queue implementation that can be shutdown.

    Shutting down a queue means that this class adds a
    trigger_shutdown method that will trigger all subsequent
    calls to put() to fail with a ``QueueShutdownError``.

    It purposefully deviates from queue.Queue, and is *not* meant
    to be a drop in replacement for ``queue.Queue``.

    cCsd|_t��|_tj�||�SrK)�	_shutdown�	threading�Lock�_shutdown_lock�queue�Queue�_init)r�maxsizer
r
r
r��s
zShutdownQueue._initc	Cs&|j�d|_t�d�W5QRXdS)NTzThe IO queue is now shutdown.)r�r�r�r�rJr
r
r
�trigger_shutdown�szShutdownQueue.trigger_shutdownc	Cs.|j�|jrtd��W5QRXtj�||�S)Nz6Cannot put item to queue when queue has been shutdown.)r�r�r(r�r��put)r�itemr
r
r
r��s�zShutdownQueue.putN)rrrrZr�r�r�r
r
r
r
r��sr�c@sNeZdZejjfdd�Zddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�MultipartDownloadercCs*||_||_||_||_t|jj�|_dSr	)rnrorprqr��max_io_queue�_ioqueuerrr
r
r
r8
s
zMultipartDownloader.__init__Nc
	Csv|jdd��`}t�|j|||||�}|�|�}	t�|j|�}
|�|
�}tjj|	|gtjj	d�}|�
|�W5QRXdS)N�r�)Zreturn_when)rqr�r��_download_file_as_futureZsubmit�_perform_io_writesr�r��waitZFIRST_EXCEPTION�_process_future_results)
rr�ryr@�object_sizerxr7�
controllerZdownload_parts_handlerZparts_futureZio_writes_handlerZ	io_future�resultsr
r
r
�
download_files(�
�
�z!MultipartDownloader.download_filecCs|\}}|D]}|��qdSr	)�result)rr��finished�
unfinished�futurer
r
r
r�1sz+MultipartDownloader._process_future_resultsc	Cs�|jj}tt�|t|���}|jj}t�|j	||||||�}	z0|j
|d��}
t|
�|	t|���W5QRXW5|j
�t�XdS)Nr�)ror�r�r�r�r�r�r�r��_download_ranger�r��SHUTDOWN_SENTINELrq�listr�r)rr�ryr@r�r7r�r�r�Zdownload_partialr�r
r
r
r�6s �	"z,MultipartDownloader._download_file_as_futurecCs:||}||dkrd}n||d}d|�d|��}|S)Nr�rzbytes=�-r
)rr��
part_indexr�Zstart_rangeZ	end_range�range_paramr
r
r
�_calculate_range_paramKsz*MultipartDownloader._calculate_range_paramc
s�z�|�|||�}|jj}	d}
t|	�D]�}zxt�d�|jj|||d�}t|d|��d�||}
t	��fdd�d�D] }|j
�|
|f�|
t|�7}
qvWW�`dSt
jttttfk
r�}z$tjd	|||	d
d�|}
WY�q&W5d}~XYq&Xq&t|
��W5t�d|�XdS)Nz$EXITING _download_range for part: %szMaking get_object call.)r|r}�Ranger�i@cs
����Sr	�rEr
��buffer_size�streaming_bodyr
r
�<lambda>j�z5MultipartDownloader._download_range.<locals>.<lambda>r��CRetrying exception caught (%s), retrying request, (attempt %s / %s)Tr)r�r�r�ro�num_download_attemptsrrn�
get_objectrVrSr�r�rF�socket�timeoutrdrrrr)rr�ryr@r�r�r7r�r��max_attempts�last_exception�ir�Z
current_index�chunkr�r
r�r
r�Ts^�
�����z#MultipartDownloader._download_rangecCs�|j�|d���}|j��}|tkr:t�d�W5QR�dSz |\}}|�|�|�|�Wqt	k
r�}z tjd|dd�|j�
��W5d}~XYqXqW5QRXdS)N�wbzCShutdown sentinel received in IO handler, shutting down IO handler.z!Caught exception in IO thread: %sTr)rpr:r��getr�r�r�r1�writer�r�)rr@rA�task�offsetrHr�r
r
r
r��s&
�
�
z&MultipartDownloader._perform_io_writes)N)
rrrr�r�r�r8r�r�r�r�r�r�r
r
r
r
r�	s�
�
	0r�c@s(eZdZdeddeddfdd�ZdS)�TransferConfigr�
��dcCs"||_||_||_||_||_dSr	)�multipart_thresholdr�r�r�r�)rr�r�r�r�r�r
r
r
r8�s
zTransferConfig.__init__N)rrr�MBr8r
r
r
r
r��s�r�c@s�eZdZdddddgZdddd	d
ddd
dddddddddddddgZd0dd�Zdd�Zd1dd�Zdd�Zd2d d!�Z	d"d#�Z
d$d%�Zd&d'�Zd(d)�Z
d*d+�Zd,d-�Zd.d/�ZdS)3�
S3TransferZ	VersionIdrkrjrlrmZACL�CacheControlZContentDispositionZContentEncodingZContentLanguageZContentTypeZExpiresZGrantFullControlZ	GrantReadZGrantReadACPZ
GrantWriteACLZMetadataZServerSideEncryptionZStorageClassZSSEKMSKeyIdZSSEKMSEncryptionContextZTaggingNcCsF||_|jjj�d|j�|dkr(t�}||_|dkr<t�}||_dS)Nzbefore-call.s3.*)	rn�meta�events�register�_update_checksum_contextr�ror[�_osutil)rrsrtrur
r
r
r8�s
�zS3Transfer.__init__cKs0|�di�}|�di�}d|kr,d|dd<dS)N�contextZchecksumZrequest_algorithm�header�in)r�)r�paramsr$�request_contextZchecksum_contextr
r
r
r��sz#S3Transfer._update_checksum_contextcCs�|dkri}|�||j�|jjj}|jdtdd�|jdtdd�|j	�
|�|jjkrl|�
|||||�n|�|||||�dS)z�Upload a file to an S3 object.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.upload_file() directly.
        Nzrequest-created.s3zs3upload-callback-disable)�	unique_idzs3upload-callback-enable)�_validate_all_known_args�ALLOWED_UPLOAD_ARGSrnr�r�Zregister_firstr%Z
register_lastr'r�r_ror��_multipart_upload�_put_object)rr@r�ryr7rxr�r
r
r
r��s(
��
��zS3Transfer.upload_filec	CsJ|jj}||d|j�|�|d�� }|jjf|||d�|��W5QRXdS)Nr)r7)r|r}r�)r�rar_rnZ
put_object)rr@r�ryr7rxr�r!r
r
r
r��s
���zS3Transfer._put_objectcCs�|dkri}|�||j�|�|||�}|tjt�}z|�||||||�Wn2tk
r�tj	d|dd�|j
�|��YnX|j
�||�dS)z�Download an S3 object to a file.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.download_file() directly.
        Nz<Exception caught in download_file, removing partial file: %sTr)
r��ALLOWED_DOWNLOAD_ARGS�_object_sizer;�extsepr�_download_filer�r�r�r�rerh)rr�ryr@rxr7r�Z
temp_filenamer
r
r
r�
s.��zS3Transfer.download_filecCs8||jjkr"|�||||||�n|�|||||�dSr	)ror��_ranged_download�_get_object)rr�ryr@r�rxr7r
r
r
r�-s�zS3Transfer._download_filecCs0|D]&}||krtd|�dd�|�����qdS)NzInvalid extra_args key 'z', must be one of: z, )�
ValueErrorr)r�actual�allowed�kwargr
r
r
r�7s
�z#S3Transfer._validate_all_known_argscCs*t|j|j|j�}|�||||||�dSr	)r�rnror�r�)rr�ryr@r�rxr7Z
downloaderr
r
r
r�?s��zS3Transfer._ranged_downloadc

Cs�|jj}d}t|�D]l}z|�|||||�WStjtttt	fk
r~}	z$t
jd|	||dd�|	}WY�qW5d}	~	XYqXqt|��dS)Nr�Tr)
ror�r�_do_get_objectr�r�rdrrrr�r�r)
rr�ryr@rxr7r�r�r�r�r
r
r
r�Is8�
�	�zS3Transfer._get_objectc		sf|jjf||d�|��}t|d|��|j�|d��(}t�fdd�d�D]}|�|�qHW5QRXdS)Nr{r�r�cs
��d�S)Ni r�r
�r�r
r
r�mr�z+S3Transfer._do_get_object.<locals>.<lambda>r�)rnr�rVr�r:rSr�)	rr�ryr@rxr7r�rAr�r
rr
rgs��zS3Transfer._do_get_objectcCs|jjf||d�|��dS)Nr{Z
ContentLength)rnZhead_object)rr�ryrxr
r
r
r�ps�zS3Transfer._object_sizecCs(t|j|j|j�}|�|||||�dSr	)rirnror�r�)rr@r�ryr7rxZuploaderr
r
r
r�uszS3Transfer._multipart_upload)NN)NN)NN)rrrr�r�r8r�r�r�r�r�r�r�r�rr�r�r
r
r
r
r��sX�	�
�
�
 

	r�)r)1rZ�concurrent.futuresr�r��loggingr�r;r�rr�rr�Zbotocore.compatrZbotocore.exceptionsrrZ6botocore.vendored.requests.packages.urllib3.exceptionsrZs3transfer.compatrfZs3transfer.exceptionsrr�
__author__�__version__�Handlerr�	getLoggerrr��
addHandlerr��objectr�rr%r'r�r(r)rVr[rir�r�r�r�r�r
r
r
r
�<module>
sHr

q"