
                             S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  Sr " S S\5      r\R                  " 5       rS r " S	 S
\5      r " S S\5      r\" 5       rS rS rS rS rS rS rg)    )unicode_literalsN)wcwidth)range)	EventDummyContext
get_cwidthsuspend_to_background_supportedis_conemu_ansi
is_windowsin_main_threadtake_using_weightstest_callable_argsc                   :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)r      a}  
Simple event to which event handlers can be attached. For instance::

    class Cls:
        def __init__(self):
            # Define event. The first parameter is the sender.
            self.event = Event(self)

    obj = Cls()

    def handler(sender):
        pass

    # Add event handler by using the += operator.
    obj.event += handler

    # Fire event.
    obj.event()
Nc                 .    Xl         / U l        Ub  X-  n g g N)sender	_handlers)selfr   handlers      'lib/third_party/prompt_toolkit/utils.py__init__Event.__init__.   s     OD     c                 N    U R                    H  nU" U R                  5        M     g)zFire event. Nr   r   r   r   s     r   __call__Event.__call__5   s    ~~GDKK  &r   c                     U " 5         g)z"Alias for just calling the event. N r   s    r   fire
Event.fire:   s    r   c                     [        U5      (       d   e[        US/5      (       d  [        SU-  5      eU R                  R	                  U5        U $ )z{
Add another handler to this callback.
(Handler should be a callable that takes exactly one parameter: the
sender object.)
Nz%%r doesn't take exactly one argument.)callabler   	TypeErrorr   appendr   s     r   __iadd__Event.__iadd__>   sN         !'D622CgMNN 	g&r   c                 <    U R                   R                  U5        U $ )z&
Remove a handler from this callback.
)r   remover   s     r   __isub__Event.__isub__M   s     	g&r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r#   r)   r-   __static_attributes__r!   r   r   r   r      s     &!
r   r   c                     [        U[        [        45      (       d   e[        [        SS5      nUb   [
        U    n UR                  " U6   g[        R                  " U 5      nS nU" U5      nUR                  b  g[        UR                  5      [        UR                  =(       d    / 5      -
  [        U5      s=:*  =(       a    [        UR                  5      :*  $ s  $ ! [         a    U" U 5      nU[
        U '    Nf = f! [         a     gf = f)zH
Return True when this function can be called with the given arguments.
	signatureNTFc                 X    U u  pp4USS S/:X  a  USS  n[         R                  " XX45      $ )Nr      r   )inspectArgSpec)specargsvarargsvarkwdefaultss        r   	drop_self%test_callable_args.<locals>.drop_selfs   s8    -1*D5AayVH$ABx??4%BBr   )
isinstancelisttuplegetattrr9   _signatures_cacheKeyErrorbindr'   
getargspecr=   lenr<   r?   )funcr<   r6   sigr;   r@   s         r   r   r   Y   s     dT5M****d3I	*#D)C
	HHdO  !!$'	C  <<# 499~DMM$7R 88CIWWTYYWWWW;  	*D/C&)d#	*  		s"   	C D  C=<C= 
DDc                   $    \ rS rSrSrS rS rSrg)r      z-
(contextlib.nested is not available on Py3)
c                     g r   r!   r"   s    r   	__enter__DummyContext.__enter__       r   c                     g r   r!   )r   as     r   __exit__DummyContext.__exit__   rR   r   r!   N)r/   r0   r1   r2   r3   rP   rU   r4   r!   r   r   r   r      s    r   r   c                       \ rS rSrSrS rSrg)_CharSizesCache   z
Cache for wcwidth sizes.
c                     [        U5      S:X  a  [        S[        U5      5      nO[        S U 5       5      n[        U5      S:  a  X U'   U$ )Nr8   r   c              3   L   #    U  H  n[        S [        U5      5      v   M     g7f)r   N)maxr   ).0cs     r   	<genexpr>._CharSizesCache.__missing__.<locals>.<genexpr>   s     <VQ
++Vs   "$   )rJ   r\   r   sum)r   stringresults      r   __missing___CharSizesCache.__missing__   sJ    
 v;!GFO,F<V<<F v;!Lr   r!   N)r/   r0   r1   r2   r3   re   r4   r!   r   r   rX   rX      s    r   rX   c                     [         U    $ )z7
Return width of a string. Wrapper around ``wcwidth``.
)_CHAR_SIZES_CACHE)rc   s    r   r   r      s     V$$r   c                  "    [        [        S5      $ )z}
Returns `True` when the Python implementation supports
suspend-to-background. This is typically `False' on Windows systems.
SIGTSTP)hasattrsignalr!   r   r   r	   r	      s    
 69%%r   c                  @    [         R                  R                  S5      $ )z!
True when we are using Windows.
win)sysplatform
startswithr!   r   r   r   r      s     <<""5))r   c                  j    [        5       =(       a#    [        R                  R                  SS5      S:H  $ )z/
True when the ConEmu Windows console is used.

ConEmuANSIOFFON)r   osenvirongetr!   r   r   r
   r
      s%     <GBJJNN<?4GGr   c                  Z    [         R                  " 5       R                  R                  S:H  $ )z2
True when the current thread is the main thread.
_MainThread)	threadingcurrent_thread	__class__r/   r!   r   r   r   r      s$     ##%//88MIIr   c              #     #    [        U [        5      (       d   e[        U[        5      (       d   e[        S U 5       5      (       d   e[        U 5      [        U5      :X  d   e[        U 5      S:  d   eU  Vs/ s H  nSPM     nn[        U 5      n[	        U5      nSn SnU(       aT  Sn[        [        U5      X5       H0  u  pxn	X7   X)-  [        U5      -  :  d  M  Uv   X7==   S-  ss'   SnM2     U(       a  MT  US-  nMd  s  snf 7f)a  
Generator that keeps yielding items from the items list, in proportion to
their weight. For instance::

    # Getting the first 70 items from this generator should have yielded 10
    # times A, 20 times B and 40 times C, all distributed equally..
    take_using_weights(['A', 'B', 'C'], [5, 10, 20])

:param items: List of items to take from.
:param weights: Integers representing the weight. (Numbers have to be
                integers, not floats.)
c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )rB   int)r]   is     r   r_   %take_using_weights.<locals>.<genexpr>   s     37az!S!!7s   r   TFr8   )rB   rC   allrJ   r\   zipr   float)
itemsweightsr   already_taken
item_count
max_weightaddingitem_iitemweights
             r   r   r      s     eT""""gt$$$$3733333u:W%%%u:>> %&1QM&UJWJ	A
F(+E*,=u(N$f (1:j8I+IIJ!)Q.)!F	 )O f 	
Q  's   A7D	9DAD	D	=D	)
__future__r   r9   rv   rl   ro   r{   weakrefr   	six.movesr   __all__objectr   WeakKeyDictionaryrF   r   r   dictrX   rh   r   r	   r   r
   r   r   r!   r   r   <module>r      s    '  	  
    
8F 8x --/ (XV6 d , $% %&*HJ$r   