+
    ,i<  c                   s    ^ 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                   s2   a a ] tR t^t oV 3R ltRtVtV ;t# )RequestExceededExceptionc                sN   < 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_timeZsuper__init__)selfr   r   Zmsg	__class__s   &&& 9/usr/lib/python3.14/site-packages/s3transfer/bandwidth.pyr   Z!RequestExceededException.__init__   s2     +$.WXbWcd    r   r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classdictcell__Z__classcell__)r   __classdict__s   @@r   r   r      s      r   r   c                   s    ] 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   Z__doc__r   r   r   r   r   r   %   s    Nr   r   c                   s,   a  ] tR t^+t o R tR tRtV tR# )	TimeUtilsc                s,    \         P                   ! 4       # )zOGet the current time back

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

:type value: float
:param value: The time to sleep for in seconds
)r   sleep)r   Zvalue   &&r   r   ZTimeUtils.sleep4   s     zz%  r   r   N)r
   r   r   r   r   r   r   r   r      @r   r   r   +   s     ! !r   r   c                   s4   a  ] tR t^=t o RR ltRR ltRtV tR# )BandwidthLimiterNc                sH    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_utils   &&&r   r   ZBandwidthLimiter.__init__>   s%     *%({D r   c                sv    \        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_coordinatorZenabledZstreams   &&&& r   get_bandwith_limited_streamZ,BandwidthLimiter.get_bandwith_limited_streamL   s6     ('')=?O?O
 --/r   )r   r   N)T)r
   r   r   r   r   r%   r   r   r   r   r   r   r   =   s     + r   r   c                   sp   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# )r!   Nc                s    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   r#   r   r$   r   Zbytes_thresholds   &&&&&&r   r   ZBandwidthLimitedStream.__init__d   sK    0  )%9"%({D+/(*n /r   c                    RV n         R# )z0Enable bandwidth limiting on reads to the streamTNr)   r   r   r   enable_bandwidth_limitingZ0BandwidthLimitedStream.enable_bandwidth_limiting   s
    +/(r   c                r-   )z1Disable bandwidth limiting on reads to the streamFNr.   r   r   r   r"   Z1BandwidthLimitedStream.disable_bandwidth_limiting   s
    +0(r   c                sP   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+   r,   _consume_through_leaky_bucket)r   Zamountr   r   r0   ZBandwidthLimitedStream.read   s    
 ///==%%f-- 	F"d333==%%f--**,}}!!&))r   c                sV   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(   Z	exceptionr   consumer+   r*   r   r   r   r   )r   Zes   & r   r1   Z4BandwidthLimitedStream._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)r/   r   r   r   signal_transferringZ*BandwidthLimitedStream.signal_transferring   s    &&(r   c                r3   )z:Signal that data being read is not being transferred to S3N)r"   r   r   r   signal_not_transferringZ.BandwidthLimitedStream.signal_not_transferring   s    '')r   c                s<    V P                   P                  W4       R # r&   )r'   seek)r   ZwhereZwhencer    r   r6   ZBandwidthLimitedStream.seek   s    5)r   c                s6    V P                   P                  4       # r&   )r'   tellr   r   r   r7   ZBandwidthLimitedStream.tell   s    }}!!##r   c                s    V P                   '       d#   V P                  '       d   V P                  4        V P                  P	                  4        R # r&   )r)   r+   r1   r'   closer   r   r   r8   ZBandwidthLimitedStream.close   s7    +++0@0@0@ ..0r   c                s    V # r&   r   r   r   r   	__enter__Z BandwidthLimitedStream.__enter__   s    r   c                s&    V P                  4        R # r&   )r8   )r   ZargsZkwargss   &*,r   __exit__ZBandwidthLimitedStream.__exit__   s    

