HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/s3transfer/__pycache__/upload.cpython-310.pyc
o

�h)w�@s�ddlZddlmZddlmZmZddlmZddlm	Z	m
Z
mZmZddl
mZmZmZmZGdd�d�ZGd	d
�d
�ZGdd�d�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�N)�BytesIO��readable�seekable)�IN_MEMORY_UPLOAD_TAG)�CompleteMultipartUploadTask�CreateMultipartUploadTask�SubmissionTask�Task)�ChunksizeAdjuster�DeferredOpenFile�
get_callbacks�get_filtered_dictc@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�AggregatedProgressCallback�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�G/usr/local/CyberPanel/lib/python3.10/site-packages/s3transfer/upload.py�__init__!s
z#AggregatedProgressCallback.__init__cCs*|j|7_|j|jkr|��dSdS�N)rr�_trigger_callbacks)r�bytes_transferredrrr�__call__1s�z#AggregatedProgressCallback.__call__cCs|jdkr|��dSdS)z@Flushes out any progress that has not been sent to its callbacksrN)rr�rrrr�flush6s
�z AggregatedProgressCallback.flushcCs"|jD]}||jd�qd|_dS)N)rr)rr)r�callbackrrrr;s

z-AggregatedProgressCallback._trigger_callbacksN)r)�__name__�
__module__�__qualname__rrrrrrrrr s

