o
    w¨Êh·!  ã                   @  sp  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	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!d?d$d%„Z"ed&ƒZ#d@d,d-„Z$dAd0d1„Z%dBd3d4„Z&ee	g e'f e'f Z(dCd7d8„Z)dDdEd;d<„Z*dS )Fé    )Ú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                   @  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%   úF/var/www/html/env/lib/python3.10/site-packages/prompt_toolkit/utils.pyÚ__init__B   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__K   s   
ÿzEvent.__call__c                 C  s
   | ƒ  dS )z!Alias for just calling the event.Nr%   ©r$   r%   r%   r&   ÚfireP   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_handlerT   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_handler]   s   
ÿzEvent.remove_handlerúEvent[_Sender]c                 C  ó   |   |¡ | S )zC
        `event += handler` notation for adding a handler.
        )r.   r(   r%   r%   r&   Ú__iadd__d   ó   
zEvent.__iadd__c                 C  r2   )zE
        `event -= handler` notation for removing a handler.
        )r0   r(   r%   r%   r&   Ú__isub__k   r4   zEvent.__isub__r"   )r   r   r   r   r    r!   ©r    r!   )r   r,   r    r!   )r   r,   r    r1   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   r)   r+   r.   r0   r3   r5   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__x   ó   zDummyContext.__enter__ÚaÚobjectc                 G  r;   r"   r%   )r$   r>   r%   r%   r&   Ú__exit__{   r=   zDummyContext.__exit__Nr6   )r>   r?   r    r!   )r7   r8   r9   r:   r<   r@   r%   r%   r%   r&   r   s   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_LENrE   r-   ÚMAX_LONG_STRINGSÚpopleft)r$   rH   ÚresultÚlong_stringsÚkey_to_remover%   r*   r&   Ú__missing__Œ   s   
z_CharSizesCache.__missing__r6   ©rH   rI   r    rJ   )	r7   r8   r9   r:   rR   rS   r'   rX   Ú__classcell__r%   r%   rF   r&   rA      s    rA   rH   rI   r    rJ   c                 C  s   t |  S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )Ú_CHAR_SIZES_CACHE)rH   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)ra   rb   Úprompt_toolkit.output.windows10rd   rc   r%   r%   r&   Úis_windows_vt100_supportedÁ   s   
rf   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)ra   rb   Ú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_threadrG   r7   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)Ú1rq   )rj   rk   rl   Úlower©Úvaluer%   r%   r&   r   Ü   s   r   c                   C  s   t j dd¡S )z&Return the $TERM environment variable.ÚTERMÚ )rj   rk   rl   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%   )rL   Úir%   r%   r&   Ú
<listcomp>  s    z&take_using_weights.<locals>.<listcomp>TFrK   )rO   Úzipr-   Ú
ValueErrorrP   ÚrangeÚfloat)ry   r{   Úitems2Úweights2ÚitemÚwÚalready_takenÚ
item_countÚ
max_weightr~   ÚaddingÚitem_iÚweightr%   r%   r&   r   ì   s>   €

€€ù	ôr   ru   úCallable[[], str] | strc                 C  ó   t | ƒr	t| ƒ ƒS t| ƒS )z$Turn callable or string into string.)Úcallabler   rI   rt   r%   r%   r&   r   "  ó   
r   úCallable[[], int] | intc                 C  r�   )zTurn callable or int into int.)r�   r   rJ   rt   r%   r%   r&   r   *  r‘   r   r   rƒ   c                 C  r�   )z"Turn callable or float into float.)r�   r   rƒ   rt   r%   r%   r&   r   5  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.
    Nrv   rw   )ÚdumbÚunknown)r   rj   rk   rl   rs   )r“   r%   r%   r&   r   =  s   r   rY   )r    r\   )r    rI   )ry   rz   r{   r|   r    r}   )ru   rŽ   r    rI   )ru   r’   r    rJ   )ru   r   r    rƒ   r"   )r“   r”   r    r\   )+Ú
__future__r   rj   r_   ra   rn   Úcollectionsr   Útypingr   r   r   r   r   r	   r
   r   Ú__all__ÚmodulesÚSPHINX_AUTODOC_RUNNINGr   r   r   rI   rJ   rA   r[   r   r   r   rf   r   r   r   r   rx   r   r   r   rƒ   r   r   r   r%   r%   r%   r&   Ú<module>   s<    $

F)









6

