
    Mh!                       d dl m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	m
Z
mZmZmZmZmZ d dlmZ g dZdej        v Z edd	
          Z G d dee                   Z G d de
d                   Z G d deeef                   Z e            Zd0dZd1dZd1dZd1dZd1dZd1dZ d1dZ!d2dZ" ed          Z#d3d$Z$d4d'Z%d5d)Z&ee	g e'f         e'f         Z(d6d,Z)d7d8d/Z*dS )9    )annotationsN)deque)CallableContextManagerDict	GeneratorGenericTypeVarUnion)wcwidth)EventDummyContext
get_cwidthsuspend_to_background_supportedis_conemu_ansi
is_windowsin_main_threadget_bell_environment_variableget_term_environment_variabletake_using_weightsto_strto_intAnyFloatto_floatis_dumb_terminalzsphinx.ext.autodoc_SenderT)	covariantc                  N    e Zd ZdZ	 ddd	Zdd
ZddZddZddZddZ	ddZ
dS )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()
    Nsenderr   handler Callable[[_Sender], None] | NonereturnNonec                4    || _         g | _        || |z  } d S d S N)r   	_handlers)selfr   r    s      T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/utils.py__init__zEvent.__init__B   s-     :<GODDD     c                :    | j         D ]} || j                   dS )zFire event.N)r&   r   r'   r    s     r(   __call__zEvent.__call__K   s2    ~ 	! 	!GGDK    	! 	!r*   c                     |              dS )z!Alias for just calling the event.N r'   s    r(   firez
Event.fireP   s    r*   Callable[[_Sender], None]c                :    | j                             |           dS )z
        Add another handler to this callback.
        (Handler should be a callable that takes exactly one parameter: the
        sender object.)
        N)r&   appendr,   s     r(   add_handlerzEvent.add_handlerT   s      	g&&&&&r*   c                P    || j         v r| j                             |           dS dS )z6
        Remove a handler from this callback.
        N)r&   remover,   s     r(   remove_handlerzEvent.remove_handler]   s5     dn$$N!!'***** %$r*   Event[_Sender]c                0    |                      |           | S )zC
        `event += handler` notation for adding a handler.
        )r5   r,   s     r(   __iadd__zEvent.__iadd__d   s     	!!!r*   c                0    |                      |           | S )zE
        `event -= handler` notation for removing a handler.
        )r8   r,   s     r(   __isub__zEvent.__isub__k   s     	G$$$r*   r%   )r   r   r    r!   r"   r#   r"   r#   )r    r2   r"   r#   )r    r2   r"   r9   )__name__
__module____qualname____doc__r)   r-   r1   r5   r8   r;   r=   r/   r*   r(   r   r   -   s         * LP    ! ! ! !
   ' ' ' '+ + + +        r*   r   c                  "    e Zd ZdZd	dZd
dZdS )r   z5
    (contextlib.nested is not available on Py3)
    r"   r#   c                    d S r%   r/   r0   s    r(   	__enter__zDummyContext.__enter__x       r*   aobjectc                    d S r%   r/   )r'   rG   s     r(   __exit__zDummyContext.__exit__{   rF   r*   Nr>   )rG   rH   r"   r#   )r?   r@   rA   rB   rE   rJ   r/   r*   r(   r   r   s   sF                 r*   r   c                  4     e Zd ZdZdZdZd fdZdd
