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: //usr/lib/python3.6/site-packages/s3transfer/__pycache__/upload.cpython-36.pyc
3

\��_vs�@sddlZddlmZddlmZmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	l
mZdd
l
mZddl
mZmZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de
�ZGdd�de	�ZGdd�de	�ZdS)�N)�six)�seekable�readable)�IN_MEMORY_UPLOAD_TAG)�Task)�SubmissionTask)�CreateMultipartUploadTask)�CompleteMultipartUploadTask)�
get_callbacks)�get_filtered_dict)�DeferredOpenFile�ChunksizeAdjusterc@s.eZdZd
dd�Zdd�Zdd�Zd	d
�ZdS)�AggregatedProgressCallbacki�cCs||_||_d|_dS)a�Aggregates progress updates for every provided progress callback

        :type callbacks: A list of functions that accepts bytes_transferred
            as a single argument
        :param callbacks: The callbacks to invoke when threshold is reached

        :type threshold: int
        :param threshold: The progress threshold in which to take the
            aggregated progress and invoke the progress callback with that
            aggregated progress total
        rN)�
_callbacks�
_threshold�_bytes_seen)�self�	callbacks�	threshold�r�/usr/lib/python3.6/upload.py�__init__sz#AggregatedProgressCallback.__init__cCs&|j|7_|j|jkr"|j�dS)N)rr�_trigger_callbacks)r�bytes_transferredrrr�__call__-sz#AggregatedProgressCallback.__call__cCs|jdkr|j�dS)z@Flushes out any progress that has not been sent to its callbacksrN)rr)rrrr�flush2s
z AggregatedProgressCallback.flushcCs&x|jD]}||jd�qWd|_dS)N)rr)rr)r�callbackrrrr7sz-AggregatedProgressCallback._trigger_callbacksN�)r)�__name__�
__module__�__qualname__rrrrrrrrrs
rc@sJeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�InterruptReadera�Wrapper that can interrupt reading using an error

    It uses a transfer coordinator to propagate an error if it notices
    that a read is being made while the file is being read from.

    :type fileobj: file-like obj
    :param fileobj: The file-like object to read from

    :type transfer_coordinator: s3transfer.futures.TransferCoordinator
    :param transfer_coordinator: The transfer coordinator to use if the
        reader needs to be interrupted.
    cCs||_||_dS)N)�_fileobj�_transfer_coordinator)r�fileobj�transfer_coordinatorrrrrJszInterruptReader.__init__NcCs|jjr|jj�|jj|�S)N)r$Z	exceptionr#�read)r�amountrrrr'NszInterruptReader.readcCs|jj|�dS)N)r#�seek)r�whererrrr)XszInterruptReader.seekcCs
|jj�S)N)r#�tell)rrrrr+[szInterruptReader.tellcCs|jj�dS)N)r#�close)rrrrr,^szInterruptReader.closecCs|S)Nr)rrrr�	__enter__aszInterruptReader.__enter__cOs|j�dS)N)r,)r�args�kwargsrrr�__exit__dszInterruptReader.__exit__)N)rr r!�__doc__rr'r)r+r,r-r0rrrrr"=s

r"c@sfeZdZdZddd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�UploadInputManageraJBase manager class for handling various types of files for uploads

    This class is typically used for the UploadSubmissionTask class to help
    determine the following:

        * How to determine the size of the file
        * How to determine if a multipart upload is required
        * How to retrieve the body for a PutObject
        * How to retrieve the bodies for a set of UploadParts

    The answers/implementations differ for the various types of file inputs
    that may be accepted. All implementations must subclass and override
    public methods from this class.
    NcCs||_||_||_dS)N)�_osutilr$�_bandwidth_limiter)r�osutilr&�bandwidth_limiterrrrrwszUploadInputManager.__init__cCstd��dS)aDetermines if the source for the upload is compatible with manager

        :param upload_source: The source for which the upload will pull data
            from.

        :returns: True if the manager can handle the type of source specified
            otherwise returns False.
        zmust implement _is_compatible()N)�NotImplementedError)�cls�
upload_sourcerrr�
is_compatible|s
z UploadInputManager.is_compatiblecCstd��dS)a�Whether the body it provides are stored in-memory

        :type operation_name: str
        :param operation_name: The name of the client operation that the body
            is being used for. Valid operation_names are ``put_object`` and
            ``upload_part``.

        :rtype: boolean
        :returns: True if the body returned by the manager will be stored in
            memory. False if the manager will not directly store the body in
            memory.
        z%must implement store_body_in_memory()N)�NotImplemented)r�operation_namerrr�stores_body_in_memory�s
