HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/click/__pycache__/testing.cpython-310.pyc
o

��hI�@s8ddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZ
ddlmZddlmZddlmZddlmZddlmZdd	lmZe
jr_dd
lmZddlmZGdd
�d
�Zejd%dd��ZGdd�dej�ZGdd�d�Z Gdd�dej!�Z"d&dd �Z#Gd!d"�d"�Z$Gd#d$�d$�Z%dS)'�)�annotationsN)�
TracebackType�)�_compat)�
formatting)�termui)�utils)�_find_binary_reader)�ReadableBuffer)�Commandc@sleZdZd#dd�Zd$dd�Zd%dd�Zd&d'dd�Zd&d'dd�Zd&d'dd�Zd(dd�Z	d)dd�Z
d*d d!�Zd"S)+�EchoingStdin�input�
t.BinaryIO�output�return�NonecCs||_||_d|_dS)NF)�_input�_output�_paused)�selfr
r�r�C/usr/local/CyberPanel/lib/python3.10/site-packages/click/testing.py�__init__s
zEchoingStdin.__init__�x�str�t.AnycCst|j|�S�N)�getattrr)rrrrr�__getattr__ szEchoingStdin.__getattr__�rv�bytescCs|js	|j�|�|Sr)rr�write)rrrrr�_echo#szEchoingStdin._echo����n�intcC�|�|j�|��Sr)r"r�read�rr$rrrr')�zEchoingStdin.readcCr&r)r"r�read1r(rrrr*,r)zEchoingStdin.read1cCr&r)r"r�readliner(rrrr+/r)zEchoingStdin.readline�list[bytes]cs�fdd��j��D�S)Ncsg|]}��|��qSr�r"��.0r�rrr�
<listcomp>3sz*EchoingStdin.readlines.<locals>.<listcomp>)r�	readlinesr0rr0rr22�zEchoingStdin.readlines�cabc.Iterator[bytes]cst�fdd��jD��S)Nc3s�|]}��|�VqdSrr-r.r0rr�	<genexpr>6s�z(EchoingStdin.__iter__.<locals>.<genexpr>)�iterrr0rr0r�__iter__5r3zEchoingStdin.__iter__cCs
t|j�Sr)�reprrr0rrr�__repr__8s
zEchoingStdin.__repr__N)r
rrrrr)rrrr)rr rr )r#)r$r%rr )rr,)rr4�rr)�__name__�
__module__�__qualname__rrr"r'r*r+r2r7r9rrrrrs




r�stream�EchoingStdin | Noner�cabc.Iterator[None]ccs*�|dur
dVdSd|_dVd|_dS)NTF)r)r>rrr�_pause_echo<s�

rAcs>eZdZdZd�fdd�Zd�fdd	�Zd�fd
d�Z�ZS)�BytesIOCopyzdPatch ``io.BytesIO`` to let the written stream be copied to another.

    .. versionadded:: 8.2
    �copy_to�
io.BytesIOrrcst���||_dSr)�superrrC)rrC��	__class__rrrLs

zBytesIOCopy.__init__cst���|j��dSr)rE�flushrCr0rFrrrHPs
zBytesIOCopy.flush�br
r%cs|j�|�t��|�Sr)rCr!rE)rrIrFrrr!TszBytesIOCopy.write)rCrDrr�rr)rIr
rr%)r;r<r=�__doc__rrHr!�
__classcell__rrrFrrBFs
rBc@seZdZdZddd�ZdS)�StreamMixerz�Mixes `<stdout>` and `<stderr>` streams.

    The result is available in the ``output`` attribute.

    .. versionadded:: 8.2
    rrcCs*t��|_t|jd�|_t|jd�|_dS)N)rC)�io�BytesIOrrB�stdout�stderrr0rrrras
zStreamMixer.__init__NrJ)r;r<r=rKrrrrrrMYsrMcsHeZdZd�fd
d�Zeddd
��Zeddd��Zd�fdd�Z�ZS)�_NamedTextIOWrapper�bufferr�namer�mode�kwargsrrrcs$t�j|fi|��||_||_dSr)rEr�_name�_mode)rrSrTrUrVrFrrrhs
z_NamedTextIOWrapper.__init__cC�|jSr)rWr0rrrrTo�z_NamedTextIOWrapper.namecCrYr)rXr0rrrrUsrZz_NamedTextIOWrapper.modec
s2zt���}W|Sty}zt�|�d}~wwr)rE�__next__�
StopIteration�EOFError)r�line�erFrrr[ws���z_NamedTextIOWrapper.__next__)
rSrrTrrUrrVrrrr:)	r;r<r=r�propertyrTrUr[rLrrrFrrRgsrRr
� str | bytes | t.IO[t.Any] | None�charsetrrcCsZt|d�rtt�d|��}|dur|Std��|durd}n
t|t�r(|�|�}t�	|�S)Nr'zt.IO[t.Any]z.Could not find binary reader for input stream.�)
�hasattrr	�t�cast�	TypeError�
isinstancer�encoderNrO)r
rbrrrr�make_input_streams



