HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/s3transfer/__pycache__/bandwidth.cpython-36.pyc
3

\��_=�@s�ddlZddlZGdd�de�ZGdd�de�ZGdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Z	Gdd�de�Z
Gdd�de�ZdS)�NcseZdZ�fdd�Z�ZS)�RequestExceededExceptioncs,||_||_d||f}tt|�j|�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 %s exceeded the amount available. Retry in %sN)�
requested_amt�
retry_time�superr�__init__)�selfrr�msg)�	__class__��/usr/lib/python3.6/bandwidth.pyrs


z!RequestExceededException.__init__)�__name__�
__module__�__qualname__r�
__classcell__r
r
)r	rrsrc@seZdZdZdS)�RequestTokenzDA token to pass as an identifier when consuming from the LeakyBucketN)rr
r�__doc__r
r
r
rr(src@seZdZdd�Zdd�ZdS)�	TimeUtilscCstj�S)zgGet the current time back

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

        :type value: float
        :param value: The time to sleep for in seconds
        )r�sleep)r�valuer
r
rr6szTimeUtils.sleepN)rr
rrrr
r
r
rr-src@s eZdZddd�Zddd�ZdS)	�BandwidthLimiterNcCs ||_||_|dkrt�|_dS)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
rr@s	zBandwidthLimiter.__init__TcCs"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
        )�BandwidthLimitedStreamrr�disable_bandwidth_limiting)r�fileobj�transfer_coordinatorZenabled�streamr
r
r�get_bandwith_limited_streamNsz,BandwidthLimiter.get_bandwith_limited_stream)N)T)rr
rrr r
r
r
rr?s
rc@sneZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)rN�icCsF||_||_||_||_|dkr(t�|_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)rrrrrZbytes_thresholdr
r
rreszBandwidthLimitedStream.__init__cCs
d|_dS)z0Enable bandwidth limiting on reads to the streamTN)r$)rr
r
r�enable_bandwidth_limiting�sz0BandwidthLimitedStream.enable_bandwidth_limitingcCs
d|_dS)z1Disable bandwidth limiting on reads to the streamFN)r$)rr
r
rr�sz1BandwidthLimitedStream.disable_bandwidth_limitingcCsL|js|jj|�S|j|7_|j|jkr8|jj|�S|j�|jj|�S)zhRead a specified amount

        Reads will only be throttled if bandwidth limiting is enabled.
        )r$r"�readr&r'�_consume_through_leaky_bucket)rZamountr
r
rr)�szBandwidthLimitedStream.readcCshxb|jjsZy|jj|j|j�d|_dStk
rV}z|jj|j	�WYdd}~XqXqW|jj�dS)Nr)
r#Z	exceptionr�consumer&r%rrrr)r�er
r
rr*�s
$z4BandwidthLimitedStream._consume_through_leaky_bucketcCs|j�dS)z6Signal that data being read is being transferred to S3N)r()rr
r
r�signal_transferring�sz*BandwidthLimitedStream.signal_transferringcCs|j�dS)z:Signal that data being read is not being transferred to S3N)r)rr
r
r�signal_not_transferring�sz.BandwidthLimitedStream.signal_not_transferringcCs|jj|�dS)N)r"�seek)r�wherer
r
rr/�szBandwidthLimitedStream.seekcCs
|jj�S)N)r"�tell)rr
r
rr1�szBandwidthLimitedStream.tellcCs"|jr|jr|j�|jj�dS)N)r$r&r*r"�close)rr
r
rr2�szBandwidthLimitedStream.closecCs|S)Nr
)rr
r
r�	__enter__�sz BandwidthLimitedStream.__enter__cOs|j�dS)N)r2)r�args�kwargsr
r
r�__exit__�szBandwidthLimitedStream.__exit__�)Nr7)rr
rrr(rr)r*r-r.r/r1r2r3r6r
r
r
rrds

rc@s>eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�LeakyBucketNcCsZt|�|_||_|dkr t�|_tj�|_||_|dkr@t�|_||_	|dkrVt
�|_	dS)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�	threadingZLock�_lock�
_rate_tracker�BandwidthRateTracker�_consumption_scheduler�ConsumptionScheduler)rZmax_raterZrate_trackerZconsumption_schedulerr
r
rr�s

zLeakyBucket.__init__cCsb|j�R|jj�}|jj|�r,|j|||�S|j||�rH|j|||�n|j||�SWdQRXdS)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)	r<rrr?�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
rr+�s

zLeakyBucket.consumecCs|jj||�}||jkS)N)r=�get_projected_rater:)rrFrHZprojected_rater
r
rrC
sz)LeakyBucket._projected_to_exceed_max_ratecCs|jj|�|j||�S)N)r?�process_scheduled_consumptionrE)rrFrGrHr
r
rrBsz8LeakyBucket._release_requested_amt_for_scheduled_requestcCs.|t|j�}|jj|||�}t||d��dS)N)rr)r9r:r?�schedule_consumptionr)rrFrGrHZallocated_timerr
r
rrDs

z-LeakyBucket._raise_request_exceeded_exceptioncCs|jj||�|S)N)r=�record_consumption_rate)rrFrHr
r
rrEsz"LeakyBucket._release_requested_amt)NNN)	rr
rrr+rCrBrDrEr
r
r
rr8�s
r8c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r@cCsi|_d|_dS)z*Schedules when to consume a desired amountrN)� _tokens_to_scheduled_consumption�_total_wait)rr
r
rr!szConsumptionScheduler.__init__cCs
||jkS)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.
        )rM)r�tokenr
r
rrA&sz!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.
        )Z
wait_duration�time_to_consume)rNrM)rrFrOrPr
r
rrK/sz)ConsumptionScheduler.schedule_consumptioncCs&|jj|�}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.
        rPrN)rM�pop�maxrN)rrOZscheduled_retryr
r
rrJIsz2ConsumptionScheduler.process_scheduled_consumptionN)rr
rrrArKrJr
r
r
rr@ s	r@c@sBeZdZddd�Zedd��Zdd�Zdd	�Zd
d�Zdd
�Z	dS)r>皙�����?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)rZalphar
r
rrVszBandwidthRateTracker.__init__cCs|jdkrdS|jS)zmThe current transfer rate

        :rtype: float
        :returns: The current tracked transfer rate
        Ng)rUrV)rr
r
r�current_ratefs
z!BandwidthRateTracker.current_ratecCs|jdkrdS|j||�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
        Ng)rU�*_calculate_exponential_moving_average_rate)rrF�time_at_consumptionr
r
rrIqs
z'BandwidthRateTracker.get_projected_ratecCs2|jdkr||_d|_dS|j||�|_||_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
        Ng)rUrVrX)rrFrYr
r
rrL�s	

z,BandwidthRateTracker.record_consumption_ratecCs"||j}|dkrtd�S||S)Nr�inf)rUr9)rrFrYZ
time_deltar
r
r�_calculate_rate�s
z$BandwidthRateTracker._calculate_ratecCs&|j||�}|j|d|j|jS)N�)r[rTrV)rrFrYZnew_rater
r
rrX�sz?BandwidthRateTracker._calculate_exponential_moving_average_rateN)rS)
rr
rr�propertyrWrIrLr[rXr
r
r
rr>Us

r>)rr;�	Exceptionr�objectrrrrr8r@r>r
r
r
r�<module>
s%jR5