U
    ue                     @   s   d dl Z d dlZd dlZdd ZG dd dZG dd deZeejZG dd	 d	eZG d
d deZ	G dd de	Z
G dd deZdS )    Nc                  O   s:   d|d< zt j| | W S  t jk
r4   g  Y S X d S )NTZuniversal_newlines)
subprocessZcheck_output
splitlinesZCalledProcessError)argskwargs r   5lib/python3.8/site-packages/argcomplete/completers.py_call	   s
    r   c                   @   s*   e Zd ZdZeejejejdddZ	dS )BaseCompleterzQ
    This is the base class that all argcomplete completers should subclass.
    )prefixactionparserparsed_argsc                C   s   t dd S )Nz0This method should be implemented by a subclass.)NotImplementedError)selfr
   r   r   r   r   r   r   __call__   s    zBaseCompleter.__call__N)
__name__
__module____qualname____doc__strargparseActionArgumentParser	Namespacer   r   r   r   r   r	      s      r	   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ChoicesCompleterc                 C   s
   || _ d S Nchoices)r   r   r   r   r   __init__   s    zChoicesCompleter.__init__c                 C   s   t |tst|}|S r   )
isinstancer   )r   choicer   r   r   _convert!   s    
zChoicesCompleter._convertc                    s    fdd j D S )Nc                 3   s   | ]}  |V  qd S r   )r!   ).0cr   r   r   	<genexpr>'   s     z,ChoicesCompleter.__call__.<locals>.<genexpr>r   )r   r   r   r$   r   r   &   s    zChoicesCompleter.__call__N)r   r   r   r   r!   r   r   r   r   r   r      s   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>7   s     z+FilesCompleter.__init__.<locals>.<listcomp>)r   r   bytesallowednamesdirectories)r   r-   r.   r   r   r   r   2   s    zFilesCompleter.__init__c              	   K   s   g }| j rb| jr8tdddj|dg}|dd |D 7 }| j D ] }|tdddj||dg7 }q>n\|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 )
NZbashz-czcompgen -A directory -- '{p}')pc                 S   s   g | ]}|d  qS /r   r"   fr   r   r   r+   ?   s     z+FilesCompleter.__call__.<locals>.<listcomp>z$compgen -A file -X '!*.{0}' -- '{p}'zcompgen -A file -- '{p}'c                 S   s   g | ]}|d  qS r0   r   r2   r   r   r   r+   H   s     )r-   r.   r   formatlistset)r   r
   r   Z
completionfilesr*   Zanticompr   r   r   r   :   s    
 zFilesCompleter.__call__N)r   T)r   r   r   r   r   r   r   r   r   r   r&   -   s   
r&   c                   @   s   e Zd Zdd Zdd ZdS )_FilteredFilesCompleterc                 C   s   |st 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)AssertionError	predicate)r   r:   r   r   r   r   M   s    z _FilteredFilesCompleter.__init__c                 k   s   t j|}zt |pd}W n tk
r4   Y dS X t j|}|D ]D}||sVqFt j||}| |spqFt j	|r|d n|V  qFdS )z/
        Provide completions on prefix
        r(   Nr1   )
ospathdirnamelistdir	Exceptionbasename
startswithjoinr:   isdir)r   r
   r   Z
target_dirnamesZincomplete_partname	candidater   r   r   r   W   s    

z _FilteredFilesCompleter.__call__N)r   r   r   r   r   r   r   r   r   r8   L   s   
r8   c                   @   s   e Zd Zdd ZdS )DirectoriesCompleterc                 C   s   t j| tjjd d S )N)r:   )r8   r   r;   r<   rC   r$   r   r   r   r   l   s    zDirectoriesCompleter.__init__N)r   r   r   r   r   r   r   r   rG   k   s   rG   c                   @   s    e Zd ZdZdd Zdd ZdS )SuppressCompleterzK
    A completer used to suppress the completion of specific arguments
    c                 C   s   d S r   r   r$   r   r   r   r   u   s    zSuppressCompleter.__init__c                 C   s   dS )z?
        Decide if the completion should be suppressed
        Tr   r$   r   r   r   suppressx   s    zSuppressCompleter.suppressN)r   r   r   r   r   rI   r   r   r   r   rH   p   s   rH   )r   r;   r   r   r	   r   environZEnvironCompleterr&   r8   rG   rH   r   r   r   r   <module>   s   	
