Current File : //proc/353637/cwd/lib/python3/dist-packages/s3transfer/__pycache__/futures.cpython-312.pyc
�

�<�e�R���ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZddl
mZmZej e�ZGd�d�ZGd	�d
�ZGd�de�ZGd
�de�ZGd�d�ZGd�d�ZGd�d�ZGd�d�ZGd�de�ZGd�d�Zeddg�Zed�Zed�Zy)�N)�
namedtuple)�futures)�MAXINT)�CancelledError�TransferNotDoneError)�FunctionContainer�
TaskSemaphorec�.�eZdZed��Zd�Zd�Zd�Zy)�BaseTransferFuturec��td��)z-The metadata associated to the TransferFuture�meta��NotImplementedError��selfs �4/usr/lib/python3/dist-packages/s3transfer/futures.pyr
zBaseTransferFuture.metas��"�&�)�)�c��td��)zmDetermines if a TransferFuture has completed

        :returns: True if completed. False, otherwise.
        zdone()rrs r�donezBaseTransferFuture.done!s��
"�(�+�+rc��td��)��Waits until TransferFuture is done and returns the result

        If the TransferFuture succeeded, it will return the result. If the
        TransferFuture failed, it will raise the exception associated to the
        failure.
        zresult()rrs r�resultzBaseTransferFuture.result(s��"�*�-�-rc��td��)z6Cancels the request associated with the TransferFuturezcancel()rrs r�cancelzBaseTransferFuture.cancel1s
��!�*�-�-rN)�__name__�
__module__�__qualname__�propertyr
rrr�rrrrs#��
�*��*�,�.�.rrc�<�eZdZed��Zed��Zed��Zy)�BaseTransferMetac��td��)�*The call args used in the transfer request�	call_argsrrs rr$zBaseTransferMeta.call_args7s��"�+�.�.rc��td��)�The unique id of the transfer�transfer_idrrs rr'zBaseTransferMeta.transfer_id<s��"�-�0�0rc��td��)�.A dictionary that requesters can store data in�user_contextrrs rr*zBaseTransferMeta.user_contextAs��"�.�1�1rN)rrrrr$r'r*rrrr!r!6s<��
�/��/��1��1��2��2rr!c�<�eZdZdd�Zed��Zd�Zd�Zd�Zd�Z	y)	�TransferFutureNc�f�||_|�t�|_||_|�t�|_yy)a�The future associated to a submitted transfer request

        :type meta: TransferMeta
        :param meta: The metadata associated to the request. This object
            is visible to the requester.

        :type coordinator: TransferCoordinator
        :param coordinator: The coordinator associated to the request. This
            object is not visible to the requester.
        N)�_meta�TransferMeta�_coordinator�TransferCoordinator)rr
�coordinators   r�__init__zTransferFuture.__init__Hs7����
��<�%��D�J�'����� 3� 5�D��rc��|jS�N)r.rs rr
zTransferFuture.meta[s���z�z�rc�6�|jj�Sr5)r0rrs rrzTransferFuture.done_s��� � �%�%�'�'rc�~�	|jj�S#t$r}|j�|�d}~wwxYwr5)r0r�KeyboardInterruptr)r�es  rrzTransferFuture.resultbs<��	��$�$�+�+�-�-�� �	��K�K�M��G��	�s��	<�7�<c�8�|jj�yr5)r0rrs rrzTransferFuture.cancells����� � �"rc�t�|j�std��|jj|d��y)z!Sets the exception on the future.z?set_exception can only be called once the transfer is complete.T)�overrideN)rrr0�
set_exception)r�	exceptions  rr=zTransferFuture.set_exceptionos8���y�y�{�&���
�	
���'�'�	�D�'�Ar�NN)
rrrr3rr
rrrr=rrrr,r,Gs0��6�&����(��#�Brr,c�^�eZdZdZd	d�Zed��Zed��Zed��Zed��Z	d�Z
y)
r/z'Holds metadata about the TransferFutureNc�<�||_||_d|_i|_yr5)�
_call_args�_transfer_id�_size�
_user_context)rr$r's   rr3zTransferMeta.__init__|s ��#���'�����
���rc��|jS)r#)rBrs rr$zTransferMeta.call_args�s�����rc��|jS)r&)rCrs rr'zTransferMeta.transfer_id�s��� � � rc��|jS)z)The size of the transfer request if known�rDrs r�sizezTransferMeta.size�s���z�z�rc��|jS)r))rErs rr*zTransferMeta.user_context�s���!�!�!rc��||_y)z�A method to provide the size of a transfer request

        By providing this value, the TransferManager will not try to
        call HeadObject or use the use OS to determine the size of the
        transfer.
        NrI)rrJs  r�provide_transfer_sizez"TransferMeta.provide_transfer_size�s����
