o
    Df                     @  s   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZ dgZeeeeee def f ZG d	d deZdS )
zA
Nestedcompleter for completion of hierarchical data structures.
    )annotations)AnyIterableMappingSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                   @  s@   e Zd ZdZ	ddd	d
ZdddZedddZdddZdS )r   a  
    Completer which wraps around several other completers, and calls any the
    one that corresponds with the first word of the input.

    By combining multiple `NestedCompleter` instances, we can achieve multiple
    hierarchical levels of autocompletion. This is useful when `WordCompleter`
    is not sufficient.

    If you need multiple levels, check out the `from_nested_dict` classmethod.
    Toptionsdict[str, Completer | None]ignore_caseboolreturnNonec                 C  s   || _ || _d S Nr   r   )selfr   r    r   Y/home/ubuntu/webapp/venv/lib/python3.10/site-packages/prompt_toolkit/completion/nested.py__init__   s   
zNestedCompleter.__init__strc                 C  s   d| j d| jdS )NzNestedCompleter(z, ignore_case=)r   )r   r   r   r   __repr__%   s   zNestedCompleter.__repr__data
NestedDictc                 C  s   i }|  D ]7\}}t|tr|||< qt|tr!| |||< qt|tr3| dd |D ||< q|du s9J d||< q| |S )a  
        Create a `NestedCompleter`, starting from a nested dictionary data
        structure, like this:

        .. code::

            data = {
                'show': {
                    'version': None,
                    'interfaces': None,
                    'clock': None,
                    'ip': {'interface': {'brief'}}
                },
                'exit': None
                'enable': None
            }

        The value should be `None` if there is no further completion at some
        point. If all values in the dictionary are None, it is also possible to
        use a set instead.

        Values in this data structure can be a completers as well.
        c                 S  s   i | ]}|d qS r   r   ).0itemr   r   r   
<dictcomp>H   s    z4NestedCompleter.from_nested_dict.<locals>.<dictcomp>N)items
isinstancer	   dictfrom_nested_dictset)clsr   r   keyvaluer   r   r   r%   (   s   




z NestedCompleter.from_nested_dictdocumentr   complete_eventr   Iterable[Completion]c           
      c  s    |j  }t|j t| }d|v rM| d }| j|}|d urK|t|d   }t|t| | }t||j| d}	||	|E d H  d S d S t	t
| j | jd}|||E d H  d S )N r   )cursor_position)r   )text_before_cursorlstriplensplitr   getr   r.   get_completionsr   listkeysr   )
r   r*   r+   textstripped_len
first_term	completerremaining_textmove_cursornew_documentr   r   r   r4   O   s&   
zNestedCompleter.get_completionsN)T)r   r   r   r   r   r   )r   r   )r   r   r   r   )r*   r   r+   r   r   r,   )	__name__
__module____qualname____doc__r   r   classmethodr%   r4   r   r   r   r   r      s    
&)rA   
__future__r   typingr   r   r   r   r   prompt_toolkit.completionr   r	   r
   (prompt_toolkit.completion.word_completerr   prompt_toolkit.documentr   __all__r   r   r   r   r   r   r   <module>   s    