o
    j!                     @  st  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
 d dlmZ d dlmZmZ d dlmZ g dZd	ejv Zed
ddZG dd dee ZG dd ded ZG dd deeef Ze Zd?ddZd@ddZd@ddZd@ddZd@d d!Z d@d"d#Z!d@d$d%Z"dAd&d'Z#ed(Z$dBd.d/Z%dCd2d3Z&dDd5d6Z'e	g e(f e(B Z)dEd9d:Z*dFdGd=d>Z+dS )H    )annotationsN)deque)Callable	Generator)AbstractContextManager)GenericTypeVar)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                   @  sZ   e Zd ZdZ	ddd	d
ZdddZdddZdddZdddZdddZ	d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                 C  s$   || _ g | _|d ur| |7 } d S d S N)r   	_handlers)selfr   r    r#   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/utils.py__init__?   s
   zEvent.__init__c                 C  s   | j D ]}|| j qdS )zFire event.N)r!   r   r"   r   r#   r#   r$   __call__H   s   
zEvent.__call__c                 C  s
   |   dS )z!Alias for just calling the event.Nr#   r"   r#   r#   r$   fireM   s   
z
Event.fireCallable[[_Sender], None]c                 C  s   | 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&   r#   r#   r$   add_handlerQ   s   zEvent.add_handlerc                 C  s   || j v r| j | dS dS )z6
        Remove a handler from this callback.
        N)r!   remover&   r#   r#   r$   remove_handlerZ   s   
zEvent.remove_handlerEvent[_Sender]c                 C     |  | | S )zC
        `event += handler` notation for adding a handler.
        )r,   r&   r#   r#   r$   __iadd__a      
zEvent.__iadd__c                 C  r0   )zE
        `event -= handler` notation for removing a handler.
        )r.   r&   r#   r#   r$   __isub__h   r2   zEvent.__isub__r    )r   r   r   r   r   r   r   r   )r   r*   r   r   )r   r*   r   r/   )__name__
__module____qualname____doc__r%   r'   r)   r,   r.   r1   r3   r#   r#   r#   r$   r
   *   s    
	


	
r
   c                   @  s$   e Zd ZdZdddZddd	Zd
S )r   z5
    (contextlib.nested is not available on Py3)
    r   r   c                 C     d S r    r#   r(   r#   r#   r$   	__enter__u      zDummyContext.__enter__aobjectc                 G  r9   r    r#   )r"   r<   r#   r#   r$   __exit__x   r;   zDummyContext.__exit__Nr4   )r<   r=   r   r   )r5   r6   r7   r8   r:   r>   r#   r#   r#   r$   r   p   s    
r   c                      s4   e Zd ZdZdZdZd fddZdddZ  ZS )_CharSizesCachez"
    Cache for wcwidth sizes.
    @      r   r   c                   s   t    t | _d S r    )superr%   r   _long_stringsr(   	__class__r#   r$   r%      s   
z_CharSizesCache.__init__stringstrintc                   s   t |dkrtdt|}nt fdd|D }| |< t | jkr> j}|| t | jkr>| }| v r> |= |S )N   r   c                 3  s    | ]} | V  qd S r    r#   ).0cr(   r#   r$   	<genexpr>   s    z._CharSizesCache.__missing__.<locals>.<genexpr>)	lenmaxr	   sumLONG_STRING_MIN_LENrC   r+   MAX_LONG_STRINGSpopleft)r"   rF   resultlong_stringskey_to_remover#   r(   r$   __missing__   s   
z_CharSizesCache.__missing__r4   rF   rG   r   rH   )	r5   r6   r7   r8   rP   rQ   r%   rV   __classcell__r#   r#   rD   r$   r?   |   s    r?   rF   rG   r   rH   c                 C  s   t |  S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)rF   r#   r#   r$   r      s   r   boolc                   C  s
   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   
r   c                   C  s
   t jdkS )z)
    True when we are using Windows.
    win32)sysplatformr#   r#   r#   r$   r      s   
r   c                  C  s    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.
    r^   r   is_win_vt100_enabledF)r_   r`   prompt_toolkit.output.windows10rb   ra   r#   r#   r$   is_windows_vt100_supported   s   
rd   c                   C  s   t jdkotjdddkS )z7
    True when the ConEmu Windows console is used.
    r^   
ConEmuANSIOFFON)r_   r`   osenvirongetr#   r#   r#   r$   r      s   r   c                   C  s   t  jjdkS )z:
    True when the current thread is the main thread.
    _MainThread)	threadingcurrent_threadrE   r5   r#   r#   r#   r$   r      s   r   c                  C  s   t jdd} |  dv S )zD
    True if env variable is set to true (true, TRUE, True, 1).
    PROMPT_TOOLKIT_BELLtrue)1ro   )rh   ri   rj   lowervaluer#   r#   r$   r      s   r   c                   C  s   t jddS )z&Return the $TERM environment variable.TERM )rh   ri   rj   r#   r#   r#   r$   r      s   r   _Titemslist[_T]weights	list[int]Generator[_T, None, None]c                 c  s    t | t |ksJ t | dksJ g }g }t| |D ]\}}|dkr.|| || q|} |}| s9tddd | D }t | }t|}d}		 d}
|
rzd}
tt|| |D ]\}}}|| |	| t| k rw|V  ||  d7  < d}
qY|
sO|	d7 }	qK)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                 S  s   g | ]}d qS )r   r#   )rJ   ir#   r#   r$   
<listcomp>  s    z&take_using_weights.<locals>.<listcomp>TFrI   )rM   zipr+   
ValueErrorrN   rangefloat)rw   ry   items2weights2itemwalready_taken
item_count
max_weightr|   addingitem_iweightr#   r#   r$   r      s>   

	r   rs   Callable[[], str] | strc                 C     t | r	t|  S t| S )z$Turn callable or string into string.)callabler   rG   rr   r#   r#   r$   r        
r   Callable[[], int] | intc                 C  r   )zTurn callable or int into int.)r   r   rH   rr   r#   r#   r$   r   '  r   r   r   r   c                 C  r   )z"Turn callable or float into float.)r   r   r   rr   r#   r#   r$   r   2  r   r   term
str | Nonec                 C  s&   | du r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.
    Nrt   ru   )dumbunknown)r   rh   ri   rj   rq   )r   r#   r#   r$   r   :  s   r   rW   )r   rZ   )r   rG   )rw   rx   ry   rz   r   r{   )rs   r   r   rG   )rs   r   r   rH   )rs   r   r   r   r    )r   r   r   rZ   ),
__future__r   rh   r]   r_   rl   collectionsr   collections.abcr   r   
contextlibr   typingr   r   r	   __all__modulesSPHINX_AUTODOC_RUNNINGr   r
   r   dictrG   rH   r?   rY   r   r   r   rd   r   r   r   r   rv   r   r   r   r   r   r   r   r#   r#   r#   r$   <module>   s@    
F)









6

