
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    e([V*                     @   s   d dl Z d dlZd dlZd dlZd dlZddlmZmZ eje	
ddd   Zer`d dlmZ nd dlZddlmZ G dd deZd	d
 ZG dd deZG dd deZdS )    N   )	iteritemsPY2.)StringIO)_find_binary_readerc                   @   sP   e Zd Zdd Zdd Zdd Zddd	Zdd
dZdd Zdd Z	dd Z
dS )EchoingStdinc                 C   s   || _ || _d S N)_input_output)selfinputoutput r   >/opt/alt/python38/lib/python3.8/site-packages/click/testing.py__init__   s    zEchoingStdin.__init__c                 C   s   t | j|S r	   )getattrr
   )r   xr   r   r   __getattr__   s    zEchoingStdin.__getattr__c                 C   s   | j | |S r	   )r   write)r   rvr   r   r   _echo!   s    zEchoingStdin._echoc                 C   s   |  | j|S r	   )r   r
   readr   nr   r   r   r   %   s    zEchoingStdin.readc                 C   s   |  | j|S r	   )r   r
   readliner   r   r   r   r   (   s    zEchoingStdin.readlinec                    s    fdd j  D S )Nc                    s   g | ]}  |qS r   r   .0r   r   r   r   
<listcomp>,   s     z*EchoingStdin.readlines.<locals>.<listcomp>)r
   	readlinesr    r   r    r   r"   +   s    zEchoingStdin.readlinesc                    s   t  fdd jD S )Nc                 3   s   | ]}  |V  qd S r	   r   r   r    r   r   	<genexpr>/   s     z(EchoingStdin.__iter__.<locals>.<genexpr>)iterr
   r    r   r    r   __iter__.   s    zEchoingStdin.__iter__c                 C   s
   t | jS r	   )reprr
   r    r   r   r   __repr__1   s    zEchoingStdin.__repr__N)r   )r   )__name__
__module____qualname__r   r   r   r   r   r"   r%   r'   r   r   r   r   r      s   

r   c                 C   sf   t | dr.tr| S t| }|d k	r&|S td| d kr<d} nt| tsP| |} tr\t| S t	| S )Nr   z.Could not find binary reader for input stream.    )
hasattrr   r   	TypeError
isinstancebytesencoder   ioBytesIO)r   charsetr   r   r   r   make_input_stream5   s    


r4   c                   @   s.   e Zd ZdZd	ddZedd Zdd ZdS )
Resultz3Holds the captured result of an invoked CLI script.Nc                 C   s"   || _ || _|| _|| _|| _d S r	   runneroutput_bytes	exit_code	exceptionexc_info)r   r7   r8   r9   r:   r;   r   r   r   r   K   s
    zResult.__init__c                 C   s   | j | jjdddS )zThe output as unicode string.replace

)r8   decoder7   r3   r<   r    r   r   r   r   X   s     zResult.outputc                 C   s   d| j rt| j pdf S )Nz<Result %s>Zokay)r:   r&   r    r   r   r   r'   ^   s    zResult.__repr__)N)r(   r)   r*   __doc__r   propertyr   r'   r   r   r   r   r5   H   s    

r5   c                   @   sT   e Zd ZdZdddZdd Zddd	Zejdd
dZ	dddZ
ejdd ZdS )	CliRunneraI  The CLI runner provides functionality to invoke a Click command line
    script for unittesting purposes in a isolated environment.  This only
    works in single-threaded systems without any concurrency as it changes the
    global interpreter state.

    :param charset: the character set for the input and output data.  This is
                    UTF-8 by default and should not be changed currently as
                    the reporting to Click only works in Python 2 properly.
    :param env: a dictionary with environment variables for overriding.
    :param echo_stdin: if this is set to `True`, then reading from stdin writes
                       to stdout.  This is useful for showing examples in
                       some circumstances.  Note that regular prompts
                       will automatically echo the input.
    NFc                 C   s&   |d krd}|| _ |pi | _|| _d S )Nzutf-8)r3   env
echo_stdin)r   r3   rC   rD   r   r   r   r   t   s
    
zCliRunner.__init__c                 C   s
   |j pdS )zGiven a command object it will return the default program name
        for it.  The default is the `name` attribute or ``"root"`` if not
        set.
        root)name)r   clir   r   r   get_default_prog_name{   s    zCliRunner.get_default_prog_namec                 C   s   t | j}|r|| |S )z8Returns the environment overrides for invoking a script.)dictrC   update)r   Z	overridesr   r   r   r   make_env   s    

zCliRunner.make_envc                 #   s  t | jtj}tj}tj}tjj}dtj_| 	|}t
r`t  t_ t_}| jrt|n@t }| jrxt|tj| jdtj|| jd t_t_t_dfdd	}	dfdd	}
dd	 }| d fd
d	}tjj}tjj}tjj}tjj}|	tj_|
tj_|tj_|tj_i }zht|D ]T\}}tj|||< |dkrrztj|= W n tk
rn   Y nX n
|tj|< q*|V  W 5 t|D ]D\}}|dkrztj|= W n tk
r   Y nX n
|tj|< q|t_|t_|t_|tj_|tj_|tj_|tj_|tj_X dS )a  A context manager that sets up the isolation for invoking of a
        command line tool.  This sets up stdin with the given input data
        and `os.environ` with the overrides from the given dictionary.
        This also rebinds some internals in Click to be mocked (like the
        prompt functionality).

        This is automatically done in the :meth:`invoke` method.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param input: the input stream to put into sys.stdin.
        :param env: the environment overrides as dictionary.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.
        P   )encodingNc                    s<   t j| pd   d}t j|d  t j  |S )N r=   r>   )sysstdoutr   r   rstripflush)promptvalr   r   r   visible_input   s
    
