
     h!                       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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DequeDict	GeneratorGenericListOptional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      P/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/prompt_toolkit/utils.py__init__zEvent.__init__E   s-     :<GODDD     c                :    | j         D ]} || j                   dS )zFire event.N)r)   r"   r*   r#   s     r+   __call__zEvent.__call__N   s2    ~ 	! 	!GGDK    	! 	!r-   c                     |              dS )z!Alias for just calling the event.N r*   s    r+   firez
Event.fireS   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_handlerW   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.
        )r8   r/   s     r+   __iadd__zEvent.__iadd__g   s     	!!!r-   c                0    |                      |           | S )zE
        `event -= handler` notation for removing a handler.
        )r;   r/   s     r+   __isub__zEvent.__isub__n   s     	G$$$r-   r(   )r"   r   r#   r$   r%   r&   r%   r&   )r#   r5   r%   r&   )r#   r5   r%   r<   )__name__
__module____qualname____doc__r,   r0   r4   r8   r;   r>   r@   r2   r-   r+   r   r   0   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(   r2   r3   s    r+   	__enter__zDummyContext.__enter__{       r-   aobjectc                    d S r(   r2   )r*   rJ   s     r+   __exit__zDummyContext.__exit__~   rI   r-   NrA   )rJ   rK   r%   r&   )rB   rC   rD   rE   rH   rM   r2   r-   r+   r   r   v   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(   r2   ).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_LENrT   r7   MAX_LONG_STRINGSpopleft)r*   rV   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-   rA   rV   rW   r%   rX   )	rB   rC   rD   rE   rb   rc   r,   rh   __classcell__)rU   s   @r+   rO   rO      si          1 1 1 1 1 1
       r-   rO   rV   rW   r%   rX   c                    t           |          S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)rV   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signalr2   r-   r+   r   r      s    
 69%%%r-   c                 "    t           j        dk    S )z)
    True when we are using Windows.
    win32)sysplatformr2   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.
    rs   r   is_win_vt100_enabledF)rt   ru   prompt_toolkit.output.windows10rx   rw   s    r+   is_windows_vt100_supportedrz      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.
    rs   
ConEmuANSIOFFON)rt   ru   osenvirongetr2   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_threadrU   rB   r2   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   r2   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   r2   )r\   is     r+   
<listcomp>z&take_using_weights.<locals>.<listcomp>  s    &&&1Q&&&r-   TFrZ   )r_   zipr7   
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   rW   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   rX   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   8  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-   ri   )r%   rm   )r%   rW   )r   r   r   r   r%   r   )r   r   r%   rW   )r   r   r%   rX   )r   r   r%   r   r(   )r   r   r%   rm   ).
__future__r   r   rq   rt   r   collectionsr   typingr   r   r   r   r	   r
   r   r   r   r   r   __all__modulesSPHINX_AUTODOC_RUNNINGr   r   r   rW   rX   rO   rl   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r2   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-   