+
    üÐjÉ$  ã                   ó  € R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt  ! R R4      t	 ! R R]4      t
]! ]
4       ! R	 R
4      4       t ! R R]4      t ! R R]4      t ! R R]P                  4      t ! R R]4      t ! R R4      tR# )a¼  
Hierarchical Token Bucket traffic shaping.

Patterned after U{Martin Devera's Hierarchical Token Bucket traffic
shaper for the Linux kernel<http://luxik.cdi.cz/~devik/qos/htb/>}.

@seealso: U{HTB Linux queuing discipline manual - user guide
  <http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm>}
@seealso: U{Token Bucket Filter in Linux Advanced Routing & Traffic Control
    HOWTO<http://lartc.org/howto/lartc.qdisc.classless.html#AEN682>}
)Útime)ÚOptional)Ú	InterfaceÚimplementer)Úpcpc                   óR   a € ] tR t^t o RtRtRt^ tRR ltR t	R t
V 3R ltRtV tR# )	ÚBucketa¿  
Implementation of a Token bucket.

A bucket can hold a certain number of tokens and it drains over time.

@cvar maxburst: The maximum number of tokens that the bucket can
    hold at any given time. If this is L{None}, the bucket has
    an infinite size.
@type maxburst: C{int}
@cvar rate: The rate at which the bucket drains, in number
    of tokens per second. If the rate is L{None}, the bucket
    drains instantaneously.
@type rate: C{int}
Nc                ó>   € ^ V n         Wn        \        4       V n        R# )zø
Create a L{Bucket} that may have a parent L{Bucket}.

@param parentBucket: If a parent Bucket is specified,
    all L{add} and L{drip} operations on this L{Bucket}
    will be applied on the parent L{Bucket} as well.
@type parentBucket: L{Bucket}
N)ÚcontentÚparentBucketr   ÚlastDrip)Úselfr   s   &&Ú7/usr/lib/python3/dist-packages/twisted/protocols/htb.pyÚ__init__ÚBucket.__init__3   s   € ð ˆŒØ(ÔÜ›ˆŽó    c                ó  € V P                  4        V P                  f   TpM&\        WP                  V P                  ,
          4      pV P                  e   V P                  P                  V4      pV ;P                  V,          un        V# )a4  
Adds tokens to the L{Bucket} and its C{parentBucket}.

This will add as many of the C{amount} tokens as will fit into both
this L{Bucket} and its C{parentBucket}.

@param amount: The number of tokens to try to add.
@type amount: C{int}

@returns: The number of tokens that actually fit.
@returntype: C{int}
)ÚdripÚmaxburstÚminr
   r   Úadd)r   ÚamountÚ	allowables   && r   r   Ú
Bucket.add@   si   € ð 	�	‰	ŒØ�=‰=Ò Ø‰Iä˜F§M¡M°D·L±LÕ$@ÓAˆIà×ÑÒ(Ø×)Ñ)×-Ñ-¨iÓ8ˆIØ�Š˜	Õ!�ØÐr   c                óH  € V P                   e   V P                   P                  4        V P                  f	   ^ V n        MV\	        4       pWP
                  ,
          pW P                  ,          p\        ^ V P                  V,
          4      V n        Wn        V P                  ^ 8H  # )zº
Let some of the bucket drain.

The L{Bucket} drains at the rate specified by the class
variable C{rate}.

@returns: C{True} if the bucket is empty after this drip.
@returntype: C{bool}
)r   r   Úrater
   r   r   Úmax)r   ÚnowÚ	deltaTimeÚdeltaTokenss   &   r   r   ÚBucket.dripX   s}   € ð ×ÑÒ(Ø×Ñ×"Ñ"Ô$à�9‰9ÒØˆD�Lä“&ˆCØŸm™mÕ+ˆIØ#§i¡iÕ/ˆKÜ˜q $§,¡,°Õ"<Ó=ˆDŒLØŒMØ�|‰|˜qÑ Ð r   c                óR   <€ V ^8„  d   Qh/ S[ S[,          ;R&   S[ S[,          ;R&   # )é   r   r   ©r   Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚBucket.__annotate__   s'   ø‡ ‚ ñ  ‘s�mÑ"ñ! ñ" ‘3�-Ñò# r   )r
   r   r   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú	_refcountr   r   r   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r&   s   @r   r   r      s2   ø‡ € ñð #€HØ€Dà€Iôòò0!÷u ƒ r   r   c                   ó&   a € ] tR t^pt o R tRtV tR# )ÚIBucketFilterc                 ó   € R# )zV
Return a L{Bucket} corresponding to the provided parameters.

@returntype: L{Bucket}
N© )Ú
somethingsÚsome_kws   *,r   ÚgetBucketForÚIBucketFilter.getBucketForq   s   ‚ r   r7   N)r*   r+   r,   r-   r:   r1   r2   r3   s   @r   r5   r5   p   s   ø‡ € ÷ð r   r5   c                   óT   a € ] tR t^yt o Rt]tRtR	R ltR t	R t
R tV 3R ltRtV tR# )
ÚHierarchicalBucketFilterzß
Filter things into buckets that can be nested.

@cvar bucketFactory: Class of buckets to make.
@type bucketFactory: L{Bucket}
@cvar sweepInterval: Seconds between sweeping out the bucket cache.
@type sweepInterval: C{int}
Nc                ó>   € / V n         Wn        \        4       V n        R # r)   )ÚbucketsÚparentFilterr   Ú	lastSweep)r   r@   s   &&r   r   Ú!HierarchicalBucketFilter.__init__‡   s   € ØˆŒØ(ÔÜ›ˆŽr   c                ó   € V P                   e;   \        4       V P                  ,
          V P                   8”  d   V P                  4        V P                  '       d"   V P                  P
                  ! V .VO5/ VB pMRpV P                  ! V/ VB pV P                  P                  V4      pVf    V P                  V4      pWPP                  V&   V# )z»
Find or create a L{Bucket} corresponding to the provided parameters.

Any parameters are passed on to L{getBucketKey}, from them it
decides which bucket you get.

@returntype: L{Bucket}
N)
ÚsweepIntervalr   rA   Úsweepr@   r:   ÚgetBucketKeyr?   ÚgetÚbucketFactory)r   ÚaÚkwr   ÚkeyÚbuckets   &*,   r   r:   Ú%HierarchicalBucketFilter.getBucketForŒ   s²   € ð ×ÑÒ*Ü‹V�d—n‘nÕ$¨×(:Ñ(:Ô:à�J‰JŒLà××ÐØ×,Ñ,×9Ò9¸$ÐIÀÒIÀbÑI‰LàˆLà×Ò Ð) bÑ)ˆØ—‘×!Ñ! #Ó&ˆØŠ>Ø×'Ñ'¨Ó5ˆFØ &�L‰L˜ÑØˆr   c                ó   € R# )zý
Construct a key based on the input parameters to choose a L{Bucket}.

The default implementation returns the same key for all
arguments. Override this method to provide L{Bucket} selection.

@returns: Something to be used as a key in the bucket cache.
Nr7   )r   rI   rJ   s   &*,r   rF   Ú%HierarchicalBucketFilter.getBucketKey¦   s   € ñ r   c                óÞ   € V P                   P                  4        F?  w  rVP                  4       pVP                  ^ 8X  g   K(  V'       g   K2  V P                   V KA  	  \	        4       V n        R# )z
Remove empty buckets.
N)r?   Úitemsr   r/   r   rA   )r   rK   rL   Úbucket_is_emptys   &   r   rE   ÚHierarchicalBucketFilter.sweep±   sQ   € ð  Ÿ<™<×-Ñ-Ö/‰KˆCØ$Ÿk™k›mˆOØ× Ñ  AÖ%¯?©?Ø—L‘L Ò%ñ 0ô
 ›ˆŽr   c                ó6   <€ V ^8„  d   Qh/ S[ S[,          ;R&   # )r"   rD   r#   )r%   r&   s   "€r   r'   Ú%HierarchicalBucketFilter.__annotate__y   s   ø‡ ‚ ñ ™C•=Ñ'ò r   )r?   rA   r@   r)   )r*   r+   r,   r-   r.   r   rH   rD   r   r:   rF   rE   r0   r1   r2   r3   s   @r   r=   r=   y   s2   ø‡ € ñð €MØ#'€Mô ò
ò4	ò	 ÷q ƒ r   r=   c                   ó.   a € ] tR t^½t o RtRtR tRtV tR# )ÚFilterByHostz>
A Hierarchical Bucket filter with a L{Bucket} for each host.
c                ó0   € VP                  4       ^,          # )é   )ÚgetPeer©r   Ú	transports   &&r   rF   ÚFilterByHost.getBucketKeyÄ   ó   € Ø× Ñ Ó" 1Õ%Ð%r   r7   Ni°  ©	r*   r+   r,   r-   r.   rD   rF   r1   r2   r3   s   @r   rW   rW   ½   s   ø‡ € ñð €M÷&ð &r   rW   c                   ó.   a € ] tR t^Èt o RtRtR tRtV tR# )ÚFilterByServerzA
A Hierarchical Bucket filter with a L{Bucket} for each service.
Nc                ó0   € VP                  4       ^,          # )r"   )ÚgetHostr[   s   &&r   rF   ÚFilterByServer.getBucketKeyÏ   r^   r   r7   r_   r3   s   @r   ra   ra   È   s   ø‡ € ñð €M÷&ð &r   ra   c                   ó:   a € ] tR t^Ót o RtRtR tR tR tRt	V t
R# )ÚShapedConsumerzD
Wraps a C{Consumer} and shapes the rate at which it receives data.
Fc                ó–   € \         P                  P                  W4       W n        V P                  ;P                  ^,          un        R# ©rY   N)r   ÚProducerConsumerProxyr   rL   r/   )r   ÚconsumerrL   s   &&&r   r   ÚShapedConsumer.__init__Ü   s0   € Ü×!Ñ!×*Ñ*¨4Ô:ØŒØ�‰×Ò Õ"×r   c                óŽ   € V P                   P                  \        V4      4      p\        P                  P                  WR V 4      # r)   )rL   r   Úlenr   ri   Ú_writeSomeData)r   Údatar   s   && r   rn   ÚShapedConsumer._writeSomeDataá   s7   € ð
 —‘—‘¤ T£Ó+ˆÜ×(Ñ(×7Ñ7¸À7ÀF¸mÓLÐLr   c                óŠ   € \         P                  P                  V 4       V P                  ;P                  ^,          un        R# rh   )r   ri   ÚstopProducingrL   r/   )r   s   &r   rr   ÚShapedConsumer.stopProducingé   s+   € Ü×!Ñ!×/Ñ/°Ô5Ø�‰×Ò Õ"×r   )rL   N)r*   r+   r,   r-   r.   ÚiAmStreamingr   rn   rr   r1   r2   r3   s   @r   rf   rf   Ó   s&   ø‡ € ñð €Lò#ò
M÷#ð #r   rf   c                   ó.   a € ] tR t^ît o RtRtR tRtV tR# )ÚShapedTransporta:  
Wraps a C{Transport} and shapes the rate at which it receives data.

This is a L{ShapedConsumer} with a little bit of magic to provide for
the case where the consumer it wraps is also a C{Transport} and people
will be attempting to access attributes this does not proxy as a
C{Consumer} (e.g. C{loseConnection}).
Fc                ó.   € \        V P                  V4      # r)   )Úgetattrrj   )r   Únames   &&r   Ú__getattr__ÚShapedTransport.__getattr__ü   s   € ô �t—}‘} dÓ+Ð+r   r7   N)	r*   r+   r,   r-   r.   rt   rz   r1   r2   r3   s   @r   rv   rv   î   s   ø‡ € ñð €L÷,ð ,r   rv   c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )ÚShapedProtocolFactoryi  ao  
Dispense C{Protocols} with traffic shaping on their transports.

Usage::

    myserver = SomeFactory()
    myserver.protocol = ShapedProtocolFactory(myserver.protocol,
                                              bucketFilter)

Where C{SomeServerFactory} is a L{twisted.internet.protocol.Factory}, and
C{bucketFilter} is an instance of L{HierarchicalBucketFilter}.
c                ó   € Wn         W n        R# )aT  
Tell me what to wrap and where to get buckets.

@param protoClass: The class of C{Protocol} this will generate
  wrapped instances of.
@type protoClass: L{Protocol<twisted.internet.interfaces.IProtocol>}
  class
@param bucketFilter: The filter which will determine how
  traffic is shaped.
@type bucketFilter: L{HierarchicalBucketFilter}.
N)ÚprotocolÚbucketFilter)r   Ú
protoClassr€   s   &&&r   r   ÚShapedProtocolFactory.__init__  s   € ð #ŒØ(Ör   c                ó`   a a€ S P                   ! V/ VB pVP                  oVV 3R lpWCn        V# )z´
Make a C{Protocol} instance with a shaped transport.

Any parameters will be passed on to the protocol's initializer.

@returns: A C{Protocol} instance with a L{ShapedTransport}.
c                 ó`   <€ SP                   P                  V 4      p\        W4      pS! V4      # r)   )r€   r:   rv   )r\   rL   ÚshapedTransportÚorigMakeConnectionr   s   &  €€r   ÚmakeConnectionÚ6ShapedProtocolFactory.__call__.<locals>.makeConnection,  s.   ø€ Ø×&Ñ&×3Ñ3°IÓ>ˆFÜ-¨iÓ@ˆOÙ% oÓ6Ð6r   )r   r‡   )r   rI   rJ   Úprotor‡   r†   s   f*,  @r   Ú__call__ÚShapedProtocolFactory.__call__!  s6   ù€ ð —’˜qÐ' BÑ'ˆØ"×1Ñ1Ðö	7ð
  .ÔØˆr   )r€   r   N)	r*   r+   r,   r-   r.   r   rŠ   r1   r2   r3   s   @r   r}   r}     s   ø‡ € ñò)÷"ð r   r}   N)r.   r   Útypingr   Úzope.interfacer   r   Útwisted.protocolsr   r   r5   r=   rW   ra   ri   rf   rv   r}   r7   r   r   Ú<module>r�      s•   ðñ
õ  Ý ç 1å !÷O!ñ O!ôd�Iô ñ ˆ]Ó÷@ ð @ ó ð@ ôF&Ð+ô &ô&Ð-ô &ô#�S×.Ñ.ô #ô6,�nô ,÷(0ó 0r   