Ë
    £ªðió<  ã                   ó¶   — d dl Z d dlZ G d„ de«      Z G d„ d«      Z G d„ d«      Z G d„ d	«      Z G d
„ d«      Z G d„ d«      Z G d„ d«      Z	 G d„ d«      Z
y)é    Nc                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )ÚRequestExceededExceptionc                 óP   •— || _         || _        d|› d|› �}t        ‰| �  |«       y)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       €úk/var/www/acinvestment.org/public_html/aci/backend/venv/lib/python3.12/site-packages/s3transfer/bandwidth.pyr	   z!RequestExceededException.__init__   s6   ø€ ð +ˆÔØ$ˆŒØ ˜Ð.WÐXbÐWcÐdˆÜ‰Ñ˜Õó    )Ú__name__Ú
__module__Ú__qualname__r	   Ú__classcell__)r   s   @r   r   r      s   ø„ ÷ð r   r   c                   ó   — e Zd ZdZy)ÚRequestTokenzDA token to pass as an identifier when consuming from the LeakyBucketN)r   r   r   Ú__doc__© r   r   r   r   %   s   „ ÙNàr   r   c                   ó   — e Zd Zd„ Zd„ Zy)Ú	TimeUtilsc                 ó*   — t        j                   «       S )zgGet the current time back

        :rtype: float
        :returns: The current time in seconds
        )Útime©r
   s    r   r   zTimeUtils.time,   s   € ô �y‰y‹{Ðr   c                 ó,   — t        j                  |«      S )zwSleep for a designated time

        :type value: float
        :param value: The time to sleep for in seconds
        )r   Úsleep)r
   Úvalues     r   r   zTimeUtils.sleep4   s   € ô �z‰z˜%Ó Ð r   N)r   r   r   r   r   r   r   r   r   r   +   s   „ òó!r   r   c                   ó   — e Zd Zdd„Z	 dd„Zy)ÚBandwidthLimiterNc                 óD   — || _         || _        |€t        «       | _        yy)a  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	   zBandwidthLimiter.__init__>   s)   € ð *ˆÔØ%ˆÔØÐÜ(›{ˆDÕð r   c                 ón   — t        || j                  || j                  «      }|s|j                  «        |S )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_streamz,BandwidthLimiter.get_bandwith_limited_streamL   s:   € ô (Ø�T×'Ñ'Ð)=¸t×?OÑ?Oó
ˆñ Ø×-Ñ-Ô/Øˆr   ©N)T)r   r   r   r	   r-   r   r   r   r    r    =   s   „ ó+ð 6:ôr   r    c                   ó\   — e Zd Z	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dd	„Z
d
„ Zd„ Zd„ Zd„ Zy)r'   Nc                 ó¦   — || _         || _        || _        || _        |€t	        «       | _        d| _        t        «       | _        d| _        || _	        y)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
   r)   r$   r*   r%   Úbytes_thresholds         r   r	   zBandwidthLimitedStream.__init__d   sU   € ð0  ˆŒØ)ˆÔØ%9ˆÔ"Ø%ˆÔØÐÜ(›{ˆDÔØ+/ˆÔ(Ü*›nˆÔØˆÔØ /ˆÕr   c                 ó   — d| _         y)z0Enable bandwidth limiting on reads to the streamTN©r3   r   s    r   Úenable_bandwidth_limitingz0BandwidthLimitedStream.enable_bandwidth_limiting‡   s
   € à+/ˆÕ(r   c                 ó   — d| _         y)z1Disable bandwidth limiting on reads to the streamFNr9   r   s    r   r(   z1BandwidthLimitedStream.disable_bandwidth_limiting‹   s
   € à+0ˆÕ(r   c                 ó8  — | j                   s| j                  j                  |«      S | xj                  |z  c_        | j                  | j                  k  r| j                  j                  |«      S | j                  «        | j                  j                  |«      S )zhRead a specified amount

        Reads will only be throttled if bandwidth limiting is enabled.
        )r3   r1   Úreadr5   r6   Ú_consume_through_leaky_bucket)r
   Úamounts     r   r=   zBandwidthLimitedStream.read�   s   € ð
 ×/Ò/Ø—=‘=×%Ñ% fÓ-Ð-ð 	×Ò˜FÑ"ÕØ×Ñ˜d×3Ñ3Ò3Ø—=‘=×%Ñ% fÓ-Ð-à×*Ñ*Ô,Ø�}‰}×!Ñ! &Ó)Ð)r   c                 ór  — | j                   j                  s9	 | j                  j                  | j                  | j
                  «       d| _        y | j                   j                  ‚# t        $ r/}| j                  j                  |j                  «       Y d }~nd }~ww xY w| j                   j                  sŒ¡Œi)Nr   )
