+
    [mh<                         ^ RI t ^ RIt ! R R]4      t ! R R4      t ! R R4      t ! R R	4      t ! R
 R4      t ! R R4      t ! R R4      t	 ! R R4      t
R# )    Nc                   2   a a ] tR t^t oV 3R ltRtVtV ;t# )RequestExceededExceptionc                N   < Wn         W n        RV RV 2p\        SV `  V4       R# )a`  Error when requested amount exceeds what is allowed

The request that raised this error should be retried after waiting
the time specified by ``retry_time``.

:type requested_amt: int
:param requested_amt: The originally requested byte amount

:type retry_time: float
:param retry_time: The length in time to wait to retry for the
    requested amount
zRequest amount z) exceeded the amount available. Retry in N)requested_amt
retry_timesuper__init__)selfr   r   msg	__class__s   &&& 6/usr/lib/python3/dist-packages/s3transfer/bandwidth.pyr	   !RequestExceededException.__init__   s2     +$.WXbWcd    r   r   )__name__
__module____qualname____firstlineno__r	   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      s      r   r   c                       ] tR t^%tRtRtR# )RequestTokenzDA token to pass as an identifier when consuming from the LeakyBucket N)r   r   r   r   __doc__r   r   r   r   r   r   %   s    Nr   r   c                   ,   a  ] tR t^+t o R tR tRtV tR# )	TimeUtilsc                ,    \         P                   ! 4       # )zOGet the current time back

:rtype: float
:returns: The current time in seconds
)timer
   s   &r   r    TimeUtils.time,   s     yy{r   c                .    \         P                  ! V4      # )z_Sleep for a designated time

:type value: float
:param value: The time to sleep for in seconds
)r    sleep)r
   values   &&r   r$   TimeUtils.sleep4   s     zz%  r   r   N)r   r   r   r   r    r$   r   r   r   s   @r   r   r   +   s     ! !r   r   c                   4   a  ] tR t^=t o RR ltRR ltRtV tR# )BandwidthLimiterNc                H    Wn         W n        Vf   \        4       V n        R# R# )zLimits bandwidth for shared S3 transfers

:type leaky_bucket: LeakyBucket
:param leaky_bucket: The leaky bucket to use limit bandwidth

:type time_utils: TimeUtils
:param time_utils: Time utility to use for interacting with time.
N)_leaky_bucket_time_utilsr   )r
   leaky_bucket
time_utilss   &&&r   r	   BandwidthLimiter.__init__>   s%     *%({D r   c                v    \        WP                  W P                  4      pV'       g   VP                  4        V# )a  Wraps a fileobj in a bandwidth limited stream wrapper

:type fileobj: file-like obj
:param fileobj: The file-like obj to wrap

:type transfer_coordinator: s3transfer.futures.TransferCoordinator
param transfer_coordinator: The coordinator for the general transfer
    that the wrapped stream is a part of

:type enabled: boolean
:param enabled: Whether bandwidth limiting should be enabled to start
)BandwidthLimitedStreamr+   r,   disable_bandwidth_limiting)r
   fileobjtransfer_coordinatorenabledstreams   &&&& r   get_bandwith_limited_stream,BandwidthLimiter.get_bandwith_limited_streamL   s6     ('')=?O?O
 --/r   )r+   r,   N)T)r   r   r   r   r	   r7   r   r   r'   s   @r   r)   r)   =   s     + r   r)   c                   p   a  ] tR t^ct o RR ltR tR tR tR tR t	R t
RR	 ltR
 tR tR tR tRtV tR# )r1   Nc                    Wn         W n        W0n        W@n        Vf   \	        4       V n        RV n        \        4       V n        ^ V n        WPn	        R# )a  Limits bandwidth for reads on a wrapped stream

:type fileobj: file-like object
:param fileobj: The file like object to wrap

