HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/s3transfer/__pycache__/bandwidth.cpython-310.pyc
o

�h=�@s�ddlZddlZGdd�de�ZGdd�d�ZGdd�d�ZGdd	�d	�ZGd
d�d�ZGdd
�d
�ZGdd�d�Z	Gdd�d�Z
dS)�NcseZdZ�fdd�Z�ZS)�RequestExceededExceptioncs(||_||_d�||�}t��|�dS)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 {} exceeded the amount available. Retry in {}N)�
requested_amt�
retry_time�format�super�__init__)�selfrr�msg��	__class__��G/usr/local/CyberCP/lib/python3.10/site-packages/s3transfer/bandwidth.pyrs
�z!RequestExceededException.__init__)�__name__�
__module__�__qualname__r�
__classcell__rrr
r
rsrc@seZdZdZdS)�RequestTokenzDA token to pass as an identifier when consuming from the LeakyBucketN)rrr�__doc__rrrr
r'src@seZdZdd�Zdd�ZdS)�	TimeUtilscCst��S)zgGet the current time back

        :rtype: float
        :returns: The current time in seconds
        )�time�rrrr
r.szTimeUtils.timecCs
t�|�S)zwSleep for a designated time

        :type value: float
        :param value: The time to sleep for in seconds
        )r�sleep)r�valuerrr
r6s
zTimeUtils.sleepN)rrrrrrrrr
r-src@s"eZdZddd�Z	ddd�ZdS)	�BandwidthLimiterNcCs$||_||_|durt�|_dSdS)aLimits 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_utilsrrr
r@s
	�zBandwidthLimiter.__init__TcCs"t||j||j�}|s|��|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
        )�BandwidthLimitedStreamrr�disable_bandwidth_limiting)r�fileobj�transfer_coordinator�enabled�streamrrr
�get_bandwith_limited_streamNs�z,BandwidthLimiter.get_bandwith_limited_stream�N)T)rrrrr$rrrr
r?s
�rc@steZdZ		ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	ddd�Z
dd�Zdd�Zdd�Z
dd�ZdS)rN�cCsF||_||_||_||_|durt�|_d|_t�|_d|_||_	dS)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_coordinatorrr�_bandwidth_limiting_enabledr�_request_token�_bytes_seen�_bytes_threshold)rr rr!r�bytes_thresholdrrr
rfs
zBandwidthLimitedStream.__init__cC�
d|_dS)z0Enable bandwidth limiting on reads to the streamTN�r)rrrr
�enable_bandwidth_limiting��
z0BandwidthLimitedStream.enable_bandwidth_limitingcCr.)z1Disable bandwidth limiting on reads to the streamFNr/rrrr
r�r1z1BandwidthLimitedStream.disable_bandwidth_limitingcCsL|js	|j�|�S|j|7_|j|jkr|j�|�S|��|j�|�S)zhRead a specified amount

        Reads will only be throttled if bandwidth limiting is enabled.
        )r)r'�readr+r,�_consume_through_leaky_bucket)r�amountrrr
r2�szBandwidthLimitedStream.readc
Csj|jjs1z|j�|j|j�d|_WdSty,}z
|j�|j	�WYd}~nd}~ww|jjr|jj�)Nr)
r(�	exceptionr�consumer+r*rrrr)r�errr
r3�s����
z4BandwidthLimitedStream._consume_through_leaky_bucketcC�|��dS)z6Signal that data being read is being transferred to S3N)r0rrrr
�signal_transferring��z*BandwidthLimitedStream.signal_transferringcCr8)z:Signal that data being read is not being transferred to S3N)rrrrr
�signal_not_transferring�r:z.BandwidthLimitedStream.signal_not_transferringrcCs|j�||�dSr%)r'�seek)r�where�whencerrr
r<�szBandwidthLimitedStream.seekcCs
|j��Sr%)r'�tellrrrr
r?�s
zBandwidthLimitedStream.tellcCs"|jr
|jr
|��|j��dSr%)r)r+r3r'�closerrrr
r@�szBandwidthLimitedStream.closecCs|Sr%rrrrr
�	__enter__�sz BandwidthLimitedStream.__enter__cOs|��dSr%)r@)r�args�kwargsrrr
�__exit__�szBandwidthLimitedStream.__exit__)Nr&)r)rrrrr0rr2r3r9r;r<r?r@rArDrrrr
res
�#