r2   Ú	exceptionr"   Úconsumer5   r4   r   r#   r   r   )r
   Úes     r   r>   z4BandwidthLimitedStream._consume_through_leaky_bucket£   s�   € ð ×,Ñ,×6Ò6ð5Ø×"Ñ"×*Ñ*Ø×$Ñ$ d×&9Ñ&9ôð $%�Ô Øð ×,Ñ,×6Ñ6Ð6øô ,ò 5Ø× Ñ ×&Ñ& q§|¡|×4Ñ4ûð5úð ×,Ñ,×6Ó6øs   ˜7A& Á&	BÁ/%BÂBc                 ó$   — | j                  «        y)z6Signal that data being read is being transferred to S3N)r:   r   s    r   Úsignal_transferringz*BandwidthLimitedStream.signal_transferringµ   s   € à×&Ñ&Õ(r   c                 ó$   — | j                  «        y)z:Signal that data being read is not being transferred to S3N)r(   r   s    r   Úsignal_not_transferringz.BandwidthLimitedStream.signal_not_transferring¹   s   € à×'Ñ'Õ)r   c                 ó<   — | j                   j                  ||«       y r.   )r1   Úseek)r
   ÚwhereÚwhences      r   rI   zBandwidthLimitedStream.seek½   s   € Ø�‰×Ñ˜5 &Õ)r   c                 ó6   — | j                   j                  «       S r.   )r1   Útellr   s    r   rM   zBandwidthLimitedStream.tellÀ   s   € Ø�}‰}×!Ñ!Ó#Ð#r   c                 óˆ   — | j                   r| j                  r| j                  «        | j                  j	                  «        y r.   )r3   r5   r>   r1   Úcloser   s    r   rO   zBandwidthLimitedStream.closeÃ   s1   € Ø×+Ò+°×0@Ò0@ð ×.Ñ.Ô0Ø�‰×ÑÕr   c                 ó   — | S r.   r   r   s    r   Ú	__enter__z BandwidthLimitedStream.__enter__Í   s   € Øˆr   c                 ó$   — | j                  «        y r.   )rO   )r
   ÚargsÚkwargss      r   Ú__exit__zBandwidthLimitedStream.__exit__Ð   s   € Ø�
‰
�r   )Ni   )r   )r   r   r   r	   r:   r(   r=   r>   rE   rG   rI   rM   rO   rQ   rU   r   r   r   r'   r'   c   sG   „ ð Ø"ó!0òF0ò1ò*ò(7ò$)ò*ó*ò$òòór   r'   c                   ó8   — e Zd Z	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zy)	ÚLeakyBucketNc                 óè   — t        |«      | _        || _        |€t        «       | _        t	        j
                  «       | _        || _        |€t        «       | _        || _	        |€t        «       | _	        yy)a9  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	   zLeakyBucket.__init__Õ   sl   € ô. ˜x›ˆŒØ%ˆÔØÐÜ(›{ˆDÔÜ—^‘^Ó%ˆŒ
Ø)ˆÔØÐÜ!5Ó!7ˆDÔØ&;ˆÔ#Ø Ð(Ü*>Ó*@ˆDÕ'ð )r   c                 ól  — | j                   5  | j                  j                  «       }| j                  j	                  |«      r| j                  |||«      cddd«       S | j                  ||«      r| j                  |||«       n| j                  ||«      cddd«       S 	 ddd«       y# 1 sw Y   yxY w)ac  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   r`   Ú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   rB   zLeakyBucket.consumeø   s·   € ð$ �Z‰Zñ 	BØ×'Ñ'×,Ñ,Ó.ˆHØ×*Ñ*×7Ñ7¸ÔFØ×HÑHØ˜¨ó÷	Bñ 	Bð ×3Ñ3°C¸ÔBØ×6Ñ6Ø˜¨õð ×2Ñ2°3¸ÓA÷	Bñ 	Bð÷	B÷ 	Bñ 	Bús   �AB*Á7B*Â*B3c                 óX   — | j                   j                  ||«      }|| j                  kD  S r.   )r^   Úget_projected_raterZ   )r
   rl   rn   Úprojected_rates       r   rh   z)LeakyBucket._projected_to_exceed_max_rate  s)   € Ø×+Ñ+×>Ñ>¸sÀHÓMˆØ §¡Ñ.Ð.r   c                 ó\   — | j                   j                  |«       | j                  ||«      S r.   )r`   Úprocess_scheduled_consumptionrj   rk   s       r   rg   z8LeakyBucket._release_requested_amt_for_scheduled_request  s0   € ð 	×#Ñ#×AÑAØô	
ð ×*Ñ*¨3°Ó9Ð9r   c                 ó†   — |t        | j                  «      z  }| j                  j                  |||«      }t	        ||¬«      ‚)N)r   r   )rY   rZ   r`   Úschedule_consumptionr   )r
   rl   rm   rn   Úallocated_timer   s         r   ri   z-LeakyBucket._raise_request_exceeded_exception#  sF   € Øœu T§^¡^Ó4Ñ4ˆØ×0Ñ0×EÑEØ� ó
