U
    -e!                     @  s  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 d dlmZ dddd	d
ddddddddddgZdejk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d dZd!d"d#d	Zd!d"d$dZd!d"d%d&Zd!d"d'd
Z d!d"d(dZ!d!d"d)dZ"dd"d*dZ#ed+Z$d,d-d.d/d0dZ%d1dd2d3dZ&d4dd2d5dZ'ee	g e(f e(f Z)dd6d2d7dZ*d;d8d!d9d:dZ+dS )<    )annotationsN)deque)CallableContextManagerDeque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                   @  s   e Zd ZdZdddddddZdd	d
dZdd	ddZdddddZdddddZdddddZ	dd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()
    Nr   z Callable[[_Sender], None] | NoneNone)senderhandlerreturnc                 C  s    || _ g | _|d k	r| |7 } d S N)r   	_handlers)selfr   r     r%   U/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/prompt_toolkit/utils.py__init__C   s    zEvent.__init__r!   c                 C  s   | j D ]}|| j qdS )zFire event.N)r#   r   r$   r    r%   r%   r&   __call__L   s    
zEvent.__call__c                 C  s
   |   dS )z!Alias for just calling the event.Nr%   r$   r%   r%   r&   fireQ   s    z
Event.firezCallable[[_Sender], None])r    r!   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_handlerU   s    zEvent.add_handlerc                 C  s   || j kr| j | dS )z6
        Remove a handler from this callback.
        N)r#   remover)   r%   r%   r&   remove_handler^   s    
zEvent.remove_handlerzEvent[_Sender]c                 C  s   |  | | S )zC
        `event += handler` notation for adding a handler.
        )r.   r)   r%   r%   r&   __iadd__e   s    
zEvent.__iadd__c                 C  s   |  | | S )zE
        `event -= handler` notation for removing a handler.
        )r0   r)   r%   r%   r&   __isub__l   s    
zEvent.__isub__)N)__name__
__module____qualname____doc__r'   r*   r,   r.   r0   r1   r2   r%   r%   r%   r&   r   .   s    		c                   @  s.   e Zd ZdZddddZddddd	Zd
S )r   z5
    (contextlib.nested is not available on Py3)
    r   r(   c                 C  s   d S r"   r%   r+   r%   r%   r&   	__enter__y   s    zDummyContext.__enter__object)ar!   c                 G  s   d S r"   r%   )r$   r9   r%   r%   r&   __exit__|   s    zDummyContext.__exit__N)r3   r4   r5   r6   r7   r:   r%   r%   r%   r&   r   t   s   c                      s>   e Zd ZdZdZdZdd fddZdd	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__strintstringr!   c                   s   t |dkrtdt|}nt fdd|D }| |< t | jkr| j}|| t | jkr|| }| k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_LENr?   r-   MAX_LONG_STRINGSpopleft)r$   rE   resultZlong_stringsZkey_to_remover%   r+   r&   __missing__   s    
z_CharSizesCache.__missing__)	r3   r4   r5   r6   rM   rN   r'   rQ   __classcell__r%   r%   r@   r&   r;      s
   r;   rB   rC   rD   c                 C  s   t |  S )z?
    Return width of a string. Wrapper around ``wcwidth``.
    )_CHAR_SIZES_CACHE)rE   r%   r%   r&   r      s    boolr(   c                   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    c                   C  s
   t jdkS )z)
    True when we are using Windows.
    win32)sysplatformr%   r%   r%   r&   r      s    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.
    rX   r   is_win_vt100_enabledF)rY   rZ   Zprompt_toolkit.output.windows10r\   r[   r%   r%   r&   is_windows_vt100_supported   s    
r]   c                   C  s   t jdkotjdddkS )z7
    True when the ConEmu Windows console is used.
    rX   Z
ConEmuANSIZOFFON)rY   rZ   osenvirongetr%   r%   r%   r&   r      s    c                   C  s   t  jjdkS )z:
    True when the current thread is the main thread.
    _MainThread)	threadingcurrent_threadrA   r3   r%   r%   r%   r&   r      s    c                  C  s   t jdd} |  dkS )zD
    True if env variable is set to true (true, TRUE, True, 1).
    ZPROMPT_TOOLKIT_BELLtrue)1re   )r_   r`   ra   lowervaluer%   r%   r&   r      s    c                   C  s   t jddS )z&Return the $TERM environment variable.TERM )r_   r`   ra   r%   r%   r%   r&   r      s    _Tzlist[_T]z	list[int]zGenerator[_T, None, None])itemsweightsr!   c                 c  s   t | t |kstt | dks$tg }g }t| |D ]$\}}|dkr6|| || q6|} |}| sptddd | D }t | }t|}d}	d}
|
rd}
tt|| |D ]<\}}}|| |	| t| k r|V  ||  d7  < d}
qq|	d7 }	qdS )	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%   )rG   ir%   r%   r&   
<listcomp>  s     z&take_using_weights.<locals>.<listcomp>TFrF   N)rJ   AssertionErrorzipr-   
ValueErrorrK   rangefloat)rm   rn   Zitems2Zweights2itemwZalready_taken
item_countZ
max_weightro   ZaddingZitem_iweightr%   r%   r&   r      s2    
zCallable[[], str] | str)ri   r!   c                 C  s   t | rt|  S t| S dS )z$Turn callable or string into string.N)callabler   rB   rh   r%   r%   r&   r   #  s    
zCallable[[], int] | intc                 C  s   t | rt|  S t| S dS )zTurn callable or int into int.N)rz   r   rC   rh   r%   r%   r&   r   +  s    
ru   c                 C  s   t | rt|  S t| S dS )z"Turn callable or float into float.N)rz   r   ru   rh   r%   r%   r&   r   6  s    
z
str | None)termr!   c                 C  s&   | dkrt tjddS |  dk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.
    Nrj   rk   )dumbunknown)r   r_   r`   ra   rg   )r{   r%   r%   r&   r   >  s    )N),
__future__r   r_   rW   rY   rc   collectionsr   typingr   r   r   r   r   r	   r
   r   r   __all__modulesZSPHINX_AUTODOC_RUNNINGr   r   r   rB   rC   r;   rS   r   r   r   r]   r   r   r   r   rl   r   r   r   ru   r   r   r   r%   r%   r%   r&   <module>   sX   (
F)6