Ë
    Ø<óe=  ã                   ó¶   — 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                 ód   •— || _         || _        dj                  ||«      }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 {} exceeded the amount available. Retry in {}N)Úrequested_amtÚ
retry_timeÚformatÚsuperÚ__init__)Úselfr   r   ÚmsgÚ	__class__s       €ú6/usr/lib/python3/dist-packages/s3transfer/bandwidth.pyr
   z!RequestExceededException.__init__   s8   ø€ ð +ˆÔØ$ˆŒØL×SÑSØ˜:ó
ˆô 	‰Ñ˜Õó    )Ú__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.sleep6   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_streamN   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__f   sU   € ð0  ˆŒØ)ˆÔØ%9ˆÔ"Ø%ˆÔØÐÜ(›{ˆDÔØ+/ˆÔ(Ü*›nˆÔØˆÔØ /ˆÕr   c                 ó   — d| _         y)z0Enable bandwidth limiting on reads to the streamTN©r4   r   s    r   Úenable_bandwidth_limitingz0BandwidthLimitedStream.enable_bandwidth_limiting‰   s
   € à+/ˆÕ(r   c                 ó   — d| _         y)z1Disable bandwidth limiting on reads to the streamFNr:   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.
        )r4   r2   Úreadr6   r7   Ú_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   )
r3   Ú	exceptionr#   Úconsumer6   r5   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/   )r2   Úseek)r   ÚwhereÚwhences      r   rJ   zBandwidthLimitedStream.seek¿   s   € Ø�‰×Ñ˜5 &Õ)r   c                 ó6   — | j                   j                  «       S r/   )r2   Útellr   s    r   rN   zBandwidthLimitedStream.tellÂ   s   € Ø�}‰}×!Ñ!Ó#Ð#r   c                 óˆ   — | j                   r| j                  r| j                  «        | j                  j	                  «        y r/   )r4   r6   r?   r2   Úcloser   s    r   rP   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/   )rP   )r   ÚargsÚkwargss      r   Ú__exit__zBandwidthLimitedStream.__exit__Ò   s   € Ø�
‰
�r   )Ni   )r   )r   r   r   r
   r;   r)   r>   r?   rF   rH   rJ   rN   rP   rR   rV   r   r   r   r(   r(   e   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   ra   Ú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   rC   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_rater[   )r   rm   ro   Úprojected_rates       r   ri   z)LeakyBucket._projected_to_exceed_max_rate  s)   € Ø×+Ñ+×>Ñ>¸sÀHÓMˆØ §¡Ñ.Ð.r   c                 ó\   — | j                   j                  |«       | j                  ||«      S r/   )ra   Úprocess_scheduled_consumptionrk   rl   s       r   rh   z8LeakyBucket._release_requested_amt_for_scheduled_request  s0   € ð 	×#Ñ#×AÑAØô	
ð ×*Ñ*¨3°Ó9Ð9r   c                 ó†   — |t        | j                  «      z  }| j                  j                  |||«      }t	        ||¬«      ‚)N)r   r   )rZ   r[   ra   Úschedule_consumptionr   )r   rm   rn   ro   Úallocated_timer   s         r   rj   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   rm   ro   s      r   rk   z"LeakyBucket._release_requested_amt.  s   € Ø×Ñ×2Ñ2°3¸ÔAØˆ
r   )NNN)	r   r   r   r
   rC   ri   rh   rj   rk   r   r   r   rX   rX   Ö   s.   „ ð ØØ"ó!AòFBò>/ò:ò
ór   rX   c                   ó$   — e Zd Zd„ Zd„ Zd„ Zd„ Zy)rb   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__4  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   rg   z!ConsumptionScheduler.is_scheduled9  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   rm   r   r‚   s       r   rv   z)ConsumptionScheduler.schedule_consumptionB  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   rt   z2ConsumptionScheduler.process_scheduled_consumption\  s=   € ð ×?Ñ?×CÑCÀEÓJˆÜØ×Ñ˜Ð/@ÑAÑAÀ1ó
ˆÕr   N)r   r   r   r
   rg   rv   rt   r   r   r   rb   rb   3  s   „ òò
>ò ó4

r   rb   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__j  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_ratez  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   rm   Útime_at_consumptions      r   rq   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   ry   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Š   rZ   )r   rm   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   rm   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�   rq   ry   r˜   r‘   r   r   r   r`   r`   i  s0   „ ó"ð  ñ"ó ð"ò
ò$.ò$"óOr   r`   )r\   r   Ú	Exceptionr   r   r   r!   r(   rX   rb   r`   r   r   r   ú<module>rž      sk   ðó Û ô˜yô ÷,	ñ 	÷!ñ !÷$#ñ #÷Lnñ n÷bZñ Z÷z3
ñ 3
÷lNOò NOr   