
                             d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 dZ G d de      Z ej                         Zd Z G d	 d
e      Z G d de      Z e       Zd Zd Zd Zd Zd Zd Zy)    )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                   0    e Zd ZdZddZd Zd Zd Zd Zy)	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                 0    || _         g | _        || |z  } y y N)sender	_handlers)selfr   handlers      'lib/third_party/prompt_toolkit/utils.py__init__zEvent.__init__.   s$    GOD     c                 J    | j                   D ]  } || j                          y)z Fire event. N)r   r   r   r   s     r   __call__zEvent.__call__5   s    ~~GDKK  &r   c                      |         y)z# Alias for just calling the event. N r   s    r   firez
Event.fire:   s    r   c                     t        |      sJ t        |dg      st        d|z        | j                  j	                  |       | S )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__zEvent.__iadd__>   sH        !'D62CgMNN 	g&r   c                 <    | j                   j                  |       | S )z6
        Remove a handler from this callback.
        )r   remover   s     r   __isub__zEvent.__isub__M   s     	g&r   r   )	__name__
__module____qualname____doc__r   r   r   r$   r'   r   r   r   r   r      s     &!
r   r   c                    t        |t        t        f      sJ t        t        dd      }|	 t
        |    }	  |j                  |  yt	        j                  |       }d } ||      }|j                  yt        |j                        t        |j                  xs g       z
  t        |      cxk  xr t        |j                        k  S c S # t        $ r  ||       }|t
        | <   Y w xY w# t        $ r Y yw xY w)zP
    Return True when this function can be called with the given arguments.
    	signatureNTFc                 \    | \  }}}}|dd dgk(  r|dd  }t        j                  ||||      S )Nr      r   )inspectArgSpec)specargsvarargsvarkwdefaultss        r   	drop_selfz%test_callable_args.<locals>.drop_selfs   s@    -1*D'5(AayVH$ABx??4%BBr   )
isinstancelisttuplegetattrr0   _signatures_cacheKeyErrorbindr"   
getargspecr4   lenr3   r6   )funcr3   r-   sigr2   r7   s         r   r   r   Y   s     dT5M***d3I	*#D)C
	CHHdO  !!$'	C  <<# 499~DMM$7R 88CIWTYYWWWW;  	*D/C&)d#	*  		s"   	C C- C*)C*-	C98C9c                       e Zd ZdZd Zd Zy)r   z5
    (contextlib.nested is not available on Py3)
    c                      y r   r   r   s    r   	__enter__zDummyContext.__enter__       r   c                      y r   r   )r   as     r   __exit__zDummyContext.__exit__   rF   r   N)r(   r)   r*   r+   rE   rI   r   r   r   r   r      s    r   r   c                       e Zd ZdZd Zy)_CharSizesCachez"
    Cache for wcwidth sizes.
    c                     t        |      dk(  rt        dt        |            }nt        d |D              }t        |      dk  r|| |<   |S )Nr/   r   c              3   F   K   | ]  }t        d t        |              yw)r   N)maxr   ).0cs     r   	<genexpr>z._CharSizesCache.__missing__.<locals>.<genexpr>   s     <VQ
+Vs   !   )r@   rN   r   sum)r   stringresults      r   __missing__z_CharSizesCache.__missing__   sL    
 v;!GFO,F<V<<F v;!DLr   N)r(   r)   r*   r+   rV   r   r   r   rK   rK      s    r   rK   c                     t         |    S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)rT   s    r   r   r      s     V$$r   c                  "    t        t        d      S )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                  @    t         j                  j                  d      S )z)
    True when we are using Windows.
    win)sysplatform
startswithr   r   r   r   r      s     <<""5))r   c                  `    t               xr# t        j                  j                  dd      dk(  S )z7
    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                  X    t        j                         j                  j                  dk(  S )z:
    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              #     K   t        | t              sJ t        |t              sJ t        d |D              sJ t        |       t        |      k(  sJ t        |       dkD  sJ | D cg c]  }d }}t        |       }t	        |      }d}	 d}|rOd}t        t        |      | |      D ]1  \  }}}	||   ||	z  t        |      z  k  s| ||xx   dz  cc<   d}3 |rO|dz  }Yc c}w w)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   <   K   | ]  }t        |t                y wr   )r8   int)rO   is     r   rQ   z%take_using_weights.<locals>.<genexpr>   s     37az!S!7s   r   TFr/   )r8   r9   allr@   rN   zipr   float)
itemsweightsrq   already_taken
item_count
max_weightaddingitem_iitemweights
             r   r   r      s     eT"""gt$$$373333u:W%%%u:>> %&1QM&UJWJ	A
F(+E*,=ug(N$f (1v:j8I+IIJ!&)Q.)!F	 )O  	
Q  's   A&C*(	C%1AC*C*C*)
__future__r   r0   rf   r\   r_   rk   weakrefr   	six.movesr   __all__objectr   WeakKeyDictionaryr<   r   r   dictrK   rX   r   r	   r   r
   r   r   r   r   r   <module>r      s    '  	  
    
8F 8x .G--/ (XV6 d , $% %&*HJ$r   