ˆ
ô 'Ø¨*ô
ð 	
r   c                 ó>   — | j                   j                  ||«       |S r.   )r^   Úrecord_consumption_rate)r
   rl   rn   s      r   rj   z"LeakyBucket._release_requested_amt,  s   € Ø×Ñ×2Ñ2°3¸ÔAØˆ
r   )NNN)	r   r   r   r	   rB   rh   rg   ri   rj   r   r   r   rW   rW   Ô   s.   „ ð ØØ"ó!AòFBò>/ò:ò
ór   rW   c                   ó$   — e Zd Zd„ Zd„ Zd„ Zd„ Zy)ra   c                 ó    — i | _         d| _        y)z*Schedules when to consume a desired amountr   N)Ú _tokens_to_scheduled_consumptionÚ_total_waitr   s    r   r	   zConsumptionScheduler.__init__2  s   € à02ˆÔ-ØˆÕr   c                 ó   — || j                   v S )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   rf   z!ConsumptionScheduler.is_scheduled7  s   € ð ˜×=Ñ=Ð=Ð=r   c                 ó|   — | xj                   |z  c_         | j                   |dœ| j                  |<   | j                   S )a´  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
   rl   r~   r�   s       r   ru   z)ConsumptionScheduler.schedule_consumption@  sA   € ð& 	×Ò˜OÑ+Õà!×-Ñ-Ø.ñ8
ˆ×-Ñ-¨eÑ4ð ×ÑÐr   c                 ó|   — | j                   j                  |«      }t        | j                  |d   z
  d«      | _        y)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   rs   z2ConsumptionScheduler.process_scheduled_consumptionZ  s=   € ð ×?Ñ?×CÑCÀEÓJˆÜØ×Ñ˜Ð/@ÑAÑAÀ1ó
ˆÕr   N)r   r   r   r	   rf   ru   rs   r   r   r   ra   ra   1  s   „ òò
>ò ó4

r   ra   c                   ó<   — e Zd Zdd„Zed„ «       Zd„ Zd„ Zd„ Zd„ Z	y)	r_   c                 ó.   — || _         d| _        d| _        y)a’  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	   zBandwidthRateTracker.__init__h  s   € ð ˆŒØˆŒØ!ˆÕr   c                 ó4   — | j                   €y| j                  S )zmThe current transfer rate

        :rtype: float
        :returns: The current tracked transfer rate
        ç        )r‰   rŠ   r   s    r   Úcurrent_ratez!BandwidthRateTracker.current_ratex  s   € ð �?‰?Ð"ØØ×!Ñ!Ð!r   c                 ó@   — | j                   €y| j                  ||«      S )aZ  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
   rl   Útime_at_consumptions      r   rp   z'BandwidthRateTracker.get_projected_rateƒ  s*   € ð �?‰?Ð"ØØ×>Ñ>ØÐ$ó
ð 	
r   c                 óv   — | j                   €|| _         d| _        y| j                  ||«      | _        || _         y)a  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   rx   z,BandwidthRateTracker.record_consumption_rate•  sB   € ð �?‰?Ð"Ø1ˆDŒOØ!$ˆDÔØØ!×LÑLØÐ$ó
ˆÔð .ˆ�r   c                 óJ   — || j                   z
  }|dk  rt        d«      S ||z  S )Nr   Úinf)r‰   rY   )r
   rl   r’   Ú
time_deltas       r   Ú_calculate_ratez$BandwidthRateTracker._calculate_rate§  s.   € Ø(¨4¯?©?Ñ:ˆ
Ø˜Š?ô
 ˜“<ÐØ�jÑ!Ð!r   c                 ó~   — | j                  ||«      }| j                  |z  d| j                  z
  | j                  z  z   S )Né   )r—   rˆ   rŠ   )r
   rl   r’   Únew_rates       r   r�   z?BandwidthRateTracker._calculate_exponential_moving_average_rate±  s>   € ð ×'Ñ'¨Ð-@ÓAˆØ�{‰{˜XÑ%¨¨T¯[©[©¸D×<NÑ<NÑ(NÑNÐNr   N)gš™™™™™é?)
r   r   r   r	   ÚpropertyrŽ   rp   rx   r—   r�   r   r   r   r_   r_   g  s0   „ ó"ð  ñ"ó ð"ò
ò$.ò$"óOr   r_   )r[   r   Ú	Exceptionr   r   r   r    r'   rW   ra   r_   r   r   r   ú<module>r�      sk   ðó Û ô˜yô ÷(	ñ 	÷!ñ !÷$#ñ #÷Lnñ n÷bZñ Z÷z3
ñ 3
÷lNOò NOr   