Z xZS )_CharSizesCachez"
    Cache for wcwidth sizes.
    @      r"   r#   c                n    t                                                       t                      | _        d S r%   )superr)   r   _long_strings)r'   	__class__s    r(   r)   z_CharSizesCache.__init__   s+    ).r*   stringstrintc                x    t          |          dk    rt          dt          |                    }nt           fd|D                       }| |<   t          |           j        k    rO j        }|                    |           t          |           j        k    r|                                }| v r |= |S )N   r   c              3  (   K   | ]}|         V  d S r%   r/   ).0cr'   s     r(   	<genexpr>z._CharSizesCache.__missing__.<locals>.<genexpr>   s'      11Qa111111r*   )	lenmaxr   sumLONG_STRING_MIN_LENrQ   r4   MAX_LONG_STRINGSpopleft)r'   rS   resultlong_stringskey_to_removes   `    r(   __missing__z_CharSizesCache.__missing__   s     v;;!GFOO,,FF1111&11111F V v;;111-L'''<  4#888 , 4 4 6 6 D((]+r*   r>   rS   rT   r"   rU   )	r?   r@   rA   rB   r_   r`   r)   re   __classcell__)rR   s   @r(   rL   rL      si          1 1 1 1 1 1
       r*   rL   rS   rT   r"   rU   c                    t           |          S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)rS   s    r(   r   r      s     V$$r*   boolc                 ,    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        dk    S )z)
    True when we are using Windows.
    win32)sysplatformr/   r*   r(   r   r      s     <7""r*   c                 F    t           j        dk    rddlm}   |             S dS )zS
    True when we are using Windows, but VT100 escape sequences are supported.
    rp   r   is_win_vt100_enabledF)rq   rr   prompt_toolkit.output.windows10ru   rt   s    r(   is_windows_vt100_supportedrw      s7     |wHHHHHH##%%%5r*   c                 j    t           j        dk    o#t          j                            dd          dk    S )z7
    True when the ConEmu Windows console is used.
    rp   
ConEmuANSIOFFON)rq   rr   osenvirongetr/   r*   r(   r   r      s+     <7"Rrz~~lE'J'Jd'RRr*   c                 D    t          j                    j        j        dk    S )z:
    True when the current thread is the main thread.
    _MainThread)	threadingcurrent_threadrR   r?   r/   r*   r(   r   r      s     #%%/8MIIr*   c                 n    t           j                            dd          } |                                 dv S )zD
    True if env variable is set to true (true, TRUE, True, 1).
    PROMPT_TOOLKIT_BELLtrue)1r   )r|   r}   r~   lowervalues    r(   r   r      s-     JNN0&99E;;==M))r*   c                 B    t           j                            dd          S )z&Return the $TERM environment variable.TERM )r|   r}   r~   r/   r*   r(   r   r      s    :>>&"%%%r*   _Titemslist[_T]weights	list[int]Generator[_T, None, None]c              #  \  K   t          |           t          |          k    sJ t          |           dk    sJ g }g }t          | |          D ]5\  }}|dk    r*|                    |           |                    |           6|} |}| st          d          d | D             }t          |           }t	          |          }d}		 d}
|
r^d}
t          t          |          | |          D ];\  }}}||         |	|z  t          |          z  k     r|V  ||xx         dz  cc<   d}
<|
^|	dz  }	h)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.)
    r   z+Did't got any items with a positive weight.c                    g | ]}d S )r   r/   )rY   is     r(   
<listcomp>z&take_using_weights.<locals>.<listcomp>  s    &&&1Q&&&r*   TFrW   )r\   zipr4   
ValueErrorr]   rangefloat)r   r   items2weights2itemwalready_taken
item_count
max_weightr   addingitem_iweights                r(   r   r      s      u::W%%%%u::>>>> FHug&&  aq55MM$OOAEG  HFGGG '&&&&MUJWJ	A 	"F(+E*,=,=ug(N(N " "$f (1v:j8I8I+IIIJJJ!&)))Q.)))!F  	" 	
Qr*   r   Callable[[], str] | strc                l    t          |           rt           |                       S t          |           S )z$Turn callable or string into string.)callabler   rT   r   s    r(   r   r   "  .     eegg5zzr*   Callable[[], int] | intc                l    t          |           rt           |                       S t          |           S )zTurn callable or int into int.)r   r   rU   r   s    r(   r   r   *  r   r*   r   r   c                l    t          |           rt           |                       S t          |           S )z"Turn callable or float into float.)r   r   r   r   s    r(   r   r   5  s0        U||r*   term
str | Nonec                    | -t          t          j                            dd                    S |                                 dv S )z
    True if this terminal type is considered "dumb".

    If so, we should fall back to the simplest possible form of line editing,
    without cursor positioning and color support.
    Nr   r   )dumbunknown)r   r|   r}   r~   r   )r   s    r(   r   r   =  s;     |
vr : :;;;::<<...r*   rf   )r"   rj   )r"   rT   )r   r   r   r   r"   r   )r   r   r"   rT   )r   r   r"   rU   )r   r   r"   r   r%   )r   r   r"   rj   )+
__future__r   r|   rn   rq   r   collectionsr   typingr   r   r   r   r	   r
   r   r   __all__modulesSPHINX_AUTODOC_RUNNINGr   r   r   rT   rU   rL   ri   r   r   r   rw   r   r   r   r   r   r   r   r   r   r   r   r   r/   r*   r(   <module>r      s   " " " " " " 				  



                                   ( .< 
')t
,
,
,C C C C CGG C C CL	 	 	 	 	>$' 	 	 	& & & & &d38n & & &R $O%% % % % %& & & &# # # #
 
 
 
S S S SJ J J J* * * *& & & &
 WT]]3 3 3 3l       "e)$e+,   
/ 
/ 
/ 
/ 
/ 
/ 
/r*   