HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/click/__pycache__/testing.cpython-38.pyc
U

L�[3�@s�ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	ej
e�dd�dZ
erlddlmZnddlZddlmZGdd�de�Zd	d
�ZGdd�de�ZGd
d�de�ZdS)�N�)�	iteritems�PY2�string_types�.)�StringIO)�_find_binary_readerc@sPeZdZdd�Zdd�Zdd�Zddd	�Zdd
d�Zdd
�Zdd�Z	dd�Z
dS)�EchoingStdincCs||_||_dS�N)�_input�_output)�self�input�output�r�//usr/lib/python3/dist-packages/click/testing.py�__init__szEchoingStdin.__init__cCst|j|�Sr
)�getattrr)r
�xrrr�__getattr__szEchoingStdin.__getattr__cCs|j�|�|Sr
)r�write)r
�rvrrr�_echo"szEchoingStdin._echo���cCs|�|j�|��Sr
)rr�read�r
�nrrrr&szEchoingStdin.readcCs|�|j�|��Sr
)rr�readlinerrrrr)szEchoingStdin.readlinecs�fdd��j��D�S)Ncsg|]}��|��qSr�r��.0r�r
rr�
<listcomp>-sz*EchoingStdin.readlines.<locals>.<listcomp>)r�	readlinesr!rr!rr#,szEchoingStdin.readlinescst�fdd��jD��S)Nc3s|]}��|�VqdSr
rrr!rr�	<genexpr>0sz(EchoingStdin.__iter__.<locals>.<genexpr>)�iterrr!rr!r�__iter__/szEchoingStdin.__iter__cCs
t|j�Sr
)�reprrr!rrr�__repr__2szEchoingStdin.__repr__N)r)r)�__name__�
__module__�__qualname__rrrrrr#r&r(rrrrr	s

r	cCsft|d�r.tr|St|�}|dk	r&|Std��|dkr<d}nt|t�sP|�|�}tr\t|�St�	|�S)Nrz.Could not find binary reader for input stream.�)
�hasattrrr�	TypeError�
isinstance�bytes�encoder�io�BytesIO)r�charsetrrrr�make_input_stream6s


r5c@sFeZdZdZd
dd�Zedd��Zedd��Zed	d
��Zdd�Z	dS)�Resultz3Holds the captured result of an invoked CLI script.NcCs(||_||_||_||_||_||_dSr
��runner�stdout_bytes�stderr_bytes�	exit_code�	exception�exc_info)r
r8r9r:r;r<r=rrrrLszResult.__init__cCs|jS)z(The (standard) output as unicode string.)�stdoutr!rrrr[sz
Result.outputcCs|j�|jjd��dd�S)z&The standard output as unicode string.�replace�
�
)r9�decoder8r4r?r!rrrr>`s�z
Result.stdoutcCs(|jstd��|j�|jjd��dd�S)z%The standard error as unicode string.zstderr not separately capturedr?r@rA)r:�
ValueErrorrBr8r4r?r!rrr�stderrfs�z
Result.stderrcCs"dt|�j|jrt|j�pdfS)Nz<%s %s>Zokay)�typer)r<r'r!rrrr(os�zResult.__repr__)N)
r)r*r+�__doc__r�propertyrr>rDr(rrrrr6Is�



r6c@sTeZdZdZddd�Zdd�Zdd	d
�Zejddd��Z	dd
d�Z
ejdd��ZdS)�	CliRunnera�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.
    :param mix_stderr: if this is set to `False`, then stdout and stderr are
                       preserved as independent streams.  This is useful for
                       Unix-philosophy apps that have predictable stdout and
                       noisy stderr, such that each may be measured
                       independently
    NFTcCs,|dkrd}||_|pi|_||_||_dS)Nzutf-8)r4�env�
echo_stdin�
mix_stderr)r
r4rIrJrKrrrr�s
zCliRunner.__init__cCs
|jpdS)z�Given 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
�clirrr�get_default_prog_name�szCliRunner.get_default_prog_namecCst|j�}|r|�|�|S)z8Returns the environment overrides for invoking a script.)�dictrI�update)r
Z	overridesrrrr�make_env�s

zCliRunner.make_envc#sZt�|j��tj}tj}tj}tjj}dtj_|�	|�}t
rlt�}|jrRt
�|��|t_|js�t�}	|	t_nZt��}|jr�t
�|��tj�|jd��tj||jd�t_|js�t��}	tj|	|jd�t_|jr�tjt_�t_d�fdd�	}
d
�fdd�	}dd	�}|�d�fd
d�	}
tjj}tjj}tjj}tjj}|
tj_|tj_|tj_|
tj_i}zvt|�D]T\}}tj�|�||<|dk�r�ztj|=Wntk
�r�YnXn
|tj|<�q^||j�o�|	fVW5t|�D]D\}}|dk�rztj|=Wntk
�rYnXn
|tj|<�q�|t_|t_|t_|tj_|tj_|tj_|tj_|tj_XdS)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)�encodingNcs<tj�|pd�����d�}tj�|d�tj��|S)N�r@rA)�sysr>rr�rstrip�flush)�prompt�val�rrr�
visible_input�s

z*CliRunner.isolation.<locals>.visible_inputcs,tj�|pdd�tj������d�S)NrUrAr@)rVr>rrXrrW)rYr[rr�hidden_input�s
z)CliRunner.isolation.<locals>.hidden_inputcSs*tj�d�}|r&tj�|�tj��|S)Nr)rV�stdinrr>rrX)Zecho�charrrr�_getchar�s

z%CliRunner.isolation.<locals>._getcharcs|dkr�S|Sr
r)�stream�color)�
default_colorrr�should_strip_ansi�sz.CliRunner.isolation.<locals>.should_strip_ansi)N)N)NN)r5r4rVr^r>rD�clickpkgZ
formattingZFORCED_WIDTHrRrrrJr	rKr2r3�
TextIOWrapperZtermuiZvisible_prompt_funcZhidden_prompt_funcr`Zutilsrdr�os�environ�	Exception�get)r
rrIrbZ	old_stdinZ
old_stdoutZ
old_stderrZold_forced_widthZbytes_outputZbytes_errorr\r]r`rdZold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold_env�key�valuer)rcrr�	isolation�s�


��

zCliRunner.isolationcKs�d}	|j|||d���P}
d}d}t|t�r4t�|�}z|�d�}
Wntk
r`|�|�}
YnXz�z|jf|prd|
d�|��Wn�t
k
r�}zTt��}	|j}|dkr�d}|dkr�|}t|t�s�tj	�t|��tj	�d�d}W5d}~XYn<tk
�r.}z|�s�|}d}t��}	W5d}~XYnXW5tj	�
�|
d��}|
d�o^|
d��}XW5QRXt||||||	d	�S)
a;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. It may be given as an iterable
                     or a string. When given as string it will be interpreted
                     as a Unix shell command. More details at
                     :func:`shlex.split`.
        :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)rrIrbr�	prog_namerr)�argsrnrAr7)rmr/r�shlex�split�pop�KeyErrorrOrVr>rX�getvalue�main�
SystemExitr=�code�intr�strrir6)r
rNrorrIZcatch_exceptionsrbrKZextrar=Z
outstreamsr<r;rnr>rD�errr�invokesN 



"�zCliRunner.invokeccs^t��}t��}t�|�z
|VW5t�|�zt�|�Wnttfk
rVYnXXdS)z�A context manager that creates a temporary folder and changes
        the current working directory to it for isolated filesystem tests.
        N)	rg�getcwd�tempfileZmkdtemp�chdir�shutilZrmtree�OSError�IOError)r
�cwd�trrr�isolated_filesystemgs


zCliRunner.isolated_filesystem)NNFT)N)NNF)NNNTFF)r)r*r+rFrrOrR�
contextlib�contextmanagerrmr{r�rrrrrHvs�
	
u�
OrH)rgrVrr}r�rpZ_compatrrr�modulesr)�rsplitre�	cStringIOrr2r�objectr	r5r6rHrrrr�<module>s-