§
    =xÅjó<  ã                   óè   — 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
dS )é    Nc                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )ÚRequestExceededExceptionc                 óv   •— || _         || _        d|› d|› �}t          ¦   «                              |¦  «         dS )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       €úEC:\Projects\Historical\venv\Lib\site-packages\s3transfer/bandwidth.pyr	   z!RequestExceededException.__init__   sH   ø€ ð +ˆÔØ$ˆŒØd ÐdÐdÐXbÐdÐdˆÝ‰Œ×Ò˜ÑÔÐÐÐó    )Ú__name__Ú
__module__Ú__qualname__r	   Ú__classcell__)r   s   @r   r   r      s8   ø€ € € € € ðð ð ð ð ð ð ð ð r   r   c                   ó   — e Zd ZdZdS )ÚRequestTokenzDA token to pass as an identifier when consuming from the LeakyBucketN)r   r   r   Ú__doc__© r   r   r   r   %   s   € € € € € ØNÐNà€Dr   r   c                   ó   — e Zd Zd„ Zd„ ZdS )Ú	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‰{Œ{Ð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˜%Ñ Ô Ð r   N)r   r   r   r   r   r   r   r   r   r   +   s2   € € € € € ðð ð ð!ð !ð !ð !ð !r   r   c                   ó    — e Zd Zdd„Z	 dd„ZdS )ÚBandwidthLimiterNc                 óP   — || _         || _        |€t          ¦   «         | _        dS dS )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__>   s4   € ð *ˆÔØ%ˆÔØÐÝ(™{œ{ˆDÔÐÐð Ðr   Tc                 ój   — 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
        )ÚBandwidthLimitedStreamr"   r#   Údisable_bandwidth_limiting)r
   ÚfileobjÚtransfer_coordinatorÚenabledÚstreams        r   Úget_bandwith_limited_streamz,BandwidthLimiter.get_bandwith_limited_streamL   sD   € õ (Ø�TÔ'Ð)=¸tÔ?Oñ
ô 
ˆð ð 	0Ø×-Ò-Ñ/Ô/Ð/Øˆr   ©N)T)r   r   r   r	   r-   r   r   r   r    r    =   sA   € € € € € ð+ð +ð +ð +ð 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dS )r'   Né   c                 ó¸   — || _         || _        || _        || _        |€t	          ¦   «         | _        d| _        t          ¦   «         | _        d| _        || _	        dS )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   s_   € ð0  ˆŒØ)ˆÔØ%9ˆÔ"Ø%ˆÔØÐÝ(™{œ{ˆDÔØ+/ˆÔ(Ý*™nœnˆÔØˆÔØ /ˆÔÐÐr   c                 ó   — d| _         dS )z0Enable bandwidth limiting on reads to the streamTN©r4   r   s    r   Úenable_bandwidth_limitingz0BandwidthLimitedStream.enable_bandwidth_limiting‡   s   € à+/ˆÔ(Ð(Ð(r   c                 ó   — d| _         dS )z1Disable bandwidth limiting on reads to the streamFNr:   r   s    r   r(   z1BandwidthLimitedStream.disable_bandwidth_limiting‹   s   € à+0ˆÔ(Ð(Ð(r   c                 ó  — | j         s| j                             |¦  «        S | xj        |z  c_        | j        | j        k     r| j                             |¦  «        S |                      ¦   «          | 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                 ó  — | j         j        sq	 | j                             | j        | j        ¦  «         d| _        d S # t          $ r)}| j                             |j	        ¦  «         Y d }~nd }~ww xY w| j         j        ¯q| j         j        ‚)Nr   )
r3   Ú	exceptionr"   Úconsumer6   r5   r   r#   r   r   )r
   Úes     r   r?   z4BandwidthLimitedStream._consume_through_leaky_bucket£   s±   € ð Ô,Ô6ð 
	7ð5ØÔ"×*Ò*ØÔ$ dÔ&9ñô ð ð $%�Ô Ø�øÝ+ð 5ð 5ð 5ØÔ ×&Ò& q¤|Ñ4Ô4Ð4Ð4Ð4Ð4Ð4Ð4øøøøð5øøøð Ô,Ô6ð 
	7ð Ô,Ô6Ð6s   Ž,< ¼
