a
    lcc3                     @   s4  d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZ ddlmZmZ g dZG d	d
 d
ZG dd dZG dd dedZG dd deZG dd deZG dd deZG dd deZG dd deZd%e	e eedddZee	e eddd Z ee ed!d"d#Z!d$S )&
    )ABCMetaabstractmethod)AsyncGeneratorCallableIterableOptionalSequence)Documentgenerator_to_async_generator)FilterOrBool	to_filter)AnyFormattedTextStyleAndTextTuples)	
Completion	CompleterThreadedCompleterDummyCompleterDynamicCompleterCompleteEventConditionalCompletermerge_completersget_common_complete_suffixc                	   @   s   e Zd ZdZdeeee ee eeddddZedd	d
Z	e
edddZedddZeedddZeedddZeedddZed dddZdS )r   a  
    :param text: The new string that will be inserted into the document.
    :param start_position: Position relative to the cursor_position where the
        new text will start. The text will be inserted between the
        start_position and the original cursor position.
    :param display: (optional string or formatted text) If the completion has
        to be displayed differently in the completion menu.
    :param display_meta: (Optional string or formatted text) Meta information
        about the completion, e.g. the path or source where it's coming from.
        This can also be a callable that returns a string.
    :param style: Style string.
    :param selected_style: Style string, used for a selected completion.
        This can override the `style` parameter.
    r   N )textstart_positiondisplaydisplay_metastyleselected_stylereturnc                 C   sR   ddl m} || _|| _|| _|d u r*|}||| _|| _|| _| jdksNJ d S )Nr   to_formatted_text)prompt_toolkit.formatted_textr#   r   r   _display_metar   r   r    )selfr   r   r   r   r   r    r#    r'   Z/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/completion/base.py__init__(   s    

zCompletion.__init__r!   c                 C   sL   t | jtr.| j| jkr.d| jj| j| jS d| jj| j| j| jS d S )Nz"{}(text={!r}, start_position={!r})z0{}(text={!r}, start_position={!r}, display={!r}))
isinstancer   strr   format	__class____name__r   r&   r'   r'   r(   __repr__B   s    zCompletion.__repr__)otherr!   c                 C   s>   t |tsdS | j|jko<| j|jko<| j|jko<| j|jkS )NF)r+   r   r   r   r   r%   )r&   r2   r'   r'   r(   __eq__Q   s    



zCompletion.__eq__c                 C   s   t | j| j| j| jfS N)hashr   r   r   r%   r0   r'   r'   r(   __hash__[   s    zCompletion.__hash__c                 C   s   ddl m} || jS )z"The 'display' field as plain text.r   fragment_list_to_text)r$   r8   r   r&   r8   r'   r'   r(   display_text^   s    zCompletion.display_textc                 C   s   ddl m} || jpdS )z7Return meta-text. (This is lazy when using a callable).r   r"   r   )r$   r#   r%   )r&   r#   r'   r'   r(   r   e   s    zCompletion.display_metac                 C   s   ddl m} || jS )zThe 'meta' field as plain text.r   r7   )r$   r8   r   r9   r'   r'   r(   display_meta_textl   s    zCompletion.display_meta_text)positionr!   c                 C   s4   || j  dksJ t| j|| j  d | j| jdS )z
        (Only for internal use!)
        Get a new completion by splitting this one. Used by `Application` when
        it needs to have a list of new completions after inserting the common
        prefix.
        r   N)r   r   r   )r   r   r   r   r%   )r&   r<   r'   r'   r(   new_completion_from_positions   s    z'Completion.new_completion_from_position)r   NNr   r   )r/   
__module____qualname____doc__r,   intr   r   r)   r1   objectboolr3   r6   propertyr:   r   r   r;   r=   r'   r'   r'   r(   r      s2        
r   c                   @   s2   e Zd ZdZd
eeddddZeddd	ZdS )r   a3  
    Event that called the completer.

    :param text_inserted: When True, it means that completions are requested
        because of a text insert. (`Buffer.complete_while_typing`.)
    :param completion_requested: When True, it means that the user explicitly
        pressed the `Tab` key in order to view the completions.

    These two flags can be used for instance to implement a completer that
    shows some completions when ``Tab`` has been pressed, but not
    automatically when the user presses a space. (Because of
    `complete_while_typing`.)
    FN)text_insertedcompletion_requestedr!   c                 C   s   |r|rJ || _ || _d S r4   )rE   rF   )r&   rE   rF   r'   r'   r(   r)      s    zCompleteEvent.__init__r*   c                 C   s   d | jj| j| jS )Nz1{}(text_inserted={!r}, completion_requested={!r}))r-   r.   r/   rE   rF   r0   r'   r'   r(   r1      s
    zCompleteEvent.__repr__)FF)r/   r>   r?   r@   rC   r)   r,   r1   r'   r'   r'   r(   r      s    r   c                   @   sD   e Zd ZdZeeeee dddZ	eee