rc@sLeZdZdZdd�Zddd�Zddd	�Zd
d�Zdd
�Zdd�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||_||_dSr)�_fileobj�_transfer_coordinator)r�fileobj�transfer_coordinatorrrrrOs
zInterruptReader.__init__NcCs|jjr|jj�|j�|�Sr)r&�	exceptionr%�read)r�amountrrrr*SszInterruptReader.readrcCs|j�||�dSr)r%�seek)r�where�whencerrrr,]szInterruptReader.seekcCs
|j��Sr)r%�tellrrrrr/`s
zInterruptReader.tellcCs|j��dSr)r%�closerrrrr0c�zInterruptReader.closecCs|Srrrrrr�	__enter__f�zInterruptReader.__enter__cOs|��dSr)r0)r�args�kwargsrrr�__exit__i�zInterruptReader.__exit__r)r)r!r"r#�__doc__rr*r,r/r0r2r6rrrrr$As


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||_||_||_dSr)�_osutilr&�_bandwidth_limiter�r�osutilr(�bandwidth_limiterrrrr}s
zUploadInputManager.__init__cC�td��)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()��NotImplementedError��cls�
upload_sourcerrr�
is_compatible�s
z UploadInputManager.is_compatiblecCr?)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()r@�r�operation_namerrr�stores_body_in_memory��
z(UploadInputManager.stores_body_in_memorycCr?)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()r@�r�transfer_futurerrr�provide_transfer_size�sz(UploadInputManager.provide_transfer_sizecCr?)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
            configuration and size. False, otherwise.
        z*must implement requires_multipart_upload()r@�rrK�configrrr�requires_multipart_upload�rIz,UploadInputManager.requires_multipart_uploadcCr?)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()r@rJrrr�get_put_object_body�rIz&UploadInputManager.get_put_object_bodycCr?)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()r@)rrK�	chunksizerrr�yield_upload_part_bodies�sz+UploadInputManager.yield_upload_part_bodiescCs*t||j�}|jr|jj||jdd�}|S)NF)�enabled)r$r&r;�get_bandwith_limited_stream)rr'rrr�
_wrap_fileobj�s�z UploadInputManager._wrap_fileobjcCst|d�}|rt|�gSgS)N�progress)r
r)rrKrrrr�_get_progress_callbacks�s

z*UploadInputManager._get_progress_callbackscCsdd�|D�S)NcSsg|]}|j�qSr)r)�.0r rrr�
<listcomp>�sz;UploadInputManager._get_close_callbacks.<locals>.<listcomp>r)r�aggregated_progress_callbacksrrr�_get_close_callbacks�r1z'UploadInputManager._get_close_callbacksr)r!r"r#r8r�classmethodrErHrLrOrPrRrUrWr[rrrrr9ms

	r9c@sdeZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�UploadFilenameInputManagerzUpload utility for filenamescCs
t|t�Sr)�
isinstance�strrBrrrrE�s
z(UploadFilenameInputManager.is_compatiblecC�dS)NFrrFrrrrH�r3z0UploadFilenameInputManager.stores_body_in_memorycCs|j�|j�|jjj��dSr)�metarLr:�
get_file_size�	call_argsr'rJrrrrL�s�z0UploadFilenameInputManager.provide_transfer_sizecCs|jj|jkSr)ra�size�multipart_thresholdrMrrrrO�r1z4UploadFilenameInputManager.requires_multipart_uploadcCsJ|�|�\}}|�|�}|�|�}|�|�}|jj}|jj|||||d�S)N�r'�
chunk_size�full_file_sizer�close_callbacks)�&_get_put_object_fileobj_with_full_sizerUrWr[rardr:�#open_file_chunk_reader_from_fileobj)rrKr'�	full_sizerrirdrrrrP�s�


�z.UploadFilenameInputManager.get_put_object_bodyccs��|jj}|�||�}td|d�D]5}|�|�}|�|�}||d}|j|jjj|||d�\}	}
|�	|	�}	|j
j|	||
||d�}||fVqdS)N�)�
start_byte�	part_sizerhrf)rard�_get_num_parts�rangerWr[�'_get_upload_part_fileobj_with_full_sizercr'rUr:rk)rrKrQrh�	num_parts�part_numberrrirnr'rl�read_file_chunkrrrrRs.�


�

��z3UploadFilenameInputManager.yield_upload_part_bodiescCst|||jjd�}|S)N)�
open_function)rr:�open)rr'rnrrr�_get_deferred_open_file1s
�z2UploadFilenameInputManager._get_deferred_open_filecCs"|jjj}|jj}|�|d�|fS)Nr)rarcr'rdrx�rrKr'rdrrrrj7s
zAUploadFilenameInputManager._get_put_object_fileobj_with_full_sizecKs |d}|d}|�||�|fS)Nrnrh)rx)rr'r5rnrlrrrrr<szBUploadFilenameInputManager._get_upload_part_fileobj_with_full_sizecCstt�|jjt|���Sr)�int�math�ceilrard�float)rrKrorrrrpAsz)UploadFilenameInputManager._get_num_partsN)r!r"r#r8r\rErHrLrOrPrRrxrjrrrprrrrr]�s
r]c@s<eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�UploadSeekableInputManagerz&Upload utility for an open file objectcCst|�ot|�SrrrBrrrrEHsz(UploadSeekableInputManager.is_compatiblecCs|dkrdSdS)N�
put_objectFTrrFrrrrHLsz0UploadSeekableInputManager.stores_body_in_memorycCsD|jjj}|��}|�dd�|��}|�|�|j�||�dS)Nr�)rarcr'r/r,rL)rrKr'�start_position�end_positionrrrrLRs

�z0UploadSeekableInputManager.provide_transfer_sizecKs|�|d�}t|�t|�fS)Nro)r*r�len)rr'r5�datarrrrr_szBUploadSeekableInputManager._get_upload_part_fileobj_with_full_sizecCs"|jjj}|��|jj}||fSr)rarcr'r/rdryrrrrjns
zAUploadSeekableInputManager._get_put_object_fileobj_with_full_sizeN)
r!r"r#r8r\rErHrLrrrjrrrrr~Es

r~csheZdZdZd�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.Ncst��|||�d|_dS)N�)�superr�
_initial_datar<��	__class__rrrys
z&UploadNonSeekableInputManager.__init__cCst|�Sr)rrBrrrrE}sz+UploadNonSeekableInputManager.is_compatiblecCr`)NTrrFrrrrH�r3z3UploadNonSeekableInputManager.stores_body_in_memorycCsdSrrrJrrrrL�sz3UploadNonSeekableInputManager.provide_transfer_sizecCsP|jjdur
|jj|jkS|jjj}|j}|�||d�|_t|j�|kr&dSdS)NFT)rardrercr'�_readr�r�)rrKrNr'rrrrrO�s
z7UploadNonSeekableInputManager.requires_multipart_uploadcCs@|�|�}|�|�}|jjj}|�|j|��||�}d|_|Sr)rWr[rarcr'�
_wrap_datar�r*)rrKrrir'�bodyrrrrP�s


