https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/s3transfer/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/s3transfer/__pycache__/upload.cpython-310.pyc
o

�y�`�s�@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.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�3/usr/lib/python3/dist-packages/s3transfer/upload.py�__init__s
z#AggregatedProgressCallback.__init__cCs*|j|7_|j|jkr|��dSdS�N)rr�_trigger_callbacks)r�bytes_transferredrrr�__call__-s�z#AggregatedProgressCallback.__call__cCs|jdkr|��dSdS)z@Flushes out any progress that has not been sent to its callbacksrN)rr�rrrr�flush2s
�z AggregatedProgressCallback.flushcCs"|jD]}||jd�qd|_dS)N)rr)rr)r�callbackrrrr7s

z-AggregatedProgressCallback._trigger_callbacksN)r)�__name__�
__module__�__qualname__rrrrrrrrrs

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_coordinatorrrrrJs
zInterruptReader.__init__NcCs|jjr|jj�|j�|�Sr)r%�	exceptionr$�read)r�amountrrrr)NszInterruptReader.readrcCs|j�||�dSr)r$�seek)r�where�whencerrrr+XszInterruptReader.seekcCs
|j��Sr)r$�tellrrrrr.[s
zInterruptReader.tellcCs|j��dSr)r$�closerrrrr/^�zInterruptReader.closecCs|Srrrrrr�	__enter__a�zInterruptReader.__enter__cOs|��dSr)r/)r�args�kwargsrrr�__exit__d�zInterruptReader.__exit__r)r)r r!r"�__doc__rr)r+r.r/r1r5rrrrr#=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||_||_||_dSr)�_osutilr%�_bandwidth_limiter�r�osutilr'�bandwidth_limiterrrrrws
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())�NotImplemented�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
            configuartion 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)�.0rrrr�
<listcomp>�sz;UploadInputManager._get_close_callbacks.<locals>.<listcomp>r)r�aggregated_progress_callbacksrrr�_get_close_callbacks�r0z'UploadInputManager._get_close_callbacksr)r r!r"r7r�classmethodrDrHrLrOrPrRrUrWr[rrrrr8hs

	r8c@sdeZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�UploadFilenameInputManagerzUpload utility for filenamescCst|tj�Sr)�
isinstancer�string_typesrArrrrD�sz(UploadFilenameInputManager.is_compatiblecC�dS)NFrrFrrrrH�r2z0UploadFilenameInputManager.stores_body_in_memorycCs|j�|j�|jjj��dSr)�metarLr9�
get_file_size�	call_argsr&rJrrrrL�s
��z0UploadFilenameInputManager.provide_transfer_sizecCs|jj|jkSr)ra�size�multipart_thresholdrMrrrrO�r0z4UploadFilenameInputManager.requires_multipart_uploadcCsJ|�|�\}}|�|�}|�|�}|�|�}|jj}|jj|||||d�S)N�r&�
chunk_size�full_file_sizer�close_callbacks)�&_get_put_object_fileobj_with_full_sizerUrWr[rardr9�#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&rUr9rk)rrKrQrh�	num_parts�part_numberrrirnr&rl�read_file_chunkrrrrRs&�



�
��z3UploadFilenameInputManager.yield_upload_part_bodiescCst|||jjd�}|S)N)�
open_function)rr9�open)rr&rnrrr�_get_deferred_open_files
�z2UploadFilenameInputManager._get_deferred_open_filecCs"|jjj}|jj}|�|d�|fS)Nr)rarcr&rdrx�rrKr&rdrrrrj#s
zAUploadFilenameInputManager._get_put_object_fileobj_with_full_sizecKs |d}|d}|�||�|fS)Nrnrh)rx)rr&r4rnrlrrrrr(szBUploadFilenameInputManager._get_upload_part_fileobj_with_full_sizecCstt�|jjt|���Sr)�int�math�ceilrard�float)rrKrorrrrp-s�z)UploadFilenameInputManager._get_num_partsN)r r!r"r7r\rDrHrLrOrPrRrxrjrrrprrrrr]�s
r]c@s<eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�UploadSeekableInputManagerz&Upload utility for an open file objectcCst|�ot|�Sr)rrrArrrrD4sz(UploadSeekableInputManager.is_compatiblecCs|dkrdSdS)N�
put_objectFTrrFrrrrH8sz0UploadSeekableInputManager.stores_body_in_memorycCsD|jjj}|��}|�dd�|��}|�|�|j�||�dS)Nr�)rarcr&r.r+rL)rrKr&�start_position�end_positionrrrrL>s

�z0UploadSeekableInputManager.provide_transfer_sizecKs |�|d�}t�|�t|�fS)Nro)r)r�BytesIO�len)rr&r4�datarrrrrJszBUploadSeekableInputManager._get_upload_part_fileobj_with_full_sizecCs"|jjj}|��|jj}||fSr)rarcr&r.rdryrrrrjYs
zAUploadSeekableInputManager._get_put_object_fileobj_with_full_sizeN)
r r!r"r7r\rDrHrLrrrjrrrrr~2s
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.Ncstt|��|||�d|_dS)N�)�superr�r�
_initial_datar;��	__class__rrrcs
�
z&UploadNonSeekableInputManager.__init__cCst|�Sr)rrArrrrDhsz+UploadNonSeekableInputManager.is_compatiblecCr`)NTrrFrrrrHlr2z3UploadNonSeekableInputManager.stores_body_in_memorycCsdSrrrJrrrrLosz3UploadNonSeekableInputManager.provide_transfer_sizecCsP|jjdur
|jj|jkS|jjj}|j}|�||d�|_t|j�|kr&dSdS)NFT)rardrercr&�_readr�r�)rrKrNr&rrrrrOts
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�r9rkr�)rr�rrir&rrrr��s
�z(UploadNonSeekableInputManager._wrap_datar)T)r r!r"r7rr\rDrHrLrOrPrRr�r��
__classcell__rrr�rr�as

*r�c@s\eZdZdZgd�ZddgZdd�Z	ddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�UploadSubmissionTaskz.Task for submitting tasks to execute an upload)�SSECustomerKey�SSECustomerAlgorithm�SSECustomerKeyMD5�RequestPayer�ExpectedBucketOwnerr�r�cCsDtttg}|jjj}|D]}|�|�r|Sqtd|t|�f��)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.)	r]r~r�rarcr&rD�RuntimeError�type)rrK�upload_manager_resolver_chainr&�upload_manager_clsrrr�_get_upload_input_manager_cls�s�

���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
s$��
�
�
�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�4s(����
�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�Nsx������	���������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��r6z3UploadSubmissionTask._extra_complete_multipart_argscCsd}|�|�r	t}|Sr)rHr)rr�rGr�rrrr��s
z)UploadSubmissionTask._get_upload_task_tagr)
r r!r"r7r�r�r�r�r�r�r�r�r�rrrrr��s	�
�'M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"r7r�rrrrr���r�c@r�)r�z+Task to upload a part in a multipart uploadc	CsR|�}|jd|||||d�|��}	Wd�n1swY|	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��UploadId�
PartNumberr�N�ETag)r�r�r)r�)rr�r&r�r�r�rtr�r��response�etagrrrr��s���
zUploadPartTask._mainNr�rrrrr��r�r�)r{�botocore.compatr�s3transfer.compatrr�s3transfer.futuresr�s3transfer.tasksrrrr	�s3transfer.utilsr
rrr
�objectrr#r8r]r~r�r�r�r�rrrr�<module>s,!+yQ/F

https://t.me/RX1948 - 2025