U
    ÝÁ]t  ã                   @   sT   d Z ddlZzddlZW n& ek
r>   ddlm  mZ Y nX G dd„ deƒZdS )z8Provides Tab completion when prompting users for a path.é    Nc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú	Completera/  Provides Tab completion when prompting users for a path.

    This class is meant to be used with readline to provide Tab
    completion for users entering paths. The complete method can be
    passed to readline.set_completer directly, however, this function
    works best as a context manager. For example:

    with Completer():
        raw_input()

    In this example, Tab completion will be available during the call to
    raw_input above, however, readline will be restored to its previous
    state when exiting the body of the with statement.

    c                 C   s   d  | _  | _| _d S ©N)Ú_iterÚ_original_completerÚ_original_delims©Úself© r	   ú;/usr/lib/python3/dist-packages/certbot/display/completer.pyÚ__init__   s    zCompleter.__init__c                 C   s$   |dkrt  |d ¡| _t| jdƒS )a(  Provides path completion for use with readline.

        :param str text: text to offer completions for
        :param int state: which completion to return

        :returns: possible completion for text or ``None`` if all
            completions have been returned
        :rtype: str

        r   Ú*N)ÚglobZiglobr   Únext)r   ÚtextÚstater	   r	   r
   Úcomplete   s    zCompleter.completec                 C   sX   t  ¡ | _t  ¡ | _t  | j¡ t  d¡ t jd k	rJdt jkrJt  	d¡ n
t  	d¡ d S )Nz 	
;Úlibeditzbind ^I rl_completeztab: complete)
ÚreadlineZget_completerr   Zget_completer_delimsr   Úset_completerr   Úset_completer_delimsÚ__doc__Úparse_and_bindr   r	   r	   r
   Ú	__enter__-   s    


zCompleter.__enter__c                 C   s   t  | j¡ t  | j¡ d S r   )r   r   r   r   r   )r   Zunused_typeZunused_valueZunused_tracebackr	   r	   r
   Ú__exit__;   s    zCompleter.__exit__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	   r	   r	   r
   r   
   s
   r   )	r   r   r   ÚImportErrorZcertbot.display.dummy_readlineZdisplayZdummy_readlineÚobjectr   r	   r	   r	   r
   Ú<module>   s   