z*CliRunner.isolation.<locals>.visible_inputc                    s,   t j| pdd  t j    dS )NrN   r>   r=   )rO   rP   r   rR   r   rQ   )rS   rU   r   r   hidden_input   s    
z)CliRunner.isolation.<locals>.hidden_inputc                 S   s*   t jd}| r&t j| t j  |S )Nr   )rO   stdinr   rP   r   rR   )Zechocharr   r   r   _getchar   s
    
z%CliRunner.isolation.<locals>._getcharc                    s   |d kr  S | S r	   r   )streamcolor)default_colorr   r   should_strip_ansi   s    z.CliRunner.isolation.<locals>.should_strip_ansi)N)N)NN)r4   r3   rO   rX   rP   stderrclickpkgZ
formattingZFORCED_WIDTHrK   r   r   rD   r   r1   r2   TextIOWrapperZtermuiZvisible_prompt_funcZhidden_prompt_funcrZ   utilsr^   r   osenviron	Exceptionget)r   r   rC   r\   Z	old_stdinZ
old_stdoutZ
old_stderrZold_forced_widthZbytes_outputrV   rW   rZ   r^   Zold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold_envkeyvaluer   )r]   r   r   	isolation   sv    

 


zCliRunner.isolationTc                 K   s  d}| j |||d}	d}
d}zz$|jf |p.d| |d| W n tk
r } zJ|jdkrd|}
t	 }|j}t
|tstjt| tjd d}W 5 d}~X Y n8 tk
r } z|s |}
d}t	 }W 5 d}~X Y nX W 5 tj  |	 }X W 5 Q R X t| |||
|d	S )
ae  Invokes a command in an isolated environment.  The arguments are
        forwarded directly to the command line script, the `extra` keyword
        arguments are passed to the :meth:`~clickpkg.Command.main` function of
        the command.

        This returns a :class:`Result` object.

        .. versionadded:: 3.0
           The ``catch_exceptions`` parameter was added.

        .. versionchanged:: 3.0
           The result object now has an `exc_info` attribute with the
           traceback if available.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param cli: the command to invoke
        :param args: the arguments to invoke
        :param input: the input data for `sys.stdin`.
        :param env: the environment overrides.
        :param catch_exceptions: Whether to catch any other exceptions than
                                 ``SystemExit``.
        :param extra: the keyword arguments to pass to :meth:`main`.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.
        N)r   rC   r\   r   r   )argsZ	prog_namer>   r   r   r6   )ri   rO   rP   rR   getvaluemainrH   
SystemExitcoder;   r.   intr   strre   r5   )r   rG   rj   r   rC   Zcatch_exceptionsr\   extrar;   outr:   r9   r   er   r   r   invoke   sB    



zCliRunner.invokec                 c   s^   t  }t }t | z
|V  W 5 t | zt| W n ttfk
rV   Y nX X dS )zA context manager that creates a temporary folder and changes
        the current working directory to it for isolated filesystem tests.
        N)	rc   getcwdtempfilemkdtempchdirshutilrmtreeOSErrorIOError)r   cwdtr   r   r   isolated_filesystem3  s    


zCliRunner.isolated_filesystem)NNF)N)NNF)NNNTF)r(   r)   r*   r@   r   rH   rK   
contextlibcontextmanagerri   rt   r   r   r   r   r   rB   d   s   

i    
@rB   )rc   rO   ry   rv   r   _compatr   r   modulesr(   rsplitr`   	cStringIOr   r1   r   objectr   r4   r5   rB   r   r   r   r   <module>   s   