z(UploadInputManager.stores_body_in_memorycCstd��dS)z�Provides the transfer size of an upload

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The future associated with upload request
        z&must implement provide_transfer_size()N)r7)r�transfer_futurerrr�provide_transfer_size�sz(UploadInputManager.provide_transfer_sizecCstd��dS)a�Determines where a multipart upload is required

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The future associated with upload request

        :type config: s3transfer.manager.TransferConfig
        :param config: The config associated to the transfer manager

        :rtype: boolean
        :returns: True, if the upload should be multipart based on
            configuartion and size. False, otherwise.
        z*must implement requires_multipart_upload()N)r7)rr>�configrrr�requires_multipart_upload�s
z,UploadInputManager.requires_multipart_uploadcCstd��dS)a�Returns the body to use for PutObject

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The future associated with upload request

        :type config: s3transfer.manager.TransferConfig
        :param config: The config associated to the transfer manager

        :rtype: s3transfer.utils.ReadFileChunk
        :returns: A ReadFileChunk including all progress callbacks
            associated with the transfer future.
        z$must implement get_put_object_body()N)r7)rr>rrr�get_put_object_body�s
z&UploadInputManager.get_put_object_bodycCstd��dS)aYields the part number and body to use for each UploadPart

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The future associated with upload request

        :type chunksize: int
        :param chunksize: The chunksize to use for this upload.

        :rtype: int, s3transfer.utils.ReadFileChunk
        :returns: Yields the part number and the ReadFileChunk including all
            progress callbacks associated with the transfer future for that
            specific yielded part.
        z)must implement yield_upload_part_bodies()N)r7)rr>�	chunksizerrr�yield_upload_part_bodies�sz+UploadInputManager.yield_upload_part_bodiescCs*t||j�}|jr&|jj||jdd�}|S)NF)Zenabled)r"r$r4Zget_bandwith_limited_stream)rr%rrr�
_wrap_fileobj�s
z UploadInputManager._wrap_fileobjcCst|d�}|rt|�gSgS)NZprogress)r
r)rr>rrrr�_get_progress_callbacks�s

z*UploadInputManager._get_progress_callbackscCsdd�|D�S)NcSsg|]
}|j�qSr)r)�.0rrrr�
<listcomp>�sz;UploadInputManager._get_close_callbacks.<locals>.<listcomp>r)rZaggregated_progress_callbacksrrr�_get_close_callbacks�sz'UploadInputManager._get_close_callbacks)N)rr r!r1r�classmethodr:r=r?rArBrDrErFrIrrrrr2hs
	r2c@sdeZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�UploadFilenameInputManagerzUpload utility for filenamescCst|tj�S)N)�
isinstancerZstring_types)r8r9rrrr:�sz(UploadFilenameInputManager.is_compatiblecCsdS)NFr)rr<rrrr=�sz0UploadFilenameInputManager.stores_body_in_memorycCs|jj|jj|jjj��dS)N)�metar?r3Z
get_file_size�	call_argsr%)rr>rrrr?�sz0UploadFilenameInputManager.provide_transfer_sizecCs|jj|jkS)N)rM�size�multipart_threshold)rr>r@rrrrA�sz4UploadFilenameInputManager.requires_multipart_uploadcCsJ|j|�\}}|j|�}|j|�}|j|�}|jj}|jj|||||d�S)N)r%�
chunk_size�full_file_sizer�close_callbacks)�&_get_put_object_fileobj_with_full_sizerErFrIrMrOr3�#open_file_chunk_reader_from_fileobj)rr>r%�	full_sizerrSrOrrrrB�s



z.UploadFilenameInputManager.get_put_object_bodyccs�|jj}|j||�}x|td|d�D]j}|j|�}|j|�}||d}|j|jjj|||d�\}	}
|j	|	�}	|j
j|	||
||d�}||fVq$WdS)N�)�
start_byte�	part_sizerR)r%rQrRrrS)rMrO�_get_num_parts�rangerFrI�'_get_upload_part_fileobj_with_full_sizerNr%rEr3rU)rr>rCrRZ	num_parts�part_numberrrSrXr%rVZread_file_chunkrrrrDs



z3UploadFilenameInputManager.yield_upload_part_bodiescCst|||jjd�}|S)N)Z
open_function)rr3�open)rr%rXrrr�_get_deferred_open_filesz2UploadFilenameInputManager._get_deferred_open_filecCs"|jjj}|jj}|j|d�|fS)Nr)rMrNr%rOr_)rr>r%rOrrrrT#s
zAUploadFilenameInputManager._get_put_object_fileobj_with_full_sizecKs |d}|d}|j||�|fS)NrXrR)r_)rr%r/rXrVrrrr\(szBUploadFilenameInputManager._get_upload_part_fileobj_with_full_sizecCsttj|jjt|���S)N)�int�mathZceilrMrO�float)rr>rYrrrrZ-sz)UploadFilenameInputManager._get_num_partsN)rr r!r1rJr:r=r?rArBrDr_rTr\rZrrrrrK�srKc@s<eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�UploadSeekableInputManagerz&Upload utility for an open file objectcCst|�ot|�S)N)rr)r8r9rrrr:4sz(UploadSeekableInputManager.is_compatiblecCs|dkrdSdSdS)N�
put_objectFTr)rr<rrrr=8sz0UploadSeekableInputManager.stores_body_in_memorycCsD|jjj}|j�}|jdd�|j�}|j|�|jj||�dS)Nr�)rMrNr%r+r)r?)rr>r%Zstart_positionZend_positionrrrr?>s

z0UploadSeekableInputManager.provide_transfer_sizecKs |j|d�}tj|�t|�fS)NrY)r'r�BytesIO�len)rr%r/�datarrrr\JszBUploadSeekableInputManager._get_upload_part_fileobj_with_full_sizecCs"|jjj}|j�|jj}||fS)N)rMrNr%r+rO)rr>r%rOrrrrTYs
zAUploadSeekableInputManager._get_put_object_fileobj_with_full_sizeN)
rr r!r1rJr:r=r?r\rTrrrrrc2srccsheZdZdZd�fdd�	Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zdd�Z
�ZS)�UploadNonSeekableInputManagerz7Upload utility for a file-like object that cannot seek.Ncstt|�j|||�d|_dS)N�)�superrir�
_initial_data)rr5r&r6)�	__class__rrrcs

z&UploadNonSeekableInputManager.__init__cCst|�S)N)r)r8r9rrrr:hsz+UploadNonSeekableInputManager.is_compatiblecCsdS)NTr)rr<rrrr=lsz3UploadNonSeekableInputManager.stores_body_in_memorycCsdS)Nr)rr>rrrr?osz3UploadNonSeekableInputManager.provide_transfer_sizecCsT|jjdk	r|jj|jkS|jjj}|j}|j||d�|_t|j�|krLdSdSdS)NFT)rMrOrPrNr%�_readrlrg)rr>r@r%rrrrrAts
z7UploadNonSeekableInputManager.requires_multipart_uploadcCs@|j|�}|j|�}|jjj}|j|j|j�||�}d|_|S)N)rFrIrMrNr%�
_wrap_datarlr')rr>rrSr%�bodyrrrrB�s


z1UploadNonSeekableInputManager.get_put_object_bodyc	csb|jjj}d}xN|j|�}|j|�}|d7}|j||�}|s>P|j|||�}d}||fVqWdS)NrrW)rMrNr%rFrIrnro)	rr>rCZfile_objectr]rrSZpart_contentZpart_objectrrrrD�s



z6UploadNonSeekableInputManager.yield_upload_part_bodiesTcCsxt|j�dkr|j|�S|t|j�krL|jd|�}|rH|j|d�|_|S|t|j�}|j|j|�}|rtd|_|S)a=
        Reads a specific amount of data from a stream and returns it. If there
        is any data in initial_data, that will be popped out first.

        :type fileobj: A file-like object that implements read
        :param fileobj: The stream to read from.

        :type amount: int
        :param amount: The number of bytes to read from the stream.

        :type truncate: bool
        :param truncate: Whether or not to truncate initial_data after
            reading from it.

        :return: Generator which generates part bodies from the initial data.
        rNrj)rgrlr')rr%r(�truncaterhZamount_to_readrrrrn�s
z#UploadNonSeekableInputManager._readcCs.|jtj|��}|jj|t|�t|�||d�S)a�
        Wraps data with the interrupt reader and the file chunk reader.

        :type data: bytes
        :param data: The data to wrap.

        :type callbacks: list
        :param callbacks: The callbacks associated with the transfer future.

        :type close_callbacks: list
        :param close_callbacks: The callbacks to be called when closing the
            wrapper for the data.

        :return: Fully wrapped data.
        )r%rQrRrrS)rErrfr3rUrg)rrhrrSr%rrrro�sz(UploadNonSeekableInputManager._wrap_data)N)T)rr r!r1rrJr:r=r?rArBrDrnro�
__classcell__rr)rmrrias

*ric@s\eZdZdZddddgZdgZdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�UploadSubmissionTaskz.Task for submitting tasks to execute an uploadZSSECustomerKeyZSSECustomerAlgorithmZSSECustomerKeyMD5ZRequestPayercCsHtttg}|jjj}x|D]}|j|�r|SqWtd|t|�f��dS)aoRetrieves a class for managing input for an upload based on file type

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The transfer future for the request

        :rtype: class of UploadInputManager
        :returns: The appropriate class to use for managing a specific type of
            input for uploads.
        z&Input %s of type: %s is not supported.N)	rKrcrirMrNr%r:�RuntimeError�type)rr>Zupload_manager_resolver_chainr%Zupload_manager_clsrrr�_get_upload_input_manager_cls�s