�z1UploadNonSeekableInputManager.get_put_object_bodyc	cs`�|jjj}d}	|�|�}|�|�}|d7}|�||�}|s!dS|�|||�}d}||fVq	)NrTrm)rarcr'rWr[r�r�)	rrKrQ�file_objectrtrri�part_content�part_objectrrrrR�s �


�
�z6UploadNonSeekableInputManager.yield_upload_part_bodiesTcCsxt|j�dkr|�|�S|t|j�kr&|jd|�}|r$|j|d�|_|S|t|j�}|j|�|�}|r:d|_|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.
        rNr�)r�r�r*)rr'r+�truncater��amount_to_readrrrr��s
z#UploadNonSeekableInputManager._readcCs,|�t|��}|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.
        rf)rUrr:rkr�)rr�rrir'rrrr��s�z(UploadNonSeekableInputManager._wrap_datar)T)r!r"r#r8rr\rErHrLrOrPrRr�r��
__classcell__rrr�rr�vs

*r�c@s\eZdZdZgd�Zgd�Zdd�Z	ddd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�UploadSubmissionTaskz.Task for submitting tasks to execute an upload)�ChecksumAlgorithm�SSECustomerKey�SSECustomerAlgorithm�SSECustomerKeyMD5�RequestPayer�ExpectedBucketOwner)r�r�r�r�r�cCsDtttg}|jjj}|D]}|�|�r|Sqtd�|t	|����)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 {} of type: {} is not supported.)
r]r~r�rarcr'rE�RuntimeError�format�type)rrK�upload_manager_resolver_chainr'�upload_manager_clsrrr�_get_upload_input_manager_clss�

���z2UploadSubmissionTask._get_upload_input_manager_clsNcCsf|�|�||j|�}|jjdur|�|�|�||�s'|�||||||�dS|�||||||�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)r�r&rardrLrO�_submit_upload_request�_submit_multipart_request)r�clientrNr=�request_executorrKr>�upload_input_managerrrr�_submit.s4��
��	�zUploadSubmissionTask._submitc	
CsN|jj}|�|d�}|jj|t|j||�|�|j|j|j	d�dd�|d�dS)Nr)r�r'�bucket�key�
extra_argsT)r(�main_kwargs�is_final��tag)
rarc�_get_upload_task_tagr&�submit�
PutObjectTaskrPr�r�r�)	rr�rNr=r�rKr�rc�put_object_tagrrrr�gs(	���	�
�z+UploadSubmissionTask._submit_upload_requestcCs�|jj}|j�|t|j||j|j|jd�d��}g}	|�|j�}
|�	|d�}|jj
}t�}
|
�|j
|�}|�||�}|D]!\}}|	�|jj|t|j|||j|j||
d�d|id�|d��q<|�|j�}|j�|t|j||j|j|d�||	d�d	d
��dS)N)r�r�r�r�)r(r��upload_part)r�r'r�r�rtr��	upload_id)r(r��pending_main_kwargsr�)r��partsT)r(r�r�r�)rarcr&r�rr�r�r��_extra_upload_part_argsr�rdr�adjust_chunksize�multipart_chunksizerR�append�UploadPartTask�_extra_complete_multipart_argsr)rr�rNr=r�rKr�rc�create_multipart_future�part_futures�extra_part_args�upload_part_tagrd�adjusterrQ�
part_iteratorrtr'�complete_multipart_extra_argsrrrr��sx	������	���������z.UploadSubmissionTask._submit_multipart_requestcC�t||j�Sr)r�UPLOAD_PART_ARGS�rr�rrrr��sz,UploadSubmissionTask._extra_upload_part_argscCr�r)r�COMPLETE_MULTIPART_ARGSr�rrrr��r7z3UploadSubmissionTask._extra_complete_multipart_argscCsd}|�|�r	t}|Sr)rHr)rr�rGr�rrrr��s
z)UploadSubmissionTask._get_upload_task_tagr)
r!r"r#r8r�r�r�r�r�r�r�r�r�rrrrr�s	!
�9#Vr�c@�eZdZdZdd�ZdS)r�z Task to do a nonmultipart uploadcCsB|�}|jd|||d�|��Wd�dS1swYdS)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�BodyNr)r)rr�r'r�r�r�r�rrr�_main�s	"�zPutObjectTask._mainN�r!r"r#r8r�rrrrr���r�c@r�)r�z+Task to upload a part in a multipart uploadc	Cs�|�}|jd|||||d�|��}	Wd�n1swY|	d}
|
|d�}d|vrB|d��}d|��}
|
|	vrB|	|
||
<|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��UploadId�
PartNumberr�N�ETag)r�r�r��Checksumr)r��upper)rr�r'r�r�r�rtr�r��response�etag�
part_metadata�algorithm_name�checksum_memberrrrr�s&���	

zUploadPartTask._mainNr�rrrrr��r�r�)r{�ior�s3transfer.compatrr�s3transfer.futuresr�s3transfer.tasksrrr	r
�s3transfer.utilsrrr
rrr$r9r]r~r�r�r�r�rrrr�<module>s"!,{]1p