A/ÁA*Á*A/c                 ó.   — |                       ¦   «          dS )z6Signal that data being read is being transferred to S3N)r;   r   s    r   Úsignal_transferringz*BandwidthLimitedStream.signal_transferringµ   s   € à×&Ò&Ñ(Ô(Ð(Ð(Ð(r   c                 ó.   — |                       ¦   «          dS )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   r   c                 ó<   — | j                              ||¦  «         d S r.   )r2   Úseek)r
   ÚwhereÚwhences      r   rJ   zBandwidthLimitedStream.seek½   s    € ØŒ×Ò˜5 &Ñ)Ô)Ð)Ð)Ð)r   c                 ó4   — | j                              ¦   «         S r.   )r2   Útellr   s    r   rN   zBandwidthLimitedStream.tellÀ   s   € ØŒ}×!Ò!Ñ#Ô#Ð#r   c                 ó|   — | j         r| j        r|                      ¦   «          | j                             ¦   «          d S r.   )r4   r6   r?   r2   Úcloser   s    r   rP   zBandwidthLimitedStream.closeÃ   sE   € ØÔ+ð 	1°Ô0@ð 	1ð ×.Ò.Ñ0Ô0Ð0ØŒ×ÒÑÔÐÐÐr   c                 ó   — | S r.   r   r   s    r   Ú	__enter__z BandwidthLimitedStream.__enter__Í   s   € Øˆr   c                 ó.   — |                       ¦   «          d S r.   )rP   )r
   ÚargsÚkwargss      r   Ú__exit__zBandwidthLimitedStream.__exit__Ð   s   € Ø�
Š
‰Œˆˆˆr   )Nr0   )r   )r   r   r   r	   r;   r(   r>   r?   rF   rH   rJ   rN   rP   rR   rV   r   r   r   r'   r'   c   sÛ   € € € € € ð Ø"ð!0ð !0ð !0ð !0ðF0ð 0ð 0ð1ð 1ð 1ð*ð *ð *ð(7ð 7ð 7ð$)ð )ð )ð*ð *ð *ð*ð *ð *ð *ð$ð $ð $ðð ð ðð ð ðð ð ð ð r   r'   c                   ó:   — e Zd Z	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )	ÚLeakyBucketNc                 ó
  — t          |¦  «        | _        || _        |€t          ¦   «         | _        t	          j        ¦   «         | _        || _        |€t          ¦   «         | _        || _	        |€t          ¦   «         | _	        dS dS )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__Õ   s€   € õ. ˜x™œˆŒØ%ˆÔØÐÝ(™{œ{ˆDÔÝ”^Ñ%Ô%ˆŒ
Ø)ˆÔØÐÝ!5Ñ!7Ô!7ˆDÔØ&;ˆÔ#Ø Ð(Ý*>Ñ*@Ô*@ˆDÔ'Ð'Ð'ð )Ð(r   c                 ó”  — | j         5  | j                             ¦   «         }| j                             |¦  «        r#|                      |||¦  «        cddd¦  «         S |                      ||¦  «        r|                      |||¦  «         n"|                      ||¦  «        cddd¦  «         S 	 ddd¦  «         dS # 1 swxY w Y   dS )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ð 	Bð 	BØÔ'×,Ò,Ñ.Ô.ˆHØÔ*×7Ò7¸ÑFÔFð 	BØ×HÒHØ˜¨ñô ð	Bð 	Bð 	Bð 	Bñ 	Bô 	Bð 	Bð 	Bð ×3Ò3°C¸ÑBÔBð BØ×6Ò6Ø˜¨ñô ð ð ð ×2Ò2°3¸ÑAÔAð	Bð 	Bð 	Bð 	Bñ 	Bô 	Bð 	Bð 	Bðð	Bð 	Bð 	Bñ 	Bô 	Bð 	Bð 	Bð 	Bð 	Bð 	Bð 	Bð 	Bøøøð 	Bð 	Bð 	Bð 	Bð 	Bð 	Bs   ˆA
B=ÁAB=Â=CÃCc                 óN   — | j                              ||¦  «        }|| j        k    S r.   )r_   Úget_projected_rater[   )r
   rm   ro   Úprojected_rates       r   ri   z)LeakyBucket._projected_to_exceed_max_rate  s'   € ØÔ+×>Ò>¸sÀHÑMÔMˆØ ¤Ò.Ð.r   c                 ób   — | j                              |¦  «         |                      ||¦  «        S r.   )ra   Úprocess_scheduled_consumptionrk   rl   s       r   rh   z8LeakyBucket._release_requested_amt_for_scheduled_request  s:   € ð 	Ô#×AÒAØñ	
ô 	
ð 	
ð ×*Ò*¨3°Ñ9Ô9Ð9r   c                 óŠ   — |t          | j        ¦  «        z  }| 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#  sS   € Ø�u T¤^Ñ4Ô4Ñ4ˆØÔ0×EÒEØ� ñ
ô 
ˆ
õ 'Ø¨*ð
ñ 
ô 
ð 	
r   c                 ó<   — | j                              ||¦  «         |S r.   )r_   Úrecord_consumption_rate)r
   rm   ro   s      r   rk   z"LeakyBucket._release_requested_amt,  s    € ØÔ×2Ò2°3¸ÑAÔAÐAØˆ
r   )NNN)	r   r   r   r	   rC   ri   rh   rj   rk   r   r   r   rX   rX   Ô   s†   € € € € € ð ØØ"ð!Að !Að !Að !AðFBð Bð Bð>/ð /ð /ð:ð :ð :ð
ð 
ð 
ðð ð ð ð r   rX   c                   ó&   — e Zd Zd„ Zd„ Zd„ Zd„ ZdS )rb   c                 ó"   — i | _         d| _        dS )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   rg   z!ConsumptionScheduler.is_scheduled7  s   € ð ˜Ô=Ð=Ð=r   c                 óT   — | 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_consumption@  s@   € ð& 	ÐÔ˜OÑ+ÐÔà!Ô-Ø.ð8
ð 8
ˆÔ-¨eÑ4ð ÔÐr   c                 ó€   — | j                              |¦  «        }t          | j        |d         z
  d¦  «        | _        dS )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_consumptionZ  sE   € ð Ô?×CÒCÀEÑJÔJˆÝØÔ˜Ð/@ÔAÑAÀ1ñ
ô 
ˆÔÐÐr   N)r   r   r   r	   rg   rv   rt   r   r   r   rb   rb   1  sP   € € € € € ðð ð ð
>ð >ð >ð ð  ð  ð4

ð 

ð 

ð 

ð 

r   rb   c                   óD   — e Zd Zd	d„Zed„ ¦   «         Zd„ Zd„ Zd„ Zd„ Z	dS )
r`   çš™™™™™é?c                 ó0   — || _         d| _        d| _        dS )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                 ó"   — | j         €dS | j        S )zmThe current transfer rate

        :rtype: float
        :returns: The current tracked transfer rate
        Nç        )r‹   rŒ   r   s    r   Úcurrent_ratez!BandwidthRateTracker.current_ratex  s   € ð Œ?Ð"Ø�3ØÔ!Ð!r   c                 ó@   — | j         €dS |                      ||¦  «        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
        Nr�   )r‹   Ú*_calculate_exponential_moving_average_rate©r
   rm   Útime_at_consumptions      r   rq   z'BandwidthRateTracker.get_projected_rateƒ  s/   € ð Œ?Ð"Ø�3Ø×>Ò>ØÐ$ñ
ô 
ð 	
r   c                 óx   — | j         €|| _         d| _        dS |                      ||¦  «        | _        || _         dS )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•  sK   € ð Œ?Ð"Ø1ˆDŒOØ!$ˆDÔØˆFØ!×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§  s0   € Ø(¨4¬?Ñ:ˆ
Ø˜Š?ˆ?õ
 ˜‘<”<ÐØ�jÑ!Ð!r   c                 óh   — |                       ||¦  «        }| 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ÔAˆØŒ{˜XÑ%¨¨T¬[©¸DÔ<NÑ(NÑNÐNr   N)rˆ   )
r   r   r   r	   Úpropertyr�   rq   ry   r™   r’   r   r   r   r`   r`   g  s„   € € € € € ð"ð "ð "ð "ð  ð"ð "ñ „Xð"ð
ð 
ð 
ð$.ð .ð .ð$"ð "ð "ðOð Oð Oð Oð Or   r`   )r\   r   Ú	Exceptionr   r   r   r    r'   rX   rb   r`   r   r   r   ú<module>rŸ      s�  ðð Ð Ð Ð Ø €€€ðð ð ð ð ˜yñ ô ð ð(	ð 	ð 	ð 	ð 	ñ 	ô 	ð 	ð!ð !ð !ð !ð !ñ !ô !ð !ð$#ð #ð #ð #ð #ñ #ô #ð #ðLnð nð nð nð nñ nô nð nðbZð Zð Zð Zð Zñ Zô Zð Zðz3
ð 3
ð 3
ð 3
ð 3
ñ 3
ô 3
ð 3
ðlNOð NOð NOð NOð NOñ NOô NOð NOð NOð NOr   