z2UploadSubmissionTask._get_upload_input_manager_clsNcCsd|j|�||j|�}|jjdkr*|j|�|j||�sL|j||||||�n|j||||||�dS)a�
        :param client: The client associated with the transfer manager

        :type config: s3transfer.manager.TransferConfig
        :param config: The transfer config associated with the transfer
            manager

        :type osutil: s3transfer.utils.OSUtil
        :param osutil: The os utility associated to the transfer manager

        :type request_executor: s3transfer.futures.BoundedExecutor
        :param request_executor: The request executor associated with the
            transfer manager

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The transfer future associated with the
            transfer request that tasks are being submitted for
        N)rvr$rMrOr?rA�_submit_upload_request�_submit_multipart_request)r�clientr@r5�request_executorr>r6�upload_input_managerrrr�_submits


zUploadSubmissionTask._submitc	
CsN|jj}|j|d�}|jj|t|j||j|�|j|j|j	d�dd�|d�dS)Nrd)ryr%�bucket�key�
extra_argsT)r&�main_kwargs�is_final)�tag)
rMrN�_get_upload_task_tagr$�submit�
PutObjectTaskrBr}r~r)	rryr@r5rzr>r{rNZput_object_tagrrrrw2sz+UploadSubmissionTask._submit_upload_requestc
Cs|jj}|jj|t|j||j|j|jd�d��}g}	|j|j�}
|j	|d�}|jj
}t�}
|
j|j
|�}|j||�}xJ|D]B\}}|	j|jj|t|j|||j|j||
d�d|id�|d��qzW|j|j�}|jj|t|j||j|j|d�||	d�d	d
��dS)N)ryr}r~r)r&r��upload_part)ryr%r}r~r]r�	upload_id)r&r��pending_main_kwargs)r�)r��partsT)r&r�r�r�)rMrNr$r�rr}r~r�_extra_upload_part_argsr�rOr
Zadjust_chunksizeZmultipart_chunksizerD�append�UploadPartTask�_extra_complete_multipart_argsr	)rryr@r5rzr>r{rNZcreate_multipart_futureZpart_futuresZextra_part_argsZupload_part_tagrOZadjusterrCZ
part_iteratorr]r%Zcomplete_multipart_extra_argsrrrrxLsZ
z.UploadSubmissionTask._submit_multipart_requestcCst||j�S)N)r�UPLOAD_PART_ARGS)rrrrrr��sz,UploadSubmissionTask._extra_upload_part_argscCst||j�S)N)r�COMPLETE_MULTIPART_ARGS)rrrrrr��sz3UploadSubmissionTask._extra_complete_multipart_argscCsd}|j|�rt}|S)N)r=r)rr{r<r�rrrr��s
z)UploadSubmissionTask._get_upload_task_tag)N)
rr r!r1r�r�rvr|rwrxr�r�r�rrrrrs�s
&Mrsc@seZdZdZdd�ZdS)r�z Task to do a nonmultipart uploadc
Cs,|�}|jf|||d�|��WdQRXdS)aP
        :param client: The client to use when calling PutObject
        :param fileobj: The file to upload.
        :param bucket: The name of the bucket to upload to
        :param key: The name of the key to upload to
        :param extra_args: A dictionary of any extra arguments that may be
            used in the upload.
        )�Bucket�Key�BodyN)rd)rryr%r}r~rrprrr�_main�s	zPutObjectTask._mainN)rr r!r1r�rrrrr��sr�c@seZdZdZdd�ZdS)r�z+Task to upload a part in a multipart uploadcCs>|�"}|jf|||||d�|��}	WdQRX|	d}
|
|d�S)a�
        :param client: The client to use when calling PutObject
        :param fileobj: The file to upload.
        :param bucket: The name of the bucket to upload to
        :param key: The name of the key to upload to
        :param upload_id: The id of the upload
        :param part_number: The number representing the part of the multipart
            upload
        :param extra_args: A dictionary of any extra arguments that may be
            used in the upload.

        :rtype: dict
        :returns: A dictionary representing a part::

            {'Etag': etag_value, 'PartNumber': part_number}

            This value can be appended to a list to be used to complete
            the multipart upload.
        )r�r�ZUploadId�
PartNumberr�N�ETag)r�r�)r�)rryr%r}r~r�r]rrpZresponseZetagrrrr��szUploadPartTask._mainN)rr r!r1r�rrrrr��sr�)raZbotocore.compatrZs3transfer.compatrrZs3transfer.futuresrZs3transfer.tasksrrrr	Zs3transfer.utilsr
rrr
�objectrr"r2rKrcrirsr�r�rrrr�<module>
s*!+yQ/D