a
    é´«jš?  ã                   @   s*  d dl Z d dlZd dlZ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
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ejršdd	lmZ G d
d„ dƒZe jeje ejd dœdd„ƒZG dd„ dejƒZejejeeejej f  eej dœdd„Z!G dd„ dƒZ"G dd„ dƒZ#dS )é    N)ÚTracebackTypeé   )Ú_compat)Ú
formatting)Útermui)Úutils)Ú_find_binary_reader)ÚBaseCommandc                   @   s°   e Zd Zejejddœdd„Zeejdœdd„Ze	e	dœd	d
„Z
dee	dœdd„Zdee	dœdd„Zdee	dœdd„Zeje	 dœdd„Zeje	 dœdd„Zedœdd„ZdS )ÚEchoingStdinN)ÚinputÚoutputÚreturnc                 C   s   || _ || _d| _d S )NF)Ú_inputÚ_outputÚ_paused)Úselfr   r   © r   úL/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/click/testing.pyÚ__init__   s    zEchoingStdin.__init__)Úxr   c                 C   s   t | j|ƒS ©N)Úgetattrr   )r   r   r   r   r   Ú__getattr__   s    zEchoingStdin.__getattr__)Úrvr   c                 C   s   | j s| j |¡ |S r   )r   r   Úwrite)r   r   r   r   r   Ú_echo   s    zEchoingStdin._echoéÿÿÿÿ)Únr   c                 C   s   |   | j |¡¡S r   )r   r   Úread©r   r   r   r   r   r   $   s    zEchoingStdin.readc                 C   s   |   | j |¡¡S r   )r   r   Úread1r   r   r   r   r    '   s    zEchoingStdin.read1c                 C   s   |   | j |¡¡S r   )r   r   Úreadliner   r   r   r   r!   *   s    zEchoingStdin.readline©r   c                    s   ‡ fdd„ˆ j  ¡ D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r   ©r   ©Ú.0r   ©r   r   r   Ú
<listcomp>.   ó    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>1   r(   z(EchoingStdin.__iter__.<locals>.<genexpr>)Úiterr   r&   r   r&   r   Ú__iter__0   s    zEchoingStdin.__iter__c                 C   s
   t | jƒS r   )Úreprr   r&   r   r   r   Ú__repr__3   s    zEchoingStdin.__repr__)r   )r   )r   )Ú__name__Ú
__module__Ú__qualname__ÚtÚBinaryIOr   ÚstrÚAnyr   Úbytesr   Úintr   r    r!   ÚListr)   ÚIteratorr,   r.   r   r   r   r   r
      s   r
   )Ústreamr   c                 c   s&   | d u rd V  nd| _ d V  d| _ d S )NTF)r   )r:   r   r   r   Ú_pause_echo7   s
    r;   c                       sR   e Zd Zejeeejddœ‡ fdd„Zeedœdd„ƒZ	eedœdd	„ƒZ
‡  ZS )
Ú_NamedTextIOWrapperN)ÚbufferÚnameÚmodeÚkwargsr   c                    s$   t ƒ j|fi |¤Ž || _|| _d S r   )Úsuperr   Ú_nameÚ_mode)r   r=   r>   r?   r@   ©Ú	__class__r   r   r   B   s    z_NamedTextIOWrapper.__init__r"   c                 C   s   | j S r   )rB   r&   r   r   r   r>   I   s    z_NamedTextIOWrapper.namec                 C   s   | j S r   )rC   r&   r   r   r   r?   M   s    z_NamedTextIOWrapper.mode)r/   r0   r1   r2   r3   r4   r5   r   Úpropertyr>   r?   Ú__classcell__r   r   rD   r   r<   A   s   þr<   )r   Úcharsetr   c                 C   sb   t | dƒr6tt tjtj | ¡ƒ}|d ur.|S tdƒ‚| d u rDd} nt| tƒrX|  	|¡} t
 | ¡S )Nr   z.Could not find binary reader for input stream.r(   )Úhasattrr   r2   ÚcastÚIOr5   Ú	TypeErrorÚ
isinstancer4   ÚencodeÚioÚBytesIO)r   rH   r   r   r   r   Úmake_input_streamR   s    


