
    Mh                        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e          ZdS )
zA
Nestedcompleter for completion of hierarchical data structures.
    )annotations)AnyIterableMappingSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                  F    e Zd ZdZ	 ddd	ZddZedd            Z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                "    || _         || _        d S )Nr   r   )selfr   r   s      `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/completion/nested.py__init__zNestedCompleter.__init__   s     &    strc                (    d| j         d| j        dS )NzNestedCompleter(z, ignore_case=)r   )r   s    r   __repr__zNestedCompleter.__repr__%   s     U$,UU@PUUUUr   data
NestedDictc                   i }|                                 D ]\  }}t          |t                    r|||<    t          |t                    r|                     |          ||<   Nt          |t
                    r1|                     t                              |                    ||<   |J d||<    | |          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.
        N)items
isinstancer
   dictfrom_nested_dictsetfromkeys)clsr    r   keyvalues        r   r&   z NestedCompleter.from_nested_dict(   s    2 02**,, 		$ 		$JC%++ $$E4(( $"33E::E3'' $"33DMM%4H4HII}}}#s7||r   documentr   complete_eventr	   Iterable[Completion]c              #    K   |j                                         }t          |j                   t          |          z
  }d|v r|                                d         }| j                            |          }||t          |          d                                          }t          |          t          |          z
  |z   }t          ||j        |z
            }	|                    |	|          E d {V  d S d S t          t          | j                                                  | j                  }|                    ||          E d {V  d S )N r   )cursor_position)r   )text_before_cursorlstriplensplitr   getr   r1   get_completionsr   listkeysr   )
r   r,   r-   textstripped_len
first_term	completerremaining_textmove_cursornew_documents
             r   r7   zNestedCompleter.get_completionsO   sm      *11338677#d))C $;;aJ((44I $!%c*oo&7&7!8!?!?!A!A!$ii#n*=*==L'"$,$<{$J     
 %44\>RRRRRRRRRRR %$ &T\&&(())t7G  I !00>JJJJJJJJJJJr   N)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&   r7    r   r   r   r      s        	 	 IM' ' ' ' 'V V V V $ $ $ [$LK K K K K Kr   )rD   
__future__r   typingr   r   r   r   r   prompt_toolkit.completionr	   r
   r   (prompt_toolkit.completion.word_completerr   prompt_toolkit.documentr   __all__r   r!   r   rF   r   r   <module>rM      s    # " " " " " 5 5 5 5 5 5 5 5 5 5 5 5 5 5 J J J J J J J J J J B B B B B B , , , , , ,
 S%SXtY >??@
ZK ZK ZK ZK ZKi ZK ZK ZK ZK ZKr   