rc@sDeZdZ			ddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�LeakyBucketNcCs^t|�|_||_|durt�|_t��|_||_|dur t�|_||_	|dur-t
�|_	dSdS)a9A 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_raterr�	threading�Lock�_lock�
_rate_tracker�BandwidthRateTracker�_consumption_scheduler�ConsumptionScheduler)r�max_rater�rate_tracker�consumption_schedulerrrr
r�s

�zLeakyBucket.__init__cCs�|j�=|j��}|j�|�r|�|||�Wd�S|�||�r+|�|||�n
|�||�Wd�SWd�dS1sCwYdS)acConsume 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)	rJrrrM�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_nowrrr
r6�s
���
�"�zLeakyBucket.consumecCs|j�||�}||jkSr%)rK�get_projected_raterG)rrXrZ�projected_raterrr
rTs
z)LeakyBucket._projected_to_exceed_max_ratecCs|j�|�|�||�Sr%)rM�process_scheduled_consumptionrVrWrrr
rSs�z8LeakyBucket._release_requested_amt_for_scheduled_requestcCs*|t|j�}|j�|||�}t||d��)N)rr)rFrGrM�schedule_consumptionr)rrXrYrZ�allocated_timerrrr
rU%s��z-LeakyBucket._raise_request_exceeded_exceptioncCs|j�||�|Sr%)rK�record_consumption_rate)rrXrZrrr
rV.sz"LeakyBucket._release_requested_amt)NNN)	rrrrr6rTrSrUrVrrrr
rE�s
�#	rEc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rNcCsi|_d|_dS)z*Schedules when to consume a desired amountrN)� _tokens_to_scheduled_consumption�_total_waitrrrr
r4s
zConsumptionScheduler.__init__cCs
||jvS)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.
        )ra)r�tokenrrr
rR9s
z!ConsumptionScheduler.is_scheduledcCs&|j|7_|j|d�|j|<|jS)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)rbra)rrXrcrerrr
r^Bs
�z)ConsumptionScheduler.schedule_consumptioncCs&|j�|�}t|j|dd�|_dS)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.
        rerN)ra�pop�maxrb)rrc�scheduled_retryrrr
r]\s
�z2ConsumptionScheduler.process_scheduled_consumptionN)rrrrrRr^r]rrrr
rN3s
	rNc@sBeZdZddd�Zedd��Zdd�Zdd	�Zd
d�Zdd
�Z	dS)rL皙�����?cCs||_d|_d|_dS)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�alpharrr
rjs
zBandwidthRateTracker.__init__cCs|jdurdS|jS)zmThe current transfer rate

        :rtype: float
        :returns: The current tracked transfer rate
        N�)rkrlrrrr
�current_ratezs
z!BandwidthRateTracker.current_ratecCs|jdurdS|�||�S)aZGet 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
        Nrn)rk�*_calculate_exponential_moving_average_rate�rrX�time_at_consumptionrrr
r[�s

�z'BandwidthRateTracker.get_projected_ratecCs2|jdur
||_d|_dS|�||�|_||_dS)aRecord 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
        Nrn)rkrlrprqrrr
r`�s
	�
z,BandwidthRateTracker.record_consumption_ratecCs"||j}|dkr
td�S||S)Nr�inf)rkrF)rrXrr�
time_deltarrr
�_calculate_rate�s
z$BandwidthRateTracker._calculate_ratecCs&|�||�}|j|d|j|jS)N�)rurjrl)rrXrr�new_raterrr
rp�sz?BandwidthRateTracker._calculate_exponential_moving_average_rateN)ri)
rrrr�propertyror[r`rurprrrr
rLis



rL)rHr�	ExceptionrrrrrrErNrLrrrr
�<module>s&q]6