rr?)rrr�__doc__r3rr$r'rJr*rMrrrr/r/ys_��1� ������!��!������"��"�rr/c���eZdZdZdd�Zd�Zed��Zed��Zed��Z	ed��Z
d	�Zdd
�Zd�Z
defd
�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)r1z*A helper class for managing TransferFutureNc�p�||_d|_d|_d|_t	�|_g|_g|_tj�|_
tj�|_tj�|_
tj�|_tj�|_y)N�not-started)r'�_status�_result�
_exception�set�_associated_futures�_failure_cleanups�_done_callbacks�	threading�Event�_done_event�Lock�_lock�_associated_futures_lock�_done_callbacks_lock�_failure_cleanups_lock)rr's  rr3zTransferCoordinator.__init__�s���&���$���������#&�5�� �!#���!���$�?�?�,����^�^�%��
�(1���(8��%�$-�N�N�$4��!�&/�n�n�&6��#rc�b�dj|jj|j�S)Nz{}(transfer_id={}))�format�	__class__rr'rs r�__repr__zTransferCoordinator.__repr__�s*��#�*�*��N�N�#�#�T�%5�%5�
�	
rc��|jSr5)rTrs rr>zTransferCoordinator.exception�s�����rc��|j5tj|j�cddd�S#1swYyxYw)z�The list of futures associated to the inprogress TransferFuture

        Once the transfer finishes this list becomes empty as the transfer
        is considered done and there should be no running futures left.
        N)r^�copyrVrs r�associated_futuresz&TransferCoordinator.associated_futures�s6���
*�
*�	7��9�9�T�5�5�6�		7�	7�	7�s�6�?c��|jS)z;The list of callbacks to call when the TransferFuture fails)rWrs r�failure_cleanupsz$TransferCoordinator.failure_cleanups�s���%�%�%rc��|jS)a�The status of the TransferFuture

        The currently supported states are:
            * not-started - Has yet to start. If in this state, a transfer
              can be canceled immediately and nothing will happen.
            * queued - SubmissionTask is about to submit tasks
            * running - Is inprogress. In-progress as of now means that
              the SubmissionTask that runs the transfer is being executed. So
              there is no guarantee any transfer requests had been made to
              S3 if this state is reached.
            * cancelled - Was cancelled
            * failed - An exception other than CancelledError was thrown
            * success - No exceptions were thrown and is done.
        )rRrs r�statuszTransferCoordinator.status�s�� �|�|�rc�p�|j5d|_||_d|_ddd�y#1swYyxYw)a�Set a result for the TransferFuture

        Implies that the TransferFuture succeeded. This will always set a
        result because it is invoked on the final task where there is only
        ever one final task and it is ran at the very end of a transfer
        process. So if a result is being set for this final task, the transfer
        succeeded even if something came a long and canceled the transfer
        on the final task.
        N�success)r]rTrSrR�rrs  r�
set_resultzTransferCoordinator.set_result�s5���Z�Z�	%�"�D�O�!�D�L�$�D�L�	%�	%�	%�s�,�5c��|j5|j�r|r||_d|_ddd�y#1swYyxYw)z�Set an exception for the TransferFuture

        Implies the TransferFuture failed.

        :param exception: The exception that cause the transfer to fail.
        :param override: If True, override any existing state.
        �failedN)r]rrTrR)rr>r<s   rr=z!TransferCoordinator.set_exception�s9���Z�Z�	(��9�9�;�(�"+���'���	(�	(�	(�s	�!7�Ac��|jjt�|jr|j�|jS)r)r[�waitrrTrSrs rrzTransferCoordinator.result�s5��	
�����f�%��?�?��/�/�!��|�|�r�c��|j5|j�sPd}tjd||�||�|_|j
dk(rd}d|_|r|j
�ddd�y#1swYyxYw)z�Cancels the TransferFuture

        :param msg: The message to attach to the cancellation
        :param exc_type: The type of exception to set for the cancellation
        Fz%s cancel(%s) calledrQT�	cancelledN)r]r�logger�debugrTrR�
announce_done)r�msg�exc_type�should_announce_dones    rrzTransferCoordinator.cancel
ss���Z�Z�		)��9�9�;�',�$����3�T�3�?�"*�3�-����<�<�=�0�+/�(�*���'��&�&�(�		)�		)�		)�s�A!A7�7Bc�&�|jd�y)z+Sets the TransferFutrue's status to running�queuedN��_transition_to_non_done_staters r�set_status_to_queuedz(TransferCoordinator.set_status_to_queueds���*�*�8�4rc�&�|jd�y)z+Sets the TransferFuture's status to running�runningNr�rs r�set_status_to_runningz)TransferCoordinator.set_status_to_running"s���*�*�9�5rc��|j5|j�rtd|j�d|�d���||_ddd�y#1swYyxYw)Nz%Unable to transition from done state z to non-done state �.)r]r�RuntimeErrorrlrR)r�
desired_states  rr�z1TransferCoordinator._transition_to_non_done_state&sK��
�Z�Z�	)��y�y�{�"�#'�;�;�
�?���)�D�L�
	)�	)�	)�s�4A
�
Ac��tjdj|||j��|j	||��}|j|�|j
t|j|��|S)a�Submits a task to a provided executor

        :type executor: s3transfer.futures.BoundedExecutor
        :param executor: The executor to submit the callable to

        :type task: s3transfer.tasks.Task
        :param task: The task to submit to the executor

        :type tag: s3transfer.futures.TaskTag
        :param tag: A tag to associate to the submitted task

        :rtype: concurrent.futures.Future
        :returns: A future representing the submitted task
        z;Submitting task {} to executor {} for transfer request: {}.)�tag)	rxryrbr'�submit�add_associated_future�add_done_callbackr�remove_associated_future)r�executor�taskr��futures     rr�zTransferCoordinator.submit/st��	���I�P�P��h�� 0� 0�
�	
�
����3��/��	
�"�"�6�*�� � ��d�;�;�V�D�	
��
rc��|jdvS)z�Determines if a TransferFuture has completed

        :returns: False if status is equal to 'failed', 'cancelled', or
            'success'. True, otherwise
        )rrrwrn)rlrs rrzTransferCoordinator.doneLs���{�{�@�@�@rc�|�|j5|jj|�ddd�y#1swYyxYw)z6Adds a future to be associated with the TransferFutureN)r^rV�add�rr�s  rr�z)TransferCoordinator.add_associated_futureTs4��
�
*�
*�	1��$�$�(�(��0�	1�	1�	1���2�;c�|�|j5|jj|�ddd�y#1swYyxYw)z4Removes a future's association to the TransferFutureN)r^rV�remover�s  rr�z,TransferCoordinator.remove_associated_futureYs4��
�
*�
*�	4��$�$�+�+�F�3�	4�	4�	4�r�c��|j5|jjt|g|��i|���ddd�y#1swYyxYw)z7Add a done callback to be invoked when transfer is doneN)r_rX�appendr�r�function�args�kwargss    rr�z%TransferCoordinator.add_done_callback^sF��
�
&�
&�	�� � �'�'�!�(�<�T�<�V�<�
�	�	�	��	�)?�Ac��|j5|jjt|g|��i|���ddd�y#1swYyxYw)z$Adds a callback to call upon failureN)r`rWr�rr�s    r�add_failure_cleanupz'TransferCoordinator.add_failure_cleanupesF��
�
(�
(�	��"�"�)�)�!�(�<�T�<�V�<�
�	�	�	�r�c��|jdk7r|j�|jj�|j	�y)aMAnnounce that future is done running and run associated callbacks

        This will run any failure cleanups if the transfer failed if not
        they have not been run, allows the result() to be unblocked, and will
        run any done callbacks associated to the TransferFuture if they have
        not already been ran.
        rnN)rl�_run_failure_cleanupsr[rU�_run_done_callbacksrs rrzz!TransferCoordinator.announce_donels:���;�;�)�#��&�&�(�������� � �"rc��|j5|j|j�g|_ddd�y#1swYyxYwr5)r_�_run_callbacksrXrs rr�z'TransferCoordinator._run_done_callbacksys>���
&�
&�	&����� 4� 4�5�#%�D� �	&�	&�	&��	�#9�Ac��|j5|j|j�g|_ddd�y#1swYyxYwr5)r`r�rjrWrs rr�z)TransferCoordinator._run_failure_cleanups�s>���
(�
(�	(����� 5� 5�6�%'�D�"�	(�	(�	(�r�c�4�|D]}|j|��yr5)�
_run_callback)r�	callbacks�callbacks   rr�z"TransferCoordinator._run_callbacks�s��!�	)�H����x�(�	)rc�f�	|�y#t$rtjd|zd��YywxYw)NzException raised in %s.T)�exc_info)�	Exceptionrxry)rr�s  rr�z!TransferCoordinator._run_callback�s6��	N��J���	N��L�L�2�X�=��L�M�	N�s�
�#0�0r5)F)rrrrNr3rdrr>rhrjrlrpr=rrrr�r�r�r�rr�r�r�r�rzr�r�r�r�rrrr1r1�s���4�7�
�
�����
7��
7��&��&�����"
%�(��&�n�)�"5�6�)��:A�1�
4�
��#�&�(�)�Nrr1c�>�eZdZejZ	dd�Zdd�Zdd�Zy)�BoundedExecutorNc��||_|�|j}||j��|_t|�|_||_y)aFAn executor implementation that has a maximum queued up tasks

        The executor will block if the number of tasks that have been
        submitted and is currently working on is past its maximum.

        :params max_size: The maximum number of inflight futures. An inflight
            future means that the task is either queued up or is currently
            being executed. A size of None or 0 means that the executor will
            have no bound in terms of the number of inflight futures.

        :params max_num_threads: The maximum number of threads the executor
            uses.

        :type tag_semaphores: dict
        :params tag_semaphores: A dictionary where the key is the name of the
            tag and the value is the semaphore to use when limiting the
            number of tasks the executor is processing at a time.

        :type executor_cls: BaseExecutor
        :param underlying_executor_cls: The executor class that
            get bounded by this executor. If None is provided, the
            concurrent.futures.ThreadPoolExecutor class is used.
        N)�max_workers)�_max_num_threads�EXECUTOR_CLS�	_executorr	�
_semaphore�_tag_semaphores)r�max_size�max_num_threads�tag_semaphores�executor_clss     rr3zBoundedExecutor.__init__�sC��4!0������,�,�L�%�$�2G�2G�H���'��1���-��rc�$�|j}|r|j|}|j|j|�}t	|j
|j|�}t
|jj|��}|j|�|S)a1Submit a task to complete

        :type task: s3transfer.tasks.Task
        :param task: The task to run __call__ on


        :type tag: s3transfer.futures.TaskTag
        :param tag: An optional tag to associate to the task. This
            is used to override which semaphore to use.

        :type block: boolean
        :param block: True if to wait till it is possible to submit a task.
            False, if not to wait and raise an error if not able to submit
            a task.

        :returns: The future associated to the submitted task
        )
r�r��acquirer'r�release�ExecutorFuturer�r�r�)rr�r��block�	semaphore�
acquire_token�release_callbackr�s        rr�zBoundedExecutor.submit�s���$�O�O�	���,�,�S�1�I�"�)�)�$�*:�*:�E�B�
�-����t�/�/��
�� ���� 5� 5�d� ;�<��	� � �!1�2��
rc�:�|jj|�yr5)r��shutdown�rrts  rr�zBoundedExecutor.shutdown�s��������%rr?�NT�T)	rrrr�ThreadPoolExecutorr�r3r�r�rrrr�r��s%���-�-�L�LP�.�B$�L&rr�c�$�eZdZd�Zd�Zd�Zd�Zy)r�c��||_y)a�A future returned from the executor

        Currently, it is just a wrapper around a concurrent.futures.Future.
        However, this can eventually grow to implement the needed functionality
        of concurrent.futures.Future if we move off of the library and not
        affect the rest of the codebase.

        :type future: concurrent.futures.Future
        :param future: The underlying future
        N)�_futurer�s  rr3zExecutorFuture.__init__�s����rc�6�|jj�Sr5)r�rrs rrzExecutorFuture.result�s���|�|�"�"�$�$rc�F���fd�}|jj|�y)aAdds a callback to be completed once future is done

        :param fn: A callable that takes no arguments. Note that is different
            than concurrent.futures.Future.add_done_callback that requires
            a single argument for the future.
        c�����Sr5r)�future_passed_to_callback�fns �r�
done_callbackz7ExecutorFuture.add_done_callback.<locals>.done_callbacks
����4�KrN)r�r�)rr�r�s ` rr�z ExecutorFuture.add_done_callback�s���	�	
���&�&�}�5rc�6�|jj�Sr5)r�rrs rrzExecutorFuture.dones���|�|� � �"�"rN)rrrr3rr�rrrrr�r��s���%�6� #rr�c�&�eZdZdZdd�Zd�Zdd�Zy)�BaseExecutorzABase Executor class implementation needed to work with s3transferNc��yr5r)rr�s  rr3zBaseExecutor.__init__���rc��td��)Nzsubmit()r)rr�r�r�s    rr�zBaseExecutor.submits
��!�*�-�-rc��td��)Nz
shutdown()rr�s  rr�zBaseExecutor.shutdowns
��!�,�/�/rr5r�)rrrrNr3r�r�rrrr�r�	s��K�
�.�0rr�c��eZdZdZd�Zdd�Zy)�NonThreadedExecutorz@A drop-in replacement non-threaded version of ThreadPoolExecutorc��t�}	||i|��}|j|�|S#t$rHtj�dd\}}t
j
d|||�|j||�Y|SwxYw)N�z0Setting exception for %s to %s with traceback %s)�NonThreadedExecutorFuturerpr��sysr�rxry�set_exception_info)rr�r�r�r�rr9�tbs        rr�zNonThreadedExecutor.submits���*�,��	-���(��(�F����f�%��
���	-��L�L�N�1�2�&�E�A�r��L�L�B����	
�
�%�%�a��,��
�	-�s�'�A
A8�7A8c��yr5rr�s  rr�zNonThreadedExecutor.shutdown)r�rNr�)rrrrNr�r�rrrr�r�s��J�� 
rr�c�B�eZdZdZd�Zd�Zd�Zdd�Zd�Zd�Z	d	�Z
d
�Zy)r�z�The Future returned from NonThreadedExecutor

    Note that this future is **not** thread-safe as it is being used
    from the context of a non-threaded environment.
    c�J�d|_d|_d|_d|_g|_y)NF)rSrT�
_traceback�_donerXrs rr3z"NonThreadedExecutorFuture.__init__4s&�������������
�!��rc�2�||_|j�yr5)rS�	_set_doneros  rrpz$NonThreadedExecutorFuture.set_result;s��������rc�@�||_||_|j�yr5)rTr�r�)rr>�	tracebacks   rr�z,NonThreadedExecutorFuture.set_exception_info?s��#���#������rNc�|�|jr%|jj|j��|jSr5)rT�with_tracebackr�rS)r�timeouts  rrz NonThreadedExecutorFuture.resultDs,���?�?��/�/�0�0����A�A��|�|�rc�d�d|_|jD]}|j|��g|_yr�)r�rX�_invoke_done_callback�rr�s  rr�z#NonThreadedExecutorFuture._set_doneIs4����
�!�1�1�	6�M��&�&�}�5�	6�!��rc��||�Sr5rr�s  rr�z/NonThreadedExecutorFuture._invoke_done_callbackOs
���T�"�"rc��|jSr5)r�rs rrzNonThreadedExecutorFuture.doneRs���z�z�rc�v�|jr|j|�y|jj|�yr5)r�r�rXr�)rr�s  rr�z+NonThreadedExecutorFuture.add_done_callbackUs+���:�:��&�&�r�*�� � �'�'��+rr5)rrrrNr3rpr�rr�r�rr�rrrr�r�-s/���"���
�
"�#��,rr��TaskTag�name�in_memory_upload�in_memory_download) rg�loggingr�rY�collectionsr�
concurrentr�s3transfer.compatr�s3transfer.exceptionsrr�s3transfer.utilsrr	�	getLoggerrrxrr!r,r/r1r�r�r�r�r�r��IN_MEMORY_UPLOAD_TAG�IN_MEMORY_DOWNLOAD_TAGrrr�<module>rs�����
��"��$�F�=�	��	�	�8�	$��.�.�62�2�"/B�'�/B�d$�#�$�NsN�sN�lK&�K&�\"#�"#�J
0�
0�
�,�
�.,,�,,�^�Y���
)���1�2�� �!5�6�r