:type leaky_bucket: LeakyBucket
:param leaky_bucket: The leaky bucket to use to throttle reads on
    the stream

:type transfer_coordinator: s3transfer.futures.TransferCoordinator
param transfer_coordinator: The coordinator for the general transfer
    that the wrapped stream is a part of

:type time_utils: TimeUtils
:param time_utils: The time utility to use for interacting with time
NT)
_fileobjr+   _transfer_coordinatorr,   r   _bandwidth_limiting_enabledr   _request_token_bytes_seen_bytes_threshold)r
   r3   r-   r4   r.   bytes_thresholds   &&&&&&r   r	   BandwidthLimitedStream.__init__d   sK    0  )%9"%({D+/(*n /r   c                    RV n         R# )z0Enable bandwidth limiting on reads to the streamTNr>   r!   s   &r   enable_bandwidth_limiting0BandwidthLimitedStream.enable_bandwidth_limiting   s
    +/(r   c                    RV n         R# )z1Disable bandwidth limiting on reads to the streamFNrE   r!   s   &r   r2   1BandwidthLimitedStream.disable_bandwidth_limiting   s
    +0(r   c                P   V P                   '       g   V P                  P                  V4      # V ;P                  V,          un        V P                  V P                  8  d   V P                  P                  V4      # V P                  4        V P                  P                  V4      # )zXRead a specified amount

Reads will only be throttled if bandwidth limiting is enabled.
)r>   r<   readr@   rA   _consume_through_leaky_bucket)r
   amounts   &&r   rK   BandwidthLimitedStream.read   s    
 ///==%%f-- 	F"d333==%%f--**,}}!!&))r   c                V   V P                   P                  '       g;    V P                  P                  V P                  V P
                  4       ^ V n        R# V P                   P                  h  \         d1   pT P                  P                  TP                  4        Rp?K  Rp?ii ; i)r   N)
