
    vKgUR                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKJrJr  \R                   " \5      r " S S5      r " S	 S
5      r " S S\5      r " S S\5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S\5      r " S S5      r\" SS/5      r\" S5      r\" S5      rg)    N)
namedtuple)futures)MAXINT)CancelledErrorTransferNotDoneError)FunctionContainerTaskSemaphorec                   6    \ rS rSr\S 5       rS rS rS rSr	g)BaseTransferFuture   c                     [        S5      e)z-The metadata associated to the TransferFuturemetaNotImplementedErrorselfs    R/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/s3transfer/futures.pyr   BaseTransferFuture.meta   s     "&))    c                     [        S5      e)z]Determines if a TransferFuture has completed

:returns: True if completed. False, otherwise.
zdone()r   r   s    r   doneBaseTransferFuture.done!   s    
 "(++r   c                     [        S5      e)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.
zresult()r   r   s    r   resultBaseTransferFuture.result(   s     "*--r   c                     [        S5      e)z6Cancels the request associated with the TransferFuturezcancel()r   r   s    r   cancelBaseTransferFuture.cancel1   s    !*--r    N)
__name__
__module____qualname____firstlineno__propertyr   r   r   r   __static_attributes__r    r   r   r   r      s#    * *,..r   r   c                   D    \ rS rSr\S 5       r\S 5       r\S 5       rSrg)BaseTransferMeta6   c                     [        S5      e)*The call args used in the transfer request	call_argsr   r   s    r   r,   BaseTransferMeta.call_args7   s     "+..r   c                     [        S5      e)The unique id of the transfertransfer_idr   r   s    r   r0   BaseTransferMeta.transfer_id<   s     "-00r   c                     [        S5      e).A dictionary that requesters can store data inuser_contextr   r   s    r   r4   BaseTransferMeta.user_contextA   s     ".11r   r    N)	r!   r"   r#   r$   r%   r,   r0   r4   r&   r    r   r   r(   r(   6   s<    / / 1 1 2 2r   r(   c                   F    \ rS rSrS
S jr\S 5       rS rS rS r	S r
S	rg)TransferFutureG   Nc                 f    Xl         Uc  [        5       U l         X l        Uc  [        5       U l        gg)aJ  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)r   r   coordinators      r   __init__TransferFuture.__init__H   s3     
<%DJ' 3 5D r   c                     U R                   $ N)r:   r   s    r   r   TransferFuture.meta[   s    zzr   c                 6    U R                   R                  5       $ rB   )r<   r   r   s    r   r   TransferFuture.done_   s      %%''r   c                      U R                   R                  5       $ ! [         a  nU R                  5         UeS nAff = frB   )r<   r   KeyboardInterruptr   )r   es     r   r   TransferFuture.resultb   s<    	 $$++--  	KKMG	s    
=8=c                 8    U R                   R                  5         g rB   )r<   r   r   s    r   r   TransferFuture.cancell   s      "r   c                 x    U R                  5       (       d  [        S5      eU R                  R                  USS9  g)z!Sets the exception on the future.z?set_exception can only be called once the transfer is complete.T)overrideN)r   r   r<   set_exception)r   	exceptions     r   rN   TransferFuture.set_exceptiono   s:    yy{{&  	''	D'Ar   )r<   r:   NN)r!   r"   r#   r$   r?   r%   r   r   r   r   rN   r&   r    r   r   r7   r7   G   s0    6&  (#Br   r7   c                   h    \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	\S 5       r
S	 rS
rg)r;   y   z'Holds metadata about the TransferFutureNc                 8    Xl         X l        S U l        0 U l        g rB   )
_call_args_transfer_id_size_user_context)r   r,   r0   s      r   r?   TransferMeta.__init__|   s    #'
r   c                     U R                   $ )r+   )rU   r   s    r   r,   TransferMeta.call_args   s     r   c                     U R                   $ )r/   )rV   r   s    r   r0   TransferMeta.transfer_id   s        r   c                     U R                   $ )z)The size of the transfer request if knownrW   r   s    r   sizeTransferMeta.size   s     zzr   c                     U R                   $ )r3   )rX   r   s    r   r4   TransferMeta.user_context   s     !!!r   c                     Xl         g)zA 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.
Nr_   )r   r`   s     r   provide_transfer_size"TransferMeta.provide_transfer_size   s	     
r   )rU   rW   rV   rX   rQ   )r!   r"   r#   r$   __doc__r?   r%   r,   r0   r`   r4   re   r&   r    r   r   r;   r;   y   s_    1    ! !   " "r   r;   c                       \ rS rSrSrSS jrS r\S 5       r\S 5       r	\S 5       r
\S	 5       rS
 rSS jrS rS\4S jrS rS rS rSS jrS rS rS rS rS rS rS rS rS rS rSrg) r=      z*A helper class for managing TransferFutureNc                 x   Xl         SU l        S U l        S U l        [	        5       U l        / U l        / U l        [        R                  " 5       U l
        [        R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       U l        g )Nnot-started)r0   _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)r   r0   s     r   r?   TransferCoordinator.__init__   s    &$#&5 !#!$??,^^%
