ó
    &ÝNjó<  ã                   ó¶   • S SK r S SK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
g)é    Nc                   ó(   ^ • \ rS rSrU 4S jrSrU =r$ )ÚRequestExceededExceptioné   c                 óL   >• Xl         X l        SU SU 3n[        TU ]  U5        g)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       €ÚQ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/s3transfer/bandwidth.pyr
   Ú!RequestExceededException.__init__   s2   ø€ ð +ÔØ$ŒØ ˜Ð.WÐXbÐWcÐdˆÜ‰Ñ˜Õó    ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r
   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s   ø† ÷ó r   r   c                   ó   • \ rS rSrSrSrg)ÚRequestTokené%   zDA 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                   ó    • \ rS rSrS rS rSrg)Ú	TimeUtilsé+   c                 ó,   • [         R                   " 5       $ )zOGet the current time back

:rtype: float
:returns: The current time in seconds
)Útime©r   s    r   r!   ÚTimeUtils.time,   s   € ô �yŠy‹{Ðr   c                 ó.   • [         R                  " U5      $ )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   € ô �zŠz˜%Ó Ð r   r   N)r   r   r   r   r!   r%   r   r   r   r   r   r   +   s   † òõ!r   r   c                   ó*   • \ rS rSrSS jr SS jrSrg)ÚBandwidthLimiteré=   Nc                 óB   • Xl         X l        Uc  [        5       U l        gg)zæLimits 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                 ót   • [        XR                  X R                  5      nU(       d  UR                  5         U$ )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
   r8   r   r   r   r   r)   r)   =   s   † ô+ð 6:÷r   r)   c                   óh   • \ rS rSr  SS j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)r2   éc   Nc                 óž   • Xl         X l        X0l        X@l        Uc  [	        5       U l        SU l        [        5       U l        SU l        XPl	        g)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
NTr   )
Ú_fileobjr,   Ú_transfer_coordinatorr-   r   Ú_bandwidth_limiting_enabledr   Ú_request_tokenÚ_bytes_seenÚ_bytes_threshold)r   r4   r.   r5   r/   Úbytes_thresholds         r   r
   ÚBandwidthLimitedStream.__init__d   sK   € ð0  ŒØ)ÔØ%9Ô"Ø%ÔØÑÜ(›{ˆDÔØ+/ˆÔ(Ü*›nˆÔØˆÔØ /Õr   c                 ó   • SU l         g)z0Enable bandwidth limiting on reads to the streamTN©r@   r"   s    r   Úenable_bandwidth_limitingÚ0BandwidthLimitedStream.enable_bandwidth_limiting‡   s
   € à+/ˆÕ(r   c                 ó   • SU l         g)z1Disable bandwidth limiting on reads to the streamFNrG   r"   s    r   r3   Ú1BandwidthLimitedStream.disable_bandwidth_limiting‹   s
   € à+0ˆÕ(r   c                 óD  • U R                   (       d  U R                  R                  U5      $ U =R                  U-  sl        U R                  U R                  :  a  U R                  R                  U5      $ U R                  5         U R                  R                  U5      $ )zXRead a specified amount

Reads will only be throttled if bandwidth limiting is enabled.
)r@   r>   ÚreadrB   rC   Ú_consume_through_leaky_bucket)r   Úamounts     r   rM   ÚBandwidthLimitedStream.read�   s   € ð
 ×/×/Ø—=‘=×%Ñ% fÓ-Ð-ð 	×Ò˜FÑ"ÕØ×Ñ˜d×3Ñ3Ó3Ø—=‘=×%Ñ% fÓ-Ð-à×*Ñ*Ô,Ø�}‰}×!Ñ! &Ó)Ð)r   c                 óŠ  • U R                   R                  (       d9   U R                  R                  U R                  U R
                  5        SU l        g U R                   R                  e! [         a/  nU R                  R                  UR                  5         S nAOS nAff = fU R                   R                  (       d  M¨  Np)Nr   )