rjc@sReZdZdZ	dddd�Zeddd��Zeddd��Zeddd��Zddd�Z	dS) �ResultaCHolds the captured result of an invoked CLI script.

    :param runner: The runner that created the result
    :param stdout_bytes: The standard output as bytes.
    :param stderr_bytes: The standard error as bytes.
    :param output_bytes: A mix of ``stdout_bytes`` and ``stderr_bytes``, as the
        user would see  it in its terminal.
    :param return_value: The value returned from the invoked command.
    :param exit_code: The exit code as integer.
    :param exception: The exception that happened if one did.
    :param exc_info: Exception information (exception type, exception instance,
        traceback type).

    .. versionchanged:: 8.2
        ``stderr_bytes`` no longer optional, ``output_bytes`` introduced and
        ``mix_stderr`` has been removed.

    .. versionadded:: 8.0
        Added ``return_value``.
    N�runner�	CliRunner�stdout_bytesr �stderr_bytes�output_bytes�return_valuer�	exit_coder%�	exception�BaseException | None�exc_info�?tuple[type[BaseException], BaseException, TracebackType] | Nonec		Cs4||_||_||_||_||_||_||_||_dSr�rlrnrorprqrrrsru)	rrlrnrorprqrrrsrurrrr�s
zResult.__init__rrcC�|j�|jjd��dd�S)aThe terminal output as unicode string, as the user would see it.

        .. versionchanged:: 8.2
            No longer a proxy for ``self.stdout``. Now has its own independent stream
            that is mixing `<stdout>` and `<stderr>`, in the order they were written.
        �replace�
�
)rp�decoderlrbryr0rrrr�s�z
Result.outputcCrx)z&The standard output as unicode string.ryrzr{)rnr|rlrbryr0rrrrP�s�z
Result.stdoutcCrx)z�The standard error as unicode string.

        .. versionchanged:: 8.2
            No longer raise an exception, always returns the `<stderr>` string.
        ryrzr{)ror|rlrbryr0rrrrQ�s�z