(1(8%$-NN$4!&/nn&6#r   c                 N    U R                   R                   SU R                   S3$ )Nz(transfer_id=))	__class__r!   r0   r   s    r   __repr__TransferCoordinator.__repr__   s'    ..))*-8H8H7IKKr   c                     U R                   $ rB   )rn   r   s    r   rO   TransferCoordinator.exception   s    r   c                     U R                      [        R                  " U R                  5      sSSS5        $ ! , (       d  f       g= f)zThe 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)rx   copyrp   r   s    r   associated_futures&TransferCoordinator.associated_futures   s-     ** 99T556	 +**s	    7
Ac                     U R                   $ )z;The list of callbacks to call when the TransferFuture fails)rq   r   s    r   failure_cleanups$TransferCoordinator.failure_cleanups   s     %%%r   c                     U R                   $ )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.
)rl   r   s    r   statusTransferCoordinator.status   s      ||r   c                 x    U R                      SU l        Xl        SU l        SSS5        g! , (       d  f       g= f)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)rw   rn   rm   rl   r   r   s     r   
set_resultTransferCoordinator.set_result   s(     ZZ"DO!L$DL ZZs   +
9c                     U R                      U R                  5       (       a  U(       a  Xl        SU l        SSS5        g! , (       d  f       g= f)zSet 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)rw   r   rn   rl   )r   rO   rM   s      r   rN   !TransferCoordinator.set_exception   s.     ZZ99;;("+' ZZs   *A  
Ac                     U R                   R                  [        5        U R                  (       a  U R                  eU R                  $ )r   )ru   waitr   rn   rm   r   s    r   r   TransferCoordinator.result   s5     	f% ??//!||r    c                 $   U R                      U R                  5       (       dU  Sn[        R                  SX5        U" U5      U l        U R
                  S:X  a  SnSU l        U(       a  U R                  5         SSS5        g! , (       d  f       g= f)zCancels 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) calledrk   T	cancelledN)rw   r   loggerdebugrn   rl   announce_done)r   msgexc_typeshould_announce_dones       r   r   TransferCoordinator.cancel  sh     ZZ99;;',$3T?"*3-<<=0+/(*'&&( ZZs   A+B
Bc                 &    U R                  S5        g)z+Sets the TransferFutrue's status to runningqueuedN_transition_to_non_done_stater   s    r   set_status_to_queued(TransferCoordinator.set_status_to_queued  s    **84r   c                 &    U R                  S5        g)z+Sets the TransferFuture's status to runningrunningNr   r   s    r   set_status_to_running)TransferCoordinator.set_status_to_running   s    **95r   c                     U R                      U R                  5       (       a  [        SU R                   SU S35      eXl        S S S 5        g ! , (       d  f       g = f)Nz%Unable to transition from done state z to non-done state .)rw   r   RuntimeErrorr   rl   )r   desired_states     r   r   1TransferCoordinator._transition_to_non_done_state$  sO    ZZyy{{";DKK= I*O1.  )L ZZs   8A
Ac           	          [         R                  SU SU SU R                   S35        UR                  X#S9nU R	                  U5        UR                  [        U R                  U5      5        U$ )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 z to executor z for transfer request: r   )tag)r   r   r0   submitadd_associated_futureadd_done_callbackr   remove_associated_future)r   executortaskr   futures        r   r   TransferCoordinator.submit-  sy     	tfM(;RSWScScRddef	
 / 	""6*  d;;VD	
 r   c                      U R                   S;   $ )zDetermines if a TransferFuture has completed

:returns: False if status is equal to 'failed', 'cancelled', or
    'success'. True, otherwise
)r   r   r   )r   r   s    r   r   TransferCoordinator.doneH  s     {{@@@r   c                     U R                      U R                  R                  U5        SSS5        g! , (       d  f       g= f)z6Adds a future to be associated with the TransferFutureN)rx   rp   addr   r   s     r   r   )TransferCoordinator.add_associated_futureP  s+    **$$((0 +**	   2
A c                     U R                      U R                  R                  U5        SSS5        g! , (       d  f       g= f)z4Removes a future's association to the TransferFutureN)rx   rp   remover   s     r   r   ,TransferCoordinator.remove_associated_futureU  s+    **$$++F3 +**r   c                     U R                      U R                  R                  [        U/UQ70 UD65        SSS5        g! , (       d  f       g= f)z7Add a done callback to be invoked when transfer is doneN)ry   rr   appendr   r   functionargskwargss       r   r   %TransferCoordinator.add_done_callbackZ  s=    &&  ''!(<T<V< '&&	   )?
Ac                     U R                      U R                  R                  [        U/UQ70 UD65        SSS5        g! , (       d  f       g= f)z$Adds a callback to call upon failureN)rz   rq   r   r   r   s       r   add_failure_cleanup'TransferCoordinator.add_failure_cleanupa  s=    ((""))!(<T<V< )((r   c                     U R                   S:w  a  U R                  5         U R                  R                  5         U R	                  5         g)a%  Announce 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.
r   N)r   _run_failure_cleanupsru   ro   _run_done_callbacksr   s    r   r   !TransferCoordinator.announce_doneh  s:     ;;)#&&(  "r   c                     U R                      U R                  U R                  5        / U l        S S S 5        g ! , (       d  f       g = frB   )ry   _run_callbacksrr   r   s    r   r   'TransferCoordinator._run_done_callbacksu  s5     && 4 45#%D  '&&	   #9
Ac                     U R                      U R                  U R                  5        / U l        S S S 5        g ! , (       d  f       g = frB   )rz   r   r   rq   r   s    r   r   )TransferCoordinator._run_failure_cleanups}  s5     (( 5 56%'D" )((r   c                 8    U H  nU R                  U5        M     g rB   )_run_callback)r   	callbackscallbacks      r   r   "TransferCoordinator._run_callbacks  s    !Hx( "r   c                 d     U" 5         g ! [          a    [        R                  SU S3SS9   g f = f)NzException raised in r   T)exc_info)	Exceptionr   r   )r   r   s     r   r   !TransferCoordinator._run_callback  s:    	LJ  	LLL/z;dLK	Ls   
 "//)rp   rx   rr   ry   ru   rn   rq   rz   rw   rm   rl   r0   rB   )F) r!   r"   r#   r$   rg   r?   r   r%   rO   r   r   r   r   rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r    r   r   r=   r=      s    47L   
7 
7 & &  "%(& n )"56)6A1
4
#&()Lr   r=   c                   L    \ rS rSr\R
                  r SS jrSS jrS	S jr	Sr
g)
BoundedExecutori  Nc                     X l         Uc  U R                  nU" U R                   S9U l        [        U5      U l        X0l        g)a  An 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        r   r?   BoundedExecutor.__init__  s?    4 !0,,L%$2G2GH'1-r   c                 .   U R                   nU(       a  U R                  U   nUR                  UR                  U5      n[	        UR
                  UR                  U5      n[        U R                  R                  U5      5      nUR                  U5        U$ )a  Submit 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   acquirer0   r   releaseExecutorFuturer   r   r   )r   r   r   block	semaphoreacquire_tokenrelease_callbackr   s           r   r   BoundedExecutor.submit  s    $ OO	 ,,S1I "))$*:*:EB -t//
   5 5d ;< 	  !12r   c                 :    U R                   R                  U5        g rB   )r   shutdownr   r   s     r   r   BoundedExecutor.shutdown  s    %r   )r   r   r   r   rQ   NTT)r!   r"   r#   r$   r   ThreadPoolExecutorr   r?   r   r   r&   r    r   r   r   r     s%    --L LP.B$L&r   r   c                   ,    \ rS rSrS rS rS rS rSrg)r   i  c                     Xl         g)ac  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     r   r?   ExecutorFuture.__init__  s	     r   c                 6    U R                   R                  5       $ rB   )r  r   r   s    r   r   ExecutorFuture.result  s    ||""$$r   c                 H   ^ U4S jnU R                   R                  U5        g)zAdds 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                    > T" 5       $ rB   r    )future_passed_to_callbackfns    r   done_callback7ExecutorFuture.add_done_callback.<locals>.done_callback  s
    4Kr   N)r  r   )r   r  r  s    ` r   r    ExecutorFuture.add_done_callback  s    	 	&&}5r   c                 6    U R                   R                  5       $ rB   )r  r   r   s    r   r   ExecutorFuture.done  s    ||  ""r   r  N)	r!   r"   r#   r$   r?   r   r   r   r&   r    r   r   r   r     s    %6 #r   r   c                   2    \ rS rSrSrSS jrS rS	S jrSrg)
BaseExecutori  zABase Executor class implementation needed to work with s3transferNc                     g rB   r    )r   r   s     r   r?   BaseExecutor.__init__      r   c                     [        S5      e)Nzsubmit()r   )r   r  r   r   s       r   r   BaseExecutor.submit  s    !*--r   c                     [        S5      e)Nz
shutdown()r   r   s     r   r   BaseExecutor.shutdown  s    !,//r   r    rB   r   )	r!   r"   r#   r$   rg   r?   r   r   r&   r    r   r   r  r    s    K.0r   r  c                   (    \ rS rSrSrS rSS jrSrg)NonThreadedExecutori  z@A drop-in replacement non-threaded version of ThreadPoolExecutorc                     [        5       n U" U0 UD6nUR                  U5        U$ ! [         aG    [        R                  " 5       SS  u  pg[
        R                  SUUU5        UR                  Xg5         U$ f = f)N   z0Setting exception for %s to %s with traceback %s)NonThreadedExecutorFuturer   r   sysr   r   r   set_exception_info)r   r  r   r   r   r   rH   tbs           r   r   NonThreadedExecutor.submit  s    *,	-((Ff%   	-LLN12&EALLB	 %%a,	-s   ' AA87A8c                     g rB   r    r   s     r   r   NonThreadedExecutor.shutdown%  r  r   r    Nr   )r!   r"   r#   r$   rg   r   r   r&   r    r   r   r  r    s    J r   r  c                   L    \ rS rSrSrS rS rS rSS jrS r	S	 r
S
 rS rSrg)r  i)  zThe 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    S U l         S U l        S U l        SU l        / U l        g )NF)rm   rn   
_traceback_donerr   r   s    r   r?   "NonThreadedExecutorFuture.__init__0  s&    
!r   c                 0    Xl         U R                  5         g rB   )rm   	_set_doner   s     r   r   $NonThreadedExecutorFuture.set_result7  s    r   c                 <    Xl         X l        U R                  5         g rB   )rn   r'  r+  )r   rO   	tracebacks      r   r   ,NonThreadedExecutorFuture.set_exception_info;  s    ##r   Nc                     U R                   (       a%  U R                   R                  U R                  5      eU R                  $ rB   )rn   with_tracebackr'  rm   )r   timeouts     r   r    NonThreadedExecutorFuture.result@  s,    ??//00AA||r   c                 h    SU l         U R                   H  nU R                  U5        M     / U l        g r   )r(  rr   _invoke_done_callbackr   r  s     r   r+  #NonThreadedExecutorFuture._set_doneE  s/    
!11M&&}5 2!r   c                     U" U 5      $ rB   r    r6  s     r   r5  /NonThreadedExecutorFuture._invoke_done_callbackK  s    T""r   c                     U R                   $ rB   )r(  r   s    r   r   NonThreadedExecutorFuture.doneN  s    zzr   c                     U R                   (       a  U R                  U5        g U R                  R                  U5        g rB   )r(  r5  rr   r   )r   r  s     r   r   +NonThreadedExecutorFuture.add_done_callbackQ  s+    ::&&r*  ''+r   )r(  rr   rn   rm   r'  rB   )r!   r"   r#   r$   rg   r?   r   r   r   r+  r5  r   r   r&   r    r   r   r  r  )  s/    "

"#,r   r  TaskTagnamein_memory_uploadin_memory_download) r   loggingr  rs   collectionsr   
concurrentr   s3transfer.compatr   s3transfer.exceptionsr   r   s3transfer.utilsr   r	   	getLoggerr!   r   r   r(   r7   r;   r=   r   r   r  r  r  r>  IN_MEMORY_UPLOAD_TAGIN_MEMORY_DOWNLOAD_TAGr    r   r   <module>rK     s      
  "  $ F =			8	$. .62 2"/B' /Bd$# $NoL oLdK& K&\"# "#J
0 
0, .,, ,,^ Y
)12  !56 r   