o
    ª`W§  ã                   @   sŒ   d dl mZmZmZmZ d dlZd dlZddlmZm	Z	 dd„ Z
G dd„ deƒZd	d
„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsNé   )ÚstrÚsys_encodingc                  O   s6   zt j| i |¤Ž t¡ ¡ W S  t jy   g  Y S w ©N)Ú
subprocessÚcheck_outputÚdecoder   Ú
splitlinesÚCalledProcessError)ÚargsÚkwargs© r   ú8/usr/lib/python3/dist-packages/argcomplete/completers.pyÚ_call
   s
   ÿr   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚChoicesCompleterc                 C   sF   g | _ |D ]}t|tƒr| t¡}t|tƒst|ƒ}| j  |¡ qd S r	   )ÚchoicesÚ
isinstanceÚbytesr   r   r   Úappend)Úselfr   Úchoicer   r   r   Ú__init__   s   


ûzChoicesCompleter.__init__c                    s   ‡ fdd„| j D ƒS )Nc                 3   ó   � | ]
}|  ˆ ¡r|V  qd S r	   ©Ú
startswith)Ú.0Úc©Úprefixr   r   Ú	<genexpr>   ó   € z,ChoicesCompleter.__call__.<locals>.<genexpr>)r   )r   r#   r   r   r"   r   Ú__call__   ó   zChoicesCompleter.__call__N©Ú__name__Ú
__module__Ú__qualname__r   r&   r   r   r   r   r      s    	r   c                    s   ‡ fdd„t jD ƒS )Nc                 3   r   r	   r   )r    Úvr"   r   r   r$      r%   z#EnvironCompleter.<locals>.<genexpr>)ÚosÚenviron)r#   r   r   r"   r   ÚEnvironCompleter   r'   r/   c                   @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
ÚFilesCompleterzM
    File completer class, optionally takes a list of allowed extensions
    r   Tc                 C   s.   t |ttfƒr
|g}dd„ |D ƒ| _|| _d S )Nc                 S   s   g | ]
}|  d ¡  d¡‘qS )Ú*Ú.)Úlstrip)r    Úxr   r   r   Ú
<listcomp>*   s    z+FilesCompleter.__init__.<locals>.<listcomp>)r   r   r   ÚallowednamesÚdirectories)r   r6   r7   r   r   r   r   %   s   
zFilesCompleter.__init__c              	   K   sÄ   g }| j r2| jrtdddj|d�gƒ}|dd„ |D ƒ7 }| j D ]}|tdddj||d�gƒ7 }q|S |tdddj|d�gƒ7 }tdddj|d�gƒ}tt|ƒt|ƒ ƒ}| jr`|d	d„ |D ƒ7 }|S )
NÚbashz-czcompgen -A directory -- '{p}')Úpc                 S   ó   g | ]}|d  ‘qS ©ú/r   ©r    Úfr   r   r   r5   2   ó    z+FilesCompleter.__call__.<locals>.<listcomp>z$compgen -A file -X '!*.{0}' -- '{p}'zcompgen -A file -- '{p}'c                 S   r:   r;   r   r=   r   r   r   r5   ;   r?   )r6   r7   r   ÚformatÚlistÚset)r   r#   r   Ú
completionÚfilesr4   Úanticompr   r   r   r&   -   s   
úzFilesCompleter.__call__N)r   T)r)   r*   r+   Ú__doc__r   r&   r   r   r   r   r0       s    
r0   c                   @   r   )Ú_FilteredFilesCompleterc                 C   s   |sJ dƒ‚|| _ dS )z–
        Create the completer

        A predicate accepts as its only argument a candidate path and either
        accepts it or rejects it.
        zExpected a callable predicateN©Ú	predicate)r   rI   r   r   r   r   ?   s   
z _FilteredFilesCompleter.__init__c                 k   sˆ   � t j |¡}z	t  |pd¡}W n   Y dS t j |¡}|D ]"}| |¡s'qt j ||¡}|  |¡s4qt j |¡r>|d n|V  qdS )z/
        Provide completions on prefix
        r2   Nr<   )	r-   ÚpathÚdirnameÚlistdirÚbasenamer   ÚjoinrI   Úisdir)r   r#   r   Ú
target_dirÚnamesÚincomplete_partÚnameÚ	candidater   r   r   r&   I   s   €

úz _FilteredFilesCompleter.__call__Nr(   r   r   r   r   rG   >   s    
rG   c                   @   s   e Zd Zdd„ ZdS )ÚDirectoriesCompleterc                 C   s   t j| tjjd� d S )NrH   )rG   r   r-   rJ   rO   )r   r   r   r   r   ]   s   zDirectoriesCompleter.__init__N)r)   r*   r+   r   r   r   r   r   rU   \   s    rU   )Ú
__future__r   r   r   r   r-   r
   Úcompatr   r   r   Úobjectr   r/   r0   rG   rU   r   r   r   r   Ú<module>   s   