r=   	exceptionr+   consumer@   r?   r   r,   r$   r   )r
   es   & r   rL   4BandwidthLimitedStream._consume_through_leaky_bucket   s     ,,6665""**$$d&9&9 $%  ,,666 , 5  &&q||445s   7A- -B(8%B##B(c                &    V P                  4        R# )z6Signal that data being read is being transferred to S3N)rF   r!   s   &r   signal_transferring*BandwidthLimitedStream.signal_transferring   s    &&(r   c                &    V P                  4        R# )z:Signal that data being read is not being transferred to S3N)r2   r!   s   &r   signal_not_transferring.BandwidthLimitedStream.signal_not_transferring   s    '')r   c                <    V P                   P                  W4       R # r9   )r<   seek)r
   wherewhences   &&&r   r[   BandwidthLimitedStream.seek   s    5)r   c                6    V P                   P                  4       # r9   )r<   tellr!   s   &r   r`   BandwidthLimitedStream.tell   s    }}!!##r   c                    V P                   '       d#   V P                  '       d   V P                  4        V P                  P	                  4        R # r9   )r>   r@   rL   r<   closer!   s   &r   rc   BandwidthLimitedStream.close   s7    +++0@0@0@ ..0r   c                    V # r9   r   r!   s   &r   	__enter__ BandwidthLimitedStream.__enter__   s    r   c                &    V P                  4        R # r9   )rc   )r
   argskwargss   &*,r   __exit__BandwidthLimitedStream.__exit__   s    

r   )r>   r@   rA   r<   r+   r?   r,   r=   )Ni   )r   )r   r   r   r   r	   rF   r2   rK   rL   rU   rX   r[   r`   rc   rf   rk   r   r   r'   s   @r   r1   r1   c   sG     !0F01*(7$)**$ r   r1   c                   H   a  ] tR t^t o R	R ltR tR tR tR tR t	Rt
V tR# )
LeakyBucketNc                    \        V4      V n        W n        Vf   \        4       V n        \        P
                  ! 4       V n        W0n        Vf   \        4       V n        W@n	        Vf   \        4       V n	        R# R# )a  A leaky bucket abstraction to limit bandwidth consumption

:type rate: int
:type rate: The maximum rate to allow. This rate is in terms of
    bytes per second.

:type time_utils: TimeUtils
:param time_utils: The time utility to use for interacting with time

:type rate_tracker: BandwidthRateTracker
:param rate_tracker: Tracks bandwidth consumption

:type consumption_scheduler: ConsumptionScheduler
:param consumption_scheduler: Schedules consumption retries when
    necessary
N)float	_max_rater,   r   	threadingLock_lock_rate_trackerBandwidthRateTracker_consumption_schedulerConsumptionScheduler)r
   max_rater.   rate_trackerconsumption_schedulers   &&&&&r   r	   LeakyBucket.__init__   sf    . x%({D^^%
)!5!7D&;# (*>*@D' )r   c                   V P                   ;_uu_ 4        V P                  P                  4       pV P                  P	                  V4      '       d   V P                  WV4      uuRRR4       # V P                  W4      '       d   V P                  WV4       MV P                  W4      uuRRR4       #  RRR4       R#   + '       g   i     R# ; i)a  Consume an a requested amount

:type amt: int
:param amt: The amount of bytes to request to consume

:type request_token: RequestToken
:param request_token: The token associated to the consumption
    request that is used to identify the request. So if a
    RequestExceededException is raised the token should be used
    in subsequent retry consume() request.

:raises RequestExceededException: If the consumption amount would
    exceed the maximum allocated bandwidth

:rtype: int
:returns: The amount consumed
N)	rt   r,   r    rw   is_scheduled,_release_requested_amt_for_scheduled_request_projected_to_exceed_max_rate!_raise_request_exceeded_exception_release_requested_amtr
   amtrequest_tokentime_nows   &&& r   rQ   LeakyBucket.consume   s    $ ZZZ'',,.H**77FFHH Z 33CBB66 223A Z ZZZs   AB=-:B==C	c                T    V P                   P                  W4      pW0P                  8  # r9   )ru   get_projected_raterq   )r
   r   r   projected_rates   &&& r   r   )LeakyBucket._projected_to_exceed_max_rate  s%    ++>>sM..r   c                Z    V P                   P                  V4       V P                  W4      # r9   )rw   process_scheduled_consumptionr   r   s   &&&&r   r   8LeakyBucket._release_requested_amt_for_scheduled_request  s.     	##AA	
 **399r   c                    V\        V P                  4      ,          pV P                  P                  WV4      p\	        WR 7      h)r   )rp   rq   rw   schedule_consumptionr   )r
   r   r   r   allocated_timer   s   &&&&  r   r   -LeakyBucket._raise_request_exceeded_exception#  sB    uT^^4400EE

 '
 	
r   c                <    V P                   P                  W4       V# r9   )ru   record_consumption_rate)r
   r   r   s   &&&r   r   "LeakyBucket._release_requested_amt,  s    223A
r   )rw   rt   rq   ru   r,   )NNN)r   r   r   r   r	   rQ   r   r   r   r   r   r   r'   s   @r   rn   rn      s+     !AFB>/:
 r   rn   c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )rx   i1  c                "    / V n         ^ V n        R# )z*Schedules when to consume a desired amountN _tokens_to_scheduled_consumption_total_waitr!   s   &r   r	   ConsumptionScheduler.__init__2  s    02-r   c                    WP                   9   # )zIndicates if a consumption request has been scheduled

:type token: RequestToken
:param token: The token associated to the consumption
    request that is used to identify the request.
)r   )r
   tokens   &&r   r~   !ConsumptionScheduler.is_scheduled7  s     ====r   c                    V ;P                   V,          un         RV P                   RV/V P                  V&   V P                   # )aL  Schedules a wait time to be able to consume an amount

:type amt: int
:param amt: The amount of bytes scheduled to be consumed

:type token: RequestToken
:param token: The token associated to the consumption
    request that is used to identify the request.

:type time_to_consume: float
:param time_to_consume: The desired time it should take for that
    specific request amount to be consumed in regardless of previously
    scheduled consumption requests

:rtype: float
:returns: The amount of time to wait for the specific request before
    actually consuming the specified amount.
wait_durationtime_to_consume)r   r   )r
   r   r   r   s   &&&&r   r   )ConsumptionScheduler.schedule_consumption@  sE    & 	O+T--8
--e4 r   c                    V P                   P                  V4      p\        V P                  VR,          ,
          ^ 4      V n        R# )zProcesses a scheduled consumption request that has completed

:type token: RequestToken
:param token: The token associated to the consumption
    request that is used to identify the request.
r   N)r   popmaxr   )r
   r   scheduled_retrys   && r   r   2ConsumptionScheduler.process_scheduled_consumptionZ  s=     ??CCEJ/@AA1
r   r   N)
r   r   r   r   r	   r~   r   r   r   r   r'   s   @r   rx   rx   1  s     
> 4

 

r   rx   c                   R   a  ] tR tRt o R
R lt]R 4       tR tR tR t	R t
RtV tR	# )rv   ig  c                .    Wn         RV n        RV n        R# )aZ  Tracks the rate of bandwidth consumption

:type a: float
:param a: The constant to use in calculating the exponentional moving
    average of the bandwidth rate. Specifically it is used in the
    following calculation:

    current_rate = alpha * new_rate + (1 - alpha) * current_rate

    This value of this constant should be between 0 and 1.
N)_alpha
_last_time_current_rate)r
   alphas   &&r   r	   BandwidthRateTracker.__init__h  s     !r   c                :    V P                   f   R# V P                  # )zUThe current transfer rate

:rtype: float
:returns: The current tracked transfer rate
        )r   r   r!   s   &r   current_rate!BandwidthRateTracker.current_ratex  s     ??"!!!r   c                D    V P                   f   R# V P                  W4      # )a"  Get the projected rate using a provided amount and time

:type amt: int
:param amt: The proposed amount to consume

:type time_at_consumption: float
:param time_at_consumption: The proposed time to consume at

:rtype: float
:returns: The consumption rate if that amt and time were consumed
r   )r   *_calculate_exponential_moving_average_rater
   r   time_at_consumptions   &&&r   r   'BandwidthRateTracker.get_projected_rate  s'     ??">>
 	
r   c                x    V P                   f   W n         RV n        R# V P                  W4      V n        W n         R# )zRecord the consumption rate based off amount and time point

:type amt: int
:param amt: The amount that got consumed

:type time_at_consumption: float
:param time_at_consumption: The time at which the amount was consumed
Nr   )r   r   r   r   s   &&&r   r   ,BandwidthRateTracker.record_consumption_rate  s;     ??"1O!$D!LL
 .r   c                Z    W P                   ,
          pV^ 8:  d   \        R4      # W,          # )r   inf)r   rp   )r
   r   r   
time_deltas   &&& r   _calculate_rate$BandwidthRateTracker._calculate_rate  s*    (??:
?
 <!!r   c                    V P                  W4      pV P                  V,          ^V P                  ,
          V P                  ,          ,           # )   )r   r   r   )r
   r   r   new_rates   &&& r   r   ?BandwidthRateTracker._calculate_exponential_moving_average_rate  s;     ''A{{X%T[[D<N<N(NNNr   )r   r   r   N)g?)r   r   r   r   r	   propertyr   r   r   r   r   r   r   r'   s   @r   rv   rv   g  s9     "  " "
$.$"O Or   rv   )rr   r    	Exceptionr   r   r   r)   r1   rn   rx   rv   r   r   r   <module>r      sk     y (	 	! !$# #Ln nbZ Zz3
 3
lNO NOr   