a
    lc                     @   s   d Z ddlmZmZ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.
    )AnyDictIterableMappingOptionalSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                   @   sh   e Zd ZdZdeeee f eddddZ	eddd	Z
eed d
ddZeeee 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.
    TN)optionsignore_casereturnc                 C   s   || _ || _d S Nr   r   )selfr   r    r   \/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/completion/nested.py__init__   s    zNestedCompleter.__init__)r   c                 C   s   d| j d| jdS )NzNestedCompleter(z, ignore_case=)r   )r   r   r   r   __repr__#   s    zNestedCompleter.__repr__)datar   c                 C   s   i }|  D ]n\}}t|tr(|||< qt|trB| |||< qt|trf| dd |D ||< q|du srJ 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>F       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)documentcomplete_eventr   c           
      c   s   |j  }t|j t| }d|v r| d }| j|}|d ur|t|d   }t|t| | }t||j| d}	||	|E d H  n*t	t
| j | jd}|||E d H  d S )N r   )cursor_position)r   )Ztext_before_cursorlstriplensplitr   getr   r*   get_completionsr   listkeysr   )
r   r'   r(   textZstripped_lenZ
first_termZ	completerZremaining_textZmove_cursorZnew_documentr   r   r   r/   M   s"    
zNestedCompleter.get_completions)T)__name__
__module____qualname____doc__r   strr   r
   boolr   r   classmethod
NestedDictr"   r   r	   r   r   r/   r   r   r   r   r      s    ')r6   typingr   r   r   r   r   r   r   Zprompt_toolkit.completionr	   r
   r   Z(prompt_toolkit.completion.word_completerr   Zprompt_toolkit.documentr   __all__r7   r:   r   r   r   r   r   <module>   s   $