Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/s3transfer/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/s3transfer/__pycache__/bandwidth.cpython-38.pyc
U

P��g�<�@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|�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
        zRequest amount z) exceeded the amount available. Retry in N)�
requested_amt�
retry_time�super�__init__)�selfrr�msg��	__class__��A/opt/cppython/lib/python3.8/site-packages/s3transfer/bandwidth.pyrs
z!RequestExceededException.__init__)�__name__�
__module__�__qualname__r�
__classcell__rrr	rrsrc@seZdZdZdS)�RequestTokenzDA token to pass as an identifier when consuming from the LeakyBucketN)r
rr�__doc__rrrrr%src@seZdZdd�Zdd�ZdS)�	TimeUtilscCst��S)zgGet the current time back

        :rtype: float
        :returns: The current time in seconds
        )�time�rrrr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�valuerrrr4szTimeUtils.sleepN)r
rrrrrrrrr+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_utilsrrr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�streamrrr�get_bandwith_limited_streamLs�z,BandwidthLimiter.get_bandwith_limited_stream)N)T)r
rrrr#rrrrr=s
�rc@speZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	ddd�Z
dd�Zdd�Zdd�Z
dd�ZdS)rN�cCsF||_||_||_||_|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)rrrr rZbytes_thresholdrrrrdszBandwidthLimitedStream.__init__cCs
d|_dS)z0Enable bandwidth limiting on reads to the streamTN�r'rrrr�enable_bandwidth_limiting�sz0BandwidthLimitedStream.enable_bandwidth_limitingcCs
d|_dS)z1Disable bandwidth limiting on reads to the streamFNr+rrrrr�sz1BandwidthLimitedStream.disable_bandwidth_limitingcCsL|js|j�|�S|j|7_|j|jkr8|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�amountrrrr-�szBandwidthLimitedStream.readc
Csf|jjsZz|j�|j|j�d|_WdStk
rV}z|j�|j	�W5d}~XYqXq|jj�dS)Nr)
r&�	exceptionr�consumer)r(rrrr)r�errrr.�s�"z4BandwidthLimitedStream._consume_through_leaky_bucketcCs|��dS)z6Signal that data being read is being transferred to S3N)r,rrrr�signal_transferring�sz*BandwidthLimitedStream.signal_transferringcCs|��dS)z:Signal that data being read is not being transferred to S3N)rrrrr�signal_not_transferring�sz.BandwidthLimitedStream.signal_not_transferringrcCs|j�||�dS�N)r%�seek)r�where�whencerrrr6�szBandwidthLimitedStream.seekcCs
|j��Sr5)r%�tellrrrrr9�szBandwidthLimitedStream.tellcCs"|jr|jr|��|j��dSr5)r'r)r.r%�closerrrrr:�szBandwidthLimitedStream.closecCs|Sr5rrrrr�	__enter__�sz BandwidthLimitedStream.__enter__cOs|��dSr5)r:)r�args�kwargsrrr�__exit__�szBandwidthLimitedStream.__exit__)Nr$)r)r
rrrr,rr-r.r3r4r6r9r:r;r>rrrrrcs�
#

rc@s>eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�LeakyBucketNcCsZt|�|_||_|dkr t�|_t��|_||_|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�	threading�Lock�_lock�
_rate_tracker�BandwidthRateTracker�_consumption_scheduler�ConsumptionScheduler)rZmax_raterZrate_trackerZconsumption_schedulerrrrr�s

zLeakyBucket.__init__c
Csz|j�j|j��}|j�|�r8|�|||�W5QR�S|�||�rT|�|||�n|�||�W5QR�SW5QRXdS)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)	rDrrrG�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_nowrrrr1�s
��zLeakyBucket.consumecCs|j�||�}||jkSr5)rE�get_projected_raterA)rrOrQZprojected_raterrrrKsz)LeakyBucket._projected_to_exceed_max_ratecCs|j�|�|�||�Sr5)rG�process_scheduled_consumptionrMrNrrrrJs�z8LeakyBucket._release_requested_amt_for_scheduled_requestcCs.|t|j�}|j�|||�}t||d��dS)N)rr)r@rArG�schedule_consumptionr)rrOrPrQZallocated_timerrrrrL#s��z-LeakyBucket._raise_request_exceeded_exceptioncCs|j�||�|Sr5)rE�record_consumption_rate)rrOrQrrrrM,sz"LeakyBucket._release_requested_amt)NNN)	r
rrrr1rKrJrLrMrrrrr?�s�
#	r?c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rHcCsi|_d|_dS)z*Schedules when to consume a desired amountrN)� _tokens_to_scheduled_consumption�_total_waitrrrrr2szConsumptionScheduler.__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.
        )rV)r�tokenrrrrI7sz!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)rWrV)rrOrXrYrrrrT@s
�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.
        rYrN)rV�pop�maxrW)rrXZscheduled_retryrrrrSZs
�z2ConsumptionScheduler.process_scheduled_consumptionN)r
rrrrIrTrSrrrrrH1s	rHc@sBeZdZddd�Zedd��Zdd�Zdd	�Zd
d�Zdd
�Z	dS)rF皙�����?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�alpharrrrhszBandwidthRateTracker.__init__cCs|jdkrdS|jS)zmThe current transfer rate

        :rtype: float
        :returns: The current tracked transfer rate
        N�)r^r_rrrr�current_ratexs
z!BandwidthRateTracker.current_ratecCs|jdkrdS|�||�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
        Nra)r^�*_calculate_exponential_moving_average_rate�rrO�time_at_consumptionrrrrR�s
�z'BandwidthRateTracker.get_projected_ratecCs2|jdkr||_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
        Nra)r^r_rcrdrrrrU�s	
�z,BandwidthRateTracker.record_consumption_ratecCs"||j}|dkrtd�S||S)Nr�inf)r^r@)rrOreZ
time_deltarrr�_calculate_rate�s
z$BandwidthRateTracker._calculate_ratecCs&|�||�}|j|d|j|jS)N�)rgr]r_)rrOreZnew_raterrrrc�sz?BandwidthRateTracker._calculate_exponential_moving_average_rateN)r\)
r
rrr�propertyrbrRrUrgrcrrrrrFgs



rF)rBr�	Exceptionrrrrrr?rHrFrrrr�<module>
s&q]6

F1le Man4ger