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