r   )r)   r+   r,   r'   r   r*   r   r(   )Ni   )r    )r
   r   r   r   r   r/   r"   r0   r1   r4   r5   r6   r7   r8   r9   r:   r   r   r   r   r   r!   r!   c   sG     !0F01*(7$)**$ r   r!   c                   sH   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                s    \        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   	threadingZLock_lock_rate_trackerBandwidthRateTracker_consumption_schedulerConsumptionScheduler)r   Zmax_rater   Zrate_trackerZconsumption_schedulers   &&&&&r   r   ZLeakyBucket.__init__   sf    . x%({D^^%
)!5!7D&;# (*>*@D' )r   c                s   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)	r?   r   r   rB   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_now   &&& r   r2   Z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                sT    V P                   P                  W4      pW0P                  8  # r&   )r@   get_projected_rater=   )r   rJ   rL   Zprojected_raterM   r   rF   Z)LeakyBucket._projected_to_exceed_max_rate  s%    ++>>sM..r   c                sZ    V P                   P                  V4       V P                  W4      # r&   )rB   process_scheduled_consumptionrH   rI      &&&&r   rE   Z8LeakyBucket._release_requested_amt_for_scheduled_request  s.     	##AA	
 **399r   c                s    V\        V P                  4      ,          pV P                  P                  WV4      p\	        WR 7      h)r	   )r<   r=   rB   schedule_consumptionr   )r   rJ   rK   rL   Zallocated_timer   s   &&&&  r   rG   Z-LeakyBucket._raise_request_exceeded_exception#  sB    uT^^4400EE

 '
 	
r   c                s<    V P                   P                  W4       V# r&   )r@   record_consumption_rate)r   rJ   rL   r    r   rH   Z"LeakyBucket._release_requested_amt,  s    223A
r   )rB   r?   r=   r@   r   )NNN)r
   r   r   r   r   r2   rF   rE   rG   rH   r   r   r   r   r   r;   r;      s+     !AFB>/:
 r   r;   c                   s8   a  ] tR tRt o R tR tR tR tRtV t	R# )rC   i1  c                s"    / V n         ^ V n        R# )z*Schedules when to consume a desired amountN _tokens_to_scheduled_consumption_total_waitr   r   r   r   ZConsumptionScheduler.__init__2  s    02-r   c                s    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.
)rT   )r   tokenr   r   rD   Z!ConsumptionScheduler.is_scheduled7  s     ====r   c                s    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.
Zwait_durationtime_to_consume)rU   rT   )r   rJ   rV   rW   rP   r   rQ   Z)ConsumptionScheduler.schedule_consumption@  sE    & 	O+T--8
--e4 r   c                s    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.
rW   N)rT   ZpopZmaxrU   )r   rV   Zscheduled_retrys   && r   rO   Z2ConsumptionScheduler.process_scheduled_consumptionZ  s=     ??CCEJ/@AA1
r   rS   N)
r
   r   r   r   r   rD   rQ   rO   r   r   r   r   r   rC   rC   1  s     
> 4

 

r   rC   c                   sR   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	# )rA   ig  c                s.    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   Zalphar   r   r   ZBandwidthRateTracker.__init__h  s     !r   c                s:    V P                   f   R# V P                  # )zUThe current transfer rate

:rtype: float
:returns: The current tracked transfer rate
        )rY   rZ   r   r   r   current_rateZ!BandwidthRateTracker.current_ratex  s     ??"!!!r   c                sD    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[   )rY   *_calculate_exponential_moving_average_rater   rJ   time_at_consumptionr    r   rN   Z'BandwidthRateTracker.get_projected_rate  s'     ??">>
 	
r   c                sx    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[   )rY   rZ   r]   r^   r    r   rR   Z,BandwidthRateTracker.record_consumption_rate  s;     ??"1O!$D!LL
 .r   c                sZ    W P                   ,
          pV^ 8:  d   \        R4      # W,          # )r    Zinf)rY   r<   )r   rJ   r_   Z
time_deltarM   r   _calculate_rateZ$BandwidthRateTracker._calculate_rate  s*    (??:
?
 <!!r   c                s    V P                  W4      pV P                  V,          ^V P                  ,
          V P                  ,          ,           # )i   )r`   rX   rZ   )r   rJ   r_   Znew_raterM   r   r]   Z?BandwidthRateTracker._calculate_exponential_moving_average_rate  s;     ''A{{X%T[[D<N<N(NNNr   )rX   rZ   rY   N)g?)r
   r   r   r   r   Zpropertyr\   rN   rR   r`   r]   r   r   r   r   r   rA   rA   g  s9     "  " "
$.$"O Or   rA   )r>   r   Z	Exceptionr   r   r   r   r!   r;   rC   rA   r   r   r   <module>ra      sk     y (	 	! !$# #Ln nbZ Zz3
 3
lNO NOr   