
    f!                       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ddZd dZd dZd dZd dZd dZ d dZ!d!dZ" ed      Z#	 	 	 	 	 	 d"dZ$d#dZ%d$dZ&ee	g e'f   e'f   Z(d%dZ)d&d'dZ*y)(    )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                  V    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
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      O/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/utils.py__init__zEvent.__init__B   s&     :<GOD     c                J    | j                   D ]  } || j                          y)zFire event.N)r"   r!   r#   r$   s     r%   __call__zEvent.__call__K   s!    ~~ 	!GDKK 	!r'   c                     |         y)z!Alias for just calling the event.N r#   s    r%   firez
Event.fireP   s    r'   c                :    | j                   j                  |       y)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                X    || j                   v r| j                   j                  |       yy)z6
        Remove a handler from this callback.
        N)r"   remover)   s     r%   remove_handlerzEvent.remove_handler]   s'     dnn$NN!!'* %r'   c                (    | j                  |       | S )zC
        `event += handler` notation for adding a handler.
        )r1   r)   s     r%   __iadd__zEvent.__iadd__d   s     	!r'   c                (    | j                  |       | S )zE
        `event -= handler` notation for removing a handler.
        )r4   r)   s     r%   __isub__zEvent.__isub__k   s     	G$r'   r    )r!   r   r$   z Callable[[_Sender], None] | NonereturnNoner9   r:   )r$   Callable[[_Sender], None]r9   r:   )r$   r<   r9   zEvent[_Sender])__name__
__module____qualname____doc__r&   r*   r.   r1   r4   r6   r8   r,   r'   r%   r   r   -   sI    * LP(H	!
'+r'   r   c                       e Zd ZdZddZddZy)r   z5
    (contextlib.nested is not available on Py3)
    c                     y r    r,   r-   s    r%   	__enter__zDummyContext.__enter__x       r'   c                     y r    r,   )r#   as     r%   __exit__zDummyContext.__exit__{   rD   r'   Nr;   )rF   objectr9   r:   )r=   r>   r?   r@   rC   rG   r,   r'   r%   r   r   s   s    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.
    @      c                @    t         |           t               | _        y r    )superr&   r   _long_strings)r#   	__class__s    r%   r&   z_CharSizesCache.__init__   s    ).r'   c                J    t        |      dk(  rt        dt        |            }nt         fd|D              }| |<   t        |       j                  kD  rL j
                  }|j                  |       t        |       j                  kD  r|j                         }| v r |= |S )N   r   c              3  (   K   | ]	  }|     y wr    r,   ).0cr#   s     r%   	<genexpr>z._CharSizesCache.__missing__.<locals>.<genexpr>   s     1Qa1s   )	lenmaxr   sumLONG_STRING_MIN_LENrO   r0   MAX_LONG_STRINGSpopleft)r#   stringresultlong_stringskey_to_removes   `    r%   __missing__z_CharSizesCache.__missing__   s     v;!GFO,F1&11F V v;111--L'< 4#8#88 , 4 4 6 D(]+r'   r;   r]   strr9   int)	r=   r>   r?   r@   rZ   r[   r&   ra   __classcell__)rP   s   @r%   rJ   rJ      s      1
r'   rJ   c                    t         |    S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)r]   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                  dk(  S )z)
    True when we are using Windows.
    win32)sysplatformr,   r'   r%   r   r      s     <<7""r'   c                 D    t         j                  dk(  rddlm}   |        S y)zS
    True when we are using Windows, but VT100 escape sequences are supported.
    rm   r   is_win_vt100_enabledF)rn   ro   prompt_toolkit.output.windows10rr   rq   s    r%   is_windows_vt100_supportedrt      s     ||wH#%%r'   c                 r    t         j                  dk(  xr# t        j                  j	                  dd      dk(  S )z7
    True when the ConEmu Windows console is used.
    rm   
ConEmuANSIOFFON)rn   ro   osenvirongetr,   r'   r%   r   r      s,     <<7"Rrzz~~lE'Jd'RRr'   c                 X    t        j                         j                  j                  dk(  S )z:
    True when the current thread is the main thread.
    _MainThread)	threadingcurrent_threadrP   r=   r,   r'   r%   r   r      s$     ##%//88MIIr'   c                 f    t         j                  j                  dd      } | j                         dv S )zD
    True if env variable is set to true (true, TRUE, True, 1).
    PROMPT_TOOLKIT_BELLtrue)1r   )ry   rz   r{   lowervalues    r%   r   r      s*     JJNN0&9E;;=M))r'   c                 B    t         j                  j                  dd      S )z&Return the $TERM environment variable.TERM )ry   rz   r{   r,   r'   r%   r   r      s    ::>>&"%%r'   _Tc              #  
  K   t        |       t        |      k(  sJ t        |       dkD  sJ g }g }t        | |      D ]-  \  }}|dkD  s|j                  |       |j                  |       / |} |}| st        d      | 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.)
    r   z+Did't got any items with a positive weight.TFrR   )rW   zipr0   
ValueErrorrX   rangefloat)itemsweightsitems2weights2itemwialready_taken
item_count
max_weightaddingitem_iweights                r%   r   r      s?     u:W%%%u:>> FHug& aq5MM$OOA
 EG FGG !&&1Q&M&UJWJ	A
F(+E*,=ug(N "$f (1v:j8I+IIJ!&)Q.)!F	"  	
Q  's%   AD9D	C>
AD D8Dc                N    t        |       rt         |              S t        |       S )z$Turn callable or string into string.)callabler   rc   r   s    r%   r   r   "      eg5zr'   c                N    t        |       rt         |              S t        |       S )zTurn callable or int into int.)r   r   rd   r   s    r%   r   r   *  r   r'   c                N    t        |       rt         |              S t        |       S )z"Turn callable or float into float.)r   r   r   r   s    r%   r   r   5  s       U|r'   c                |    | )t        t        j                  j                  dd            S | j	                         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.
    r   r   )dumbunknown)r   ry   rz   r{   r   )terms    r%   r   r   =  s5     |

vr :;;::<...r'   rb   )r9   bool)r9   rc   )r   zlist[_T]r   z	list[int]r9   zGenerator[_T, None, None])r   zCallable[[], str] | strr9   rc   )r   zCallable[[], int] | intr9   rd   )r   r   r9   r   r    )r   z
str | Noner9   r   )+
__future__r   ry   rk   rn   r~   collectionsr   typingr   r   r   r   r	   r
   r   r   __all__modulesSPHINX_AUTODOC_RUNNINGr   r   r   rc   rd   rJ   rg   r   r   r   rt   r   r   r   r   r   r   r   r   r   r   r   r   r,   r'   r%   <module>r      s   " 	  
     ( .< 
)t
,CGG CL	>$' 	&d38n &R $% %&#
SJ*&
 T]33'33l "e)$e+,
/r'   