edf dddZdS )r   z3
    Base class for completer implementations.
    documentcomplete_eventr!   c                 c   s   dS )a$  
        This should be a generator that yields :class:`.Completion` instances.

        If the generation of completions is something expensive (that takes a
        lot of time), consider wrapping this `Completer` class in a
        `ThreadedCompleter`. In that case, the completer algorithm runs in a
        background thread and completions will be displayed as soon as they
        arrive.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        :param complete_event: :class:`.CompleteEvent` instance.
        Nr'   r&   rH   rI   r'   r'   r(   get_completions   s    zCompleter.get_completionsNc                 C  s   |  ||D ]
}|V  qdS )z
        Asynchronous generator for completions. (Probably, you won't have to
        override this.)

        Asynchronous generator of :class:`.Completion` objects.
        N)rK   r&   rH   rI   itemr'   r'   r(   get_completions_async   s    	zCompleter.get_completions_async)r/   r>   r?   r@   r   r
   r   r   r   rK   r   rN   r'   r'   r'   r(   r      s   
r   )	metaclassc                   @   s^   e Zd ZdZeddddZeeee	 dddZ
eeee	df dd	d
ZedddZdS )r   ai  
    Wrapper that runs the `get_completions` generator in a thread.

    (Use this to prevent the user interface from becoming unresponsive if the
    generation of completions takes too much time.)

    The completions will be displayed as soon as they are produced. The user
    can already select a completion, even if not all completions are displayed.
    N)	completerr!   c                 C   s
   || _ d S r4   rP   )r&   rP   r'   r'   r(   r)      s    zThreadedCompleter.__init__rG   c                 C   s   | j ||S r4   rP   rK   rJ   r'   r'   r(   rK      s    z!ThreadedCompleter.get_completionsc                   s.   t  fdd2 z3 dH W }|V  q6 dS )z8
        Asynchronous generator of completions.
        c                      s   j  S r4   rR   r'   rI   rH   r&   r'   r(   <lambda>       z9ThreadedCompleter.get_completions_async.<locals>.<lambda>Nr   )r&   rH   rI   
completionr'   rS   r(   rN      s    z'ThreadedCompleter.get_completions_asyncr*   c                 C   s   d| j dS )NzThreadedCompleter()rQ   r0   r'   r'   r(   r1      s    zThreadedCompleter.__repr__)r/   r>   r?   r@   r   r)   r
   r   r   r   rK   r   rN   r,   r1   r'   r'   r'   r(   r      s   

r   c                   @   s4   e Zd ZdZeeee dddZe	dddZ
dS )	r   z9
    A completer that doesn't return any completion.
    rG   c                 C   s   g S r4   r'   rJ   r'   r'   r(   rK      s    zDummyCompleter.get_completionsr*   c                 C   s   dS )NzDummyCompleter()r'   r0   r'   r'   r(   r1      s    zDummyCompleter.__repr__N)r/   r>   r?   r@   r
   r   r   r   rK   r,   r1   r'   r'   r'   r(   r      s
   r   c                   @   sj   e Zd ZdZeg ee f ddddZee	e
e dddZee	eedf dd	d
ZedddZdS )r   z
    Completer class that can dynamically returns any Completer.

    :param get_completer: Callable that returns a :class:`.Completer` instance.
    N)get_completerr!   c                 C   s
   || _ d S r4   rX   )r&   rX   r'   r'   r(   r)     s    zDynamicCompleter.__init__rG   c                 C   s   |   pt }|||S r4   )rX   r   rK   r&   rH   rI   rP   r'   r'   r(   rK     s    z DynamicCompleter.get_completionsc                 C  s4   |   pt }|||2 z3 d H W }|V  q6 d S r4   )rX   r   rN   )r&   rH   rI   rP   rV   r'   r'   r(   rN   
  s
    z&DynamicCompleter.get_completions_asyncr*   c                 C   s   d| j d|   dS )NzDynamicCompleter(z -> rW   rY   r0   r'   r'   r(   r1     s    zDynamicCompleter.__repr__)r/   r>   r?   r@   r   r   r   r)   r
   r   r   r   rK   r   rN   r,   r1   r'   r'   r'   r(   r      s   