Result.stderrcCs,|jrt|j�nd}dt|�j�d|�d�S)N�okay�<� �>)rsr8�typer;)r�exc_strrrrr9�szResult.__repr__r)rlrmrnr ror rpr rqrrrr%rsrtrurvr:)
r;r<r=rKrr`rrPrQr9rrrrrk�s�
rkc@s~eZdZdZ				d,d-dd�Zd.dd�Z	d/d0dd�Zej			d1d2dd��Z						d3d4d%d&�Z
ej	d/d5d*d+��ZdS)6rma�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.
    :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 catch_exceptions: Whether to catch any exceptions other than
                             ``SystemExit`` when running :meth:`~CliRunner.invoke`.

    .. versionchanged:: 8.2
        Added the ``catch_exceptions`` parameter.

    .. versionchanged:: 8.2
        ``mix_stderr`` parameter has been removed.
    �utf-8NFTrbr�env�$cabc.Mapping[str, str | None] | None�
echo_stdin�bool�catch_exceptionsrrcCs ||_|pi|_||_||_dSr)rbr�r�r�)rrbr�r�r�rrrr�s

zCliRunner.__init__�clircCs
|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)rT)rr�rrr�get_default_prog_names
zCliRunner.get_default_prog_name�	overrides�cabc.Mapping[str, str | None]cCst|j�}|r|�|�|S)z8Returns the environment overrides for invoking a script.)�dictr��update)rr�rrrr�make_env
s

zCliRunner.make_envr
ra�color�8cabc.Iterator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]]c#s��t||j�}d}tj}tj}tj}tj}	dt_|�|�}t	�}
|j
r0t�tj
t||
j��}}t||jddd�t_�|j
rBd�_t|
j|jddd�t_t|
j|jd	dd
d�t_t|�dd�fdd�
�}t|�dd�fdd�
�}t|�d dd��}
|�	d!d"�fdd�
}tj}tj}tj}tj}tj}|t_|t_|
t_|t_|t_i}zs|��D]%\}}tj�|�||<|dur�ztj|=Wq�ty�Yq�w|tj|<q�|
j|
j|
jfVW|��D]\}}|dur�ztj|=Wq�ty�Yq�w|tj|<q�|t_|t_|t_|t_|t_|t_|t_|t_|	t_dS|��D]"\}}|du�r9ztj|=W�qt�y8Y�qw|tj|<�q|t_|t_|t_|t_|t_|t_|t_|t_|	t_w)#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.

        :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.

        .. versionadded:: 8.2
            An additional output stream is returned, which is a mix of
            `<stdout>` and `<stderr>` streams.

        .. versionchanged:: 8.2
            Always returns the `<stderr>` stream.

        .. versionchanged:: 8.0
            `<stderr>` is opened with ``errors="backslashreplace"``
            instead of the default ``"strict"``.

        .. versionchanged:: 4.0
            Added the ``color`` parameter.
        N�Pz<stdin>�r)�encodingrTrUrz<stdout>�wz<stderr>�backslashreplace)r�rTrU�errors�prompt�
str | Nonerrcs>tj�|pd�t���d�}tj�|�d��tj��|S)N�rzr{)�sysrPr!�next�rstriprH)r��val��
text_inputrr�
visible_input\s

z*CliRunner.isolation.<locals>.visible_inputcs.tj�|pd�d��tj��t���d�S)Nr�r{rz)r�rPr!rHr�r�)r�r�rr�hidden_inputds
z)CliRunner.isolation.<locals>.hidden_input�echor�cSs*tj�d�}|rtj�|�tj��|S)Nr)r��stdinr'rPr!rH)r��charrrr�_getcharjs

z%CliRunner.isolation.<locals>._getcharr>�t.IO[t.Any] | Noner��bool | Nonecs|dur�S|Srr)r>r�)�
default_colorrr�should_strip_ansivsz.CliRunner.isolation.<locals>.should_strip_ansir)r�r�rr)r�r�rr)NN)r>r�r�r�rr�)rjrbr�r�rPrQr�FORCED_WIDTHr�rMr�rerf�BinaryIOrrR�_CHUNK_SIZErAr�visible_prompt_func�hidden_prompt_funcr�rr�r�items�os�environ�get�	Exceptionr)rr
r�r��bytes_input�
echo_input�	old_stdin�
old_stdout�
old_stderr�old_forced_width�stream_mixerr�r�r�r��old_visible_prompt_func�old_hidden_prompt_func�old__getchar_func�old_should_strip_ansi�old__compat_should_strip_ansi�old_env�key�valuer)r�r�r�	isolations��"
�
���	���
�
�zCliRunner.isolation�args�str | cabc.Sequence[str] | Noner��extrarrkcKs�d}|dur	|j}|j|||d���}	d}
d}d}t|t�r"t�|�}z|�d�}
Wnty7|�|�}
Ynwz�z|j	d|p@d|
d�|��}
Wn\t
y�}z4t��}t
�d|j�}|durad}|dkrg|}t|t�s|tj�t|��tj�d�d	}|}WYd}~n!d}~wty�}z|s��|}d	}t��}WYd}~nd}~wwWtj��tj��|	d��}|	d	��}|	d
��}ntj��tj��|	d��}|	d	��}|	d
��}wWd�n1s�wYt|||||
|||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.

        :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``. If :data:`None`, the value
                                 from :class:`CliRunner` is used.
        :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.

        .. versionadded:: 8.2
            The result object has the ``output_bytes`` attribute with
            the mix of ``stdout_bytes`` and ``stderr_bytes``, as the user would
            see it in its terminal.

        .. versionchanged:: 8.2
            The result object always returns the ``stderr_bytes`` stream.

        .. versionchanged:: 8.0
            The result object has the ``return_value`` attribute with
            the value returned from the invoked command.

        .. versionchanged:: 4.0
            Added the ``color`` parameter.

        .. versionchanged:: 3.0
            Added the ``catch_exceptions`` parameter.

        .. versionchanged:: 3.0
            The result object has the ``exc_info`` attribute with the
            traceback if available.
        N)r
r�r�r�	prog_namer)r�r�zint | t.Any | Noner{r�rw)r�r�rhr�shlex�split�pop�KeyErrorr��main�
SystemExitr�rurerf�coder%rPr!r�rHrQ�getvaluerk)rr�r�r
r�r�r�r�ru�
outstreamsrqrsrrr�r_�e_coderPrQrrrr�invoke�sv5

�
����


�
�-�zCliRunner.invoke�temp_dir�str | os.PathLike[str] | None�cabc.Iterator[str]ccs��t��}tj|d�}t�|�z"|VWt�|�|dur1zt�|�WdSty0YdSwdSt�|�|durMzt�|�WwtyLYwww)a�A context manager that creates a temporary directory and
        changes the current working directory to it. This isolates tests
        that affect the contents of the CWD to prevent them from
        interfering with each other.

        :param temp_dir: Create the temporary directory under this
            directory. If given, the created directory is not removed
            when exiting.

        .. versionchanged:: 8.0
            Added the ``temp_dir`` parameter.
        )�dirN)r��getcwd�tempfile�mkdtemp�chdir�shutil�rmtree�OSError)rr��cwd�dtrrr�isolated_filesystems,�

��
���zCliRunner.isolated_filesystem)r�NFT)
rbrr�r�r�r�r�r�rr)r�rrrr)r�r�rr�)NNF)r
rar�r�r�r�rr�)NNNNF)r�rr�r�r
rar�r�r�r�r�r�r�rrrk)r�r�rr�)r;r<r=rKrr�r��
contextlib�contextmanagerr�r�r�rrrrrm�s2�
�	��q�rm)r>r?rr@)r
rarbrrr)&�
__future__r�collections.abc�abc�cabcr�rNr�r�r�r�r��typingre�typesrr�rrrrr	�
TYPE_CHECKING�	_typeshedr
�corerrr�rArOrBrM�
TextIOWrapperrRrjrkrmrrrr�<module>s8"	
N