r?   Ú	exceptionr,   ÚconsumerB   rA   r   r-   r%   r   )r   Úes     r   rN   Ú4BandwidthLimitedStream._consume_through_leaky_bucket£   sŸ   € ð ×,Ñ,×6×6ð5Ø×"Ñ"×*Ñ*Ø×$Ñ$ d×&9Ñ&9ôð $%�Ô Øð ×,Ñ,×6Ñ6Ð6øô ,ó 5Ø× Ñ ×&Ñ& q§|¡|×4Ñ4ûð5úð ×,Ñ,×6×6Ò6s   �7A+ Á+
B$Á5%BÂB$c                 ó$   • U R                  5         g)z6Signal that data being read is being transferred to S3N)rH   r"   s    r   Úsignal_transferringÚ*BandwidthLimitedStream.signal_transferringµ   s   € à×&Ñ&Õ(r   c                 ó$   • U R                  5         g)z:Signal that data being read is not being transferred to S3N)r3   r"   s    r   Úsignal_not_transferringÚ.BandwidthLimitedStream.signal_not_transferring¹   s   € à×'Ñ'Õ)r   c                 ó:   • U R                   R                  X5        g r:   )r>   Úseek)r   ÚwhereÚwhences      r   r]   ÚBandwidthLimitedStream.seek½   s   € Ø�‰×Ñ˜5Õ)r   c                 ó6   • U R                   R                  5       $ r:   )r>   Útellr"   s    r   rb   ÚBandwidthLimitedStream.tellÀ   s   € Ø�}‰}×!Ñ!Ó#Ð#r   c                 óœ   • U R                   (       a!  U R                  (       a  U R                  5         U R                  R	                  5         g r:   )r@   rB   rN   r>   Úcloser"   s    r   re   ÚBandwidthLimitedStream.closeÃ   s1   € Ø×+×+°×0@×0@ð ×.Ñ.Ô0Ø�‰×ÑÕr   c                 ó   • U $ r:   r   r"   s    r   Ú	__enter__Ú BandwidthLimitedStream.__enter__Í   s   € Øˆr   c                 ó$   • U R                  5         g r:   )re   )r   ÚargsÚkwargss      r   Ú__exit__ÚBandwidthLimitedStream.__exit__Ð   s   € Ø�
‰
�r   )r@   rB   rC   r>   r,   rA   r-   r?   )Ni   )r   )r   r   r   r   r
   rH   r3   rM   rN   rW   rZ   r]   rb   re   rh   rm   r   r   r   r   r2   r2   c   sG   † ð Ø"ô!0òF0ò1ò*ò(7ò$)ò*ô*ò$òòõr   r2   c                   óB   • \ rS rSr   S
S jrS rS rS rS rS r	S	r
g)ÚLeakyBucketéÔ   Nc                 óê   • [        U5      U l        X l        Uc  [        5       U l        [        R
                  " 5       U l        X0l        Uc  [        5       U l        X@l	        Uc  [        5       U l	        gg)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Ó!7ˆDÔØ&;Ô#Ø Ñ(Ü*>Ó*@ˆDÕ'ð )r   c                 ó‚  • U R                      U R                  R                  5       nU R                  R	                  U5      (       a  U R                  XU5      sSSS5        $ U R                  X5      (       a  U R                  XU5        OU R                  X5      sSSS5        $  SSS5        g! , (       d  f       g= f)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)	rw   r-   r!   rz   Ú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   rS   ÚLeakyBucket.consumeø   sœ   € ð$ �Z‹ZØ×'Ñ'×,Ñ,Ó.ˆHØ×*Ñ*×7Ñ7¸×FÑFØ×HÑHØ¨ó÷ ‰Zð ×3Ñ3°C×BÑBØ×6Ñ6Ø¨õð ×2Ñ2°3ÓA÷ ‰Zð÷ �ZŽZús   �AB0Á#9B0Â0
B>c                 óT   • U R                   R                  X5      nX0R                  :„  $ r:   )rx   Úget_projected_ratert   )r   r‡   r‰   Úprojected_rates       r   rƒ   Ú)LeakyBucket._projected_to_exceed_max_rate  s%   € Ø×+Ñ+×>Ñ>¸sÓMˆØ§¡Ñ.Ð.r   c                 óZ   • U R                   R                  U5        U R                  X5      $ r:   )rz   Úprocess_scheduled_consumptionr…   r†   s       r   r‚   Ú8LeakyBucket._release_requested_amt_for_scheduled_request  s.   € ð 	×#Ñ#×AÑAØô	
ð ×*Ñ*¨3Ó9Ð9r   c                 ó|   • U[        U R                  5      -  nU R                  R                  XU5      n[	        XS9e)Nr   )rs   rt   rz   Úschedule_consumptionr   )r   r‡   rˆ   r‰   Úallocated_timer   s         r   r„   Ú-LeakyBucket._raise_request_exceeded_exception#  sB   € Øœu T§^¡^Ó4Ñ4ˆØ×0Ñ0×EÑEØ ó
ˆ
ô 'Øñ
ð 	
r   c                 ó<   • U R                   R                  X5        U$ r:   )rx   Úrecord_consumption_rate)r   r‡   r‰   s      r   r…   Ú"LeakyBucket._release_requested_amt,  s   € Ø×Ñ×2Ñ2°3ÔAØˆ
r   )rz   rw   rt   rx   r-   )NNN)r   r   r   r   r
   rS   rƒ   r‚   r„   r…   r   r   r   r   rp   rp   Ô   s.   † ð ØØ"ô!AòFBò>/ò:ò
õr   rp   c                   ó,   • \ rS rSrS rS rS rS rSrg)r{   i1  c                 ó    • 0 U l         SU l        g)z*Schedules when to consume a desired amountr   N©Ú _tokens_to_scheduled_consumptionÚ_total_waitr"   s    r   r
   ÚConsumptionScheduler.__init__2  s   € à02ˆÔ-ØˆÕr   c                 ó   • XR                   ;   $ )z¹Indicates 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                 ó|   • U =R                   U-  sl         U R                   US.U R                  U'   U R                   $ )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@  sA   € ð& 	×Ò˜OÑ+Õà!×-Ñ-Ø.ñ8
ˆ×-Ñ-¨eÑ4ð ×ÑÐr   c                 ó|   • U R                   R                  U5      n[        U R                  US   -
  S5      U l        g)zÀProcesses 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¤   r   N)rœ   ÚpopÚmaxr�   )r   r    Úscheduled_retrys      r   r�   Ú2ConsumptionScheduler.process_scheduled_consumptionZ  s=   € ð ×?Ñ?×CÑCÀEÓJˆÜØ×Ñ˜Ð/@ÑAÑAÀ1ó
ˆÕr   r›   N)	r   r   r   r   r
   r�   r“   r�   r   r   r   r   r{   r{   1  s   † òò
>ò õ4

r   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	)ry   ig  c                 ó,   • Xl         SU l        SU l        g)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                 ó6   • U R                   c  gU R                  $ )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                 ó@   • U R                   c  gU R                  X5      $ )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                 ór   • U R                   c  X l         SU l        gU R                  X5      U l        X l         g)zÝRecord 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;   € ð �?‰?Ñ"Ø1ŒOØ!$ˆDÔØØ!×LÑLØó
ˆÔð .�r   c                 óH   • X R                   -
  nUS::  a  [        S5      $ X-  $ )Nr   Úinf)r®   rs   )r   r‡   r¹   Ú
time_deltas       r   Ú_calculate_rateÚ$BandwidthRateTracker._calculate_rate§  s*   € Ø(¯?©?Ñ:ˆ
Ø˜‹?ô
 ˜“<ÐØÑ!Ð!r   c                 ó|   • U R                  X5      nU R                  U-  SU R                  -
  U R                  -  -   $ )Né   )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   r   ry   ry   g  s0   † ô"ð  ñ"ó ð"ò
ò$.ò$"õOr   ry   )ru   r!   Ú	Exceptionr   r   r   r)   r2   rp   r{   ry   r   r   r   Ú<module>rÈ      sk   ðó Û ô˜yô ÷(	ñ 	÷!ñ !÷$#ñ #÷Lnñ n÷bZñ Z÷z3
ñ 3
÷lNOò NOr   