r   c                   @   s`   e Zd ZdZeeddddZedddZe	e
ee d	d
dZe	e
eedf d	ddZdS )r   z
    Wrapper around any other completer that will enable/disable the completions
    depending on whether the received condition is satisfied.

    :param completer: :class:`.Completer` instance.
    :param filter: :class:`.Filter` instance.
    N)rP   filterr!   c                 C   s   || _ t|| _d S r4   )rP   r   r[   )r&   rP   r[   r'   r'   r(   r)   !  s    zConditionalCompleter.__init__r*   c                 C   s   d| j d| jdS )NzConditionalCompleter(z	, filter=rW   )rP   r[   r0   r'   r'   r(   r1   %  s    zConditionalCompleter.__repr__rG   c                 c   s    |   r| j||E d H  d S r4   )r[   rP   rK   rJ   r'   r'   r(   rK   (  s    z$ConditionalCompleter.get_completionsc                 C  s0   |   r,| j||2 z3 d H W }|V  q6 d S r4   )r[   rP   rN   rL   r'   r'   r(   rN   /  s
    z*ConditionalCompleter.get_completions_async)r/   r>   r?   r@   r   r   r)   r,   r1   r
   r   r   r   rK   r   rN   r'   r'   r'   r(   r     s   
r   c                   @   sT   e Zd ZdZee ddddZeee	e
 dddZeeee
df dd	d
ZdS )_MergedCompleterz.
    Combine several completers into one.
    N)
completersr!   c                 C   s
   || _ d S r4   )r]   )r&   r]   r'   r'   r(   r)   @  s    z_MergedCompleter.__init__rG   c                 c   s"   | j D ]}|||E d H  qd S r4   )r]   rK   rZ   r'   r'   r(   rK   C  s    
z _MergedCompleter.get_completionsc                 C  s2   | j D ]&}|||2 z3 d H W }|V  q6 qd S r4   )r]   rN   )r&   rH   rI   rP   rM   r'   r'   r(   rN   J  s    
z&_MergedCompleter.get_completions_async)r/   r>   r?   r@   r	   r   r)   r
   r   r   r   rK   r   rN   r'   r'   r'   r(   r\   ;  s   
r\   F)r]   deduplicater!   c                 C   s$   |rddl m} |t| S t| S )z
    Combine several completers into one.

    :param deduplicate: If `True`, wrap the result in a `DeduplicateCompleter`
        so that completions that would result in the same text will be
        deduplicated.
       )DeduplicateCompleter)r^   r`   r\   )r]   r^   r`   r'   r'   r(   r   T  s    
r   )rH   completionsr!   c                    s`   t td fddfdd|D }t|t|kr:dS t tdddtfd	d|D S )
z7
    Return the common prefix for all completions.
    )rV   r!   c                    s   | j d | j  } j|S r4   )r   r   Ztext_before_cursorendswith)rV   end)rH   r'   r(   doesnt_change_before_cursorm  s    z?get_common_complete_suffix.<locals>.doesnt_change_before_cursorc                    s   g | ]} |r|qS r'   r'   .0c)rd   r'   r(   
<listcomp>q  rU   z.get_common_complete_suffix.<locals>.<listcomp>r   c                 S   s   | j | j d  S r4   )r   r   )rV   r'   r'   r(   
get_suffixy  s    z.get_common_complete_suffix.<locals>.get_suffixc                    s   g | ]} |qS r'   r'   re   )ri   r'   r(   rh   |  rU   )r   rC   lenr,   _commonprefix)rH   ra   Zcompletions2r'   )rH   rd   ri   r(   r   f  s    r   )stringsr!   c                 C   sN   | sdS t | }t| }t|D ]$\}}||| kr |d |   S q |S d S )Nr   )minmax	enumerate)rl   s1s2irg   r'   r'   r(   rk     s    rk   N)F)"r@   abcr   r   typingr   r   r   r   r	   Zprompt_toolkit.documentr
   Zprompt_toolkit.eventloopr   Zprompt_toolkit.filtersr   r   r$   r   r   __all__r   r   r   r   r   r   r   r\   rC   r   r,   r   rk   r'   r'   r'   r(   <module>   s0   k"%"# 