o
    ñu]ã  ã                   @   s\   d Z ddlZddlmZ ej ¡ rddlmZ nddl	mZ edd„ ƒZ
G dd„ deƒZdS )	z,
Tab completion for our interpreter prompt.
é    N)Úuses_settings)Ú	lru_cachec           
         s@  |  dg ¡}| du r|S |  dd¡}|r.| ¡ D ]}| dd¡d  d¡}| d| ¡ qn| d	¡ |  d
d¡}|r`| ¡ D ]}| dd¡d }| d| ¡ | d| ¡ | d| ¡ q?n|g d¢7 }d}|D ]\‰ }|  |d¡}|r„|‡ fdd„| ¡ D ƒ7 }qj| ˆ ¡ qj|  di ¡}| ¡ D ]	}	| d|	 ¡ q”|S )z*
  Provides commands recognized by tor.
  ZautocompleteNz
info/namesú é   r   Ú*z
GETINFO %szGETINFO zconfig/namesz
GETCONF %sz
SETCONF %szRESETCONF %s)zGETCONF zSETCONF z
RESETCONF ))z
SETEVENTS zevents/names)zUSEFEATURE zfeatures/names)zSIGNAL zsignal/namesc                    s   g | ]}ˆ | ‘qS © r   )Ú.0Úvalue©Úprefixr   ú?/usr/lib/python3/dist-packages/stem/interpreter/autocomplete.pyÚ
<listcomp>E   s    z!_get_commands.<locals>.<listcomp>z
help.usagez/help )ÚgetZget_infoÚ
splitlinesÚsplitÚrstripÚappendÚkeys)
Ú
controllerZconfigZcommandsÚresultsÚlineÚoptionÚoptionsZgetinfo_cmdZ
usage_infoÚcmdr   r
   r   Ú_get_commands   s:   þ
ûr   c                   @   s*   e Zd Zdd„ Zeƒ dd„ ƒZdd„ ZdS )ÚAutocompleterc                 C   s   t |ƒ| _d S )N)r   Ú	_commands)Úselfr   r   r   r   Ú__init__T   s   zAutocompleter.__init__c                    s   |  ¡ ‰ ‡ fdd„| jD ƒS )z¯
    Provides autocompletion matches for the given text.

    :param str text: text to check for autocompletion matches with

    :returns: **list** with possible matches
    c                    s   g | ]}|  ¡  ˆ ¡r|‘qS r   )ÚlowerÚ
startswith)r   r   ©Zlowercase_textr   r   r   b   s    z)Autocompleter.matches.<locals>.<listcomp>)r   r   )r   Útextr   r!   r   ÚmatchesW   s   
zAutocompleter.matchesc                 C   s&   z|   |¡| W S  ty   Y dS w )aÀ  
    Provides case insensetive autocompletion options, acting as a functor for
    the readlines set_completer function.

    :param str text: text to check for autocompletion matches with
    :param int state: index of result to be provided, readline fetches matches
      until this function provides None

    :returns: **str** with the autocompletion match, **None** if eithe none
      exists or state is higher than our number of matches
    N)r#   Ú
IndexError)r   r"   Ústater   r   r   Úcompleted   s
   ÿzAutocompleter.completeN)Ú__name__Ú
__module__Ú__qualname__r   r   r#   r&   r   r   r   r   r   S   s
    
r   )Ú__doc__Zstem.prereqZstemZstem.interpreterr   ZprereqZ_is_lru_cache_availableÚ	functoolsr   Zstem.util.lru_cacher   Úobjectr   r   r   r   r   Ú<module>   s   

@