rQ   c                   @   s–   e Zd ZdZddeeje ejeeje	 ejej
eje	 e	ef  dœdd„Zeedœdd	„ƒZeedœd
d„ƒZeedœdd„ƒZedœdd„ZdS )ÚResultz3Holds the captured result of an invoked CLI script.NÚ	CliRunner©ÚrunnerÚstdout_bytesÚstderr_bytesÚreturn_valueÚ	exit_codeÚ	exceptionÚexc_infoc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r   rT   )r   rU   rV   rW   rX   rY   rZ   r[   r   r   r   r   i   s    zResult.__init__r"   c                 C   s   | j S )z(The (standard) output as unicode string.)Ústdoutr&   r   r   r   r   †   s    zResult.outputc                 C   s   | j  | jjd¡ dd¡S )z&The standard output as unicode string.Úreplaceú
Ú
)rV   ÚdecoderU   rH   r]   r&   r   r   r   r\   ‹   s    ÿzResult.stdoutc                 C   s,   | j du rtdƒ‚| j  | jjd¡ dd¡S )z%The standard error as unicode string.Nzstderr not separately capturedr]   r^   r_   )rW   Ú
ValueErrorr`   rU   rH   r]   r&   r   r   r   Ústderr’   s
    
ÿzResult.stderrc                 C   s,   | j rt| j ƒnd}dt| ƒj› d|› d�S )NÚokayú<ú ú>)rZ   r-   Útyper/   )r   Zexc_strr   r   r   r.   ›   s    zResult.__repr__)N)r/   r0   r1   Ú__doc__r6   r2   ÚOptionalr5   r7   ÚBaseExceptionÚTupleÚTyper   r   rF   r4   r   r\   rb   r.   r   r   r   r   rR   f   s(    öÿørR   c                
   @   s€  e Zd ZdZdeejejeeje f  eeddœdd„Z	d	ed
œdd„Z
dejejeeje f  ejeeje f dœdd„Zejdejejeeejej f  ejejeeje f  eejejejejej f  dœdd„ƒZdd	ejejeeje f  ejejeeejej f  ejejeeje f  eeejedœdd„Zejdejejedf  eje dœdd„ƒZdS )rS   aø  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 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
    úutf-8NFT)rH   ÚenvÚ
echo_stdinÚ
mix_stderrr   c                 C   s    || _ |pi | _|| _|| _d S r   )rH   rn   ro   rp   )r   rH   rn   ro   rp   r   r   r   r   ³   s    
zCliRunner.__init__r	   )Úclir   c                 C   s
   |j pdS )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)r>   )r   rq   r   r   r   Úget_default_prog_name¿   s    zCliRunner.get_default_prog_name)Ú	overridesr   c                 C   s   t | jƒ}|r| |¡ |S )z8Returns the environment overrides for invoking a script.)Údictrn   Úupdate)r   rt   r   r   r   r   Úmake_envÆ   s    

zCliRunner.make_env)r   rn   Úcolorr   c                 #   s  t || jƒ}d}tj}tj}tj}tj}	dt_|  |¡}t	 
¡ }
| jr^t tjt||
ƒ¡ }}t|| jddd� t_‰| jr‚dˆ_t|
| jddd�t_d}| jrªtjt_nt	 
¡ }t|| jd	dd
d�t_t|ƒdtjt tdœ‡fdd„ƒ}t|ƒdtjt tdœ‡fdd„ƒ}t|ƒttdœdd„ƒ}|‰ dtjtjtj  tjt tdœ‡ fdd„}tj}tj}tj}tj}tj}|t_|t_|t_|t_|t_i }zì|  ¡ D ]R\}}t!j" #|¡||< |du �rèzt!j"|= W n t$�yä   Y n0 n
|t!j"|< �q¢|
|fV  W |  ¡ D ]B\}}|du �r@zt!j"|= W n t$�y<   Y n0 n
|t!j"|< �q
|t_|t_|t_|t_|t_|t_|t_|t_|	t_n„|  ¡ D ]B\}}|du �rÄzt!j"|= W n t$�yÀ   Y n0 n
|t!j"|< �qŽ|t_|t_|t_|t_|t_|t_|t_|t_|	t_0 dS )an  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.

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

        .. versionchanged:: 4.0
            Added the ``color`` parameter.
        NéP   z<stdin>Úr)Úencodingr>   r?   r   z<stdout>Úwz<stderr>Úbackslashreplace)r{   r>   r?   Úerrors)Úpromptr   c                    s>   t j | pd¡ ˆ  ¡  d¡}t j |› d�¡ t j ¡  |S )NÚ r^   r_   )Úsysr\   r   r!   ÚrstripÚflush)r   Úval©Ú
text_inputr   r   Úvisible_input  s
    
z*CliRunner.isolation.<locals>.visible_inputc                    s.   t j | pd› d�¡ t j ¡  ˆ  ¡  d¡S )Nr€   r_   r^   )r�   r\   r   rƒ   r!   r‚   )r   r…   r   r   Úhidden_input  s    
z)CliRunner.isolation.<locals>.hidden_input)Úechor   c                 S   s*   t j d¡}| rt j |¡ t j ¡  |S )Nr   )r�   Ústdinr   r\   r   rƒ   )r‰   Úcharr   r   r   Ú_getchar$  s
    
z%CliRunner.isolation.<locals>._getchar)r:   rx   r   c                    s   |d u rˆ  S | S r   r   )r:   rx   )Údefault_colorr   r   Úshould_strip_ansi0  s    z.CliRunner.isolation.<locals>.should_strip_ansi)N)N)NN)%rQ   rH   r�   rŠ   r\   rb   r   ZFORCED_WIDTHrw   rO   rP   ro   r2   rJ   r3   r
   r<   Ú_CHUNK_SIZErp   r;   ri   r4   ÚboolrK   r5   r   Zvisible_prompt_funcZhidden_prompt_funcrŒ   r   rŽ   r   ÚitemsÚosÚenvironÚgetÚ	Exception)r   r   rn   rx   Zbytes_inputZ
echo_inputZ	old_stdinZ
old_stdoutZ
old_stderrZold_forced_widthZbytes_outputZbytes_errorr‡   rˆ   rŒ   rŽ   Zold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold__compat_should_strip_ansiZold_envÚkeyÚvaluer   )r�   r†   r   Ú	isolationÏ   sÂ    
ÿ
ÿ
ÿ
û	 ÿþ

ð
zCliRunner.isolation)rq   Úargsr   rn   Úcatch_exceptionsrx   Úextrar   c                 K   sö  d}| j |||d���¸}	d}
d}d}t|tƒr8t |¡}z| d¡}W n tyb   |  |¡}Y n0 �z&z|jf |pvd|dœ|¤Ž}
W nÒ t	�y } z|t
 ¡ }t tjtjttjf  |j¡}|du rÌd}|dkrØ|}t|tƒ�st
j t|ƒ¡ t
j d¡ d}|}W Y d}~nFd}~0  t�yX } z$|�s4‚ |}d}t
 ¡ }W Y d}~n
d}~0 0 W t
j ¡  |	d  ¡ }| j�r€d}n|	d  ¡ }n2t
j ¡  |	d  ¡ }| j�r²d}n|	d  ¡ }0 W d  ƒ n1 �sÖ0    Y  t| |||
|||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``.
        :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.

        .. 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   rn   rx   r   Ú	prog_namer   )r™   rœ   r_   r   rT   )r˜   rM   r4   ÚshlexÚsplitÚpopÚKeyErrorrs   ÚmainÚ
SystemExitr�   r[   r2   rJ   ri   ÚUnionr7   r5   Úcoder\   r   r•   rƒ   Úgetvaluerp   rR   )r   rq   r™   r   rn   rš   rx   r›   r[   Z
outstreamsrX   rZ   rY   rœ   ÚeZe_coder\   rb   r   r   r   Úinvokea  sd    ,

  
û
.ùzCliRunner.invokezos.PathLike[str])Útemp_dirr   c                 c   s˜   t  ¡ }tj|d�}t  |¡ z>|V  W t  |¡ |du r”zt |¡ W q” tyZ   Y q”0 n6t  |¡ |du r’zt |¡ W n ty�   Y n0 0 dS )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)r   r¨   ÚcwdÚdtr   r   r   Úisolated_filesystemÆ  s"    

ú
zCliRunner.isolated_filesystem)rm   NFT)N)NNF)NNNTF)N)r/   r0   r1   rh   r4   r2   ri   ÚMappingr�   r   rs   rw   Ú
contextlibÚcontextmanagerr£   r6   rK   r5   r9   rk   rO   rP   r˜   ÚSequencerR   r§   r³   r   r   r   r   rS       sd       ûú ÿþ	   üû      ù÷e ÿþrS   )$rµ   rO   r’   r�   r®   r�   r«   Útypingr2   Útypesr   r€   r   r   r   r   r   ÚTYPE_CHECKINGÚcorer	   r
   r¶   ri   r9   r;   ÚTextIOWrapperr<   r£   r4   r6   rK   r5   r3   rQ   rR   rS   r   r   r   r   Ú<module>   s0   "	þ: