
    wdf62                         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rd d	lmZ n
d dlZdd
l
mZ  G d de          Zd Z G d de          Z G d de          ZdS )    N   )
formatting)termui)utils)	iteritems)PY2)string_types)StringIO)_find_binary_readerc                   B    e Zd Zd Zd Zd ZddZddZd Zd Z	d	 Z
d
S )EchoingStdinc                 "    || _         || _        d S N)_input_output)selfinputoutputs      R/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/click/testing.py__init__zEchoingStdin.__init__   s        c                 ,    t          | j        |          S r   )getattrr   )r   xs     r   __getattr__zEchoingStdin.__getattr__   s    t{A&&&r   c                 :    | j                             |           |S r   )r   write)r   rvs     r   _echozEchoingStdin._echo   s    2	r   c                 \    |                      | j                            |                    S r   )r   r   readr   ns     r   r"   zEchoingStdin.read#   s$    zz$+**1--...r   c                 \    |                      | j                            |                    S r   )r   r   readliner#   s     r   r&   zEchoingStdin.readline&   s$    zz$+..q11222r   c                 N      fd j                                         D             S )Nc                 :    g | ]}                     |          S  r   .0r   r   s     r   
<listcomp>z*EchoingStdin.readlines.<locals>.<listcomp>*   s#    ???!

1???r   )r   	readlinesr   s   `r   r.   zEchoingStdin.readlines)   s+    ????t{'<'<'>'>????r   c                 D     t           fd j        D                       S )Nc              3   B   K   | ]}                     |          V  d S r   r*   r+   s     r   	<genexpr>z(EchoingStdin.__iter__.<locals>.<genexpr>-   s-      77aDJJqMM777777r   )iterr   r/   s   `r   __iter__zEchoingStdin.__iter__,   s(    77774;777777r   c                 *    t          | j                  S r   )reprr   r/   s    r   __repr__zEchoingStdin.__repr__/   s    DK   r   N)r    )__name__
__module____qualname__r   r   r   r"   r&   r.   r4   r7   r)   r   r   r   r      s          ' ' '  / / / /3 3 3 3@ @ @8 8 8! ! ! ! !r   r   c                 *   t          | d          r+t          r| S t          |           }||S t          d          | d} n*t	          | t
                    s|                     |          } t          rt          |           S t          j	        |           S )Nr"   z.Could not find binary reader for input stream.r   )
hasattrr   r   	TypeError
isinstancebytesencoder
   ioBytesIO)r   charsetr   s      r   make_input_streamrD   3   s    uf J 	L ''>IHIII}u%% &W%%
 :er   c                   d    e Zd ZdZ	 ddZed             Zed             Zed             Zd Z	dS )	Resultz3Holds the captured result of an invoked CLI script.Nc                 Z    || _         || _        || _        || _        || _        || _        d S r   runnerstdout_bytesstderr_bytes	exit_code	exceptionexc_info)r   rI   rJ   rK   rL   rM   rN   s          r   r   zResult.__init__I   s4     (("" r   c                     | j         S )z(The (standard) output as unicode string.)stdoutr/   s    r   r   zResult.outputY   s     {r   c                 t    | j                             | j        j        d                              dd          S )z&The standard output as unicode string.replace

)rJ   decoderI   rC   rR   r/   s    r   rP   zResult.stdout^   s9      ''(;YGGOOD
 
 	
r   c                     | j         t          d          | j                             | j        j        d                              dd          S )z%The standard error as unicode string.Nzstderr not separately capturedrR   rS   rT   )rK   
ValueErrorrU   rI   rC   rR   r/   s    r   stderrzResult.stderre   sQ     $=>>> ''(;YGGOOD
 
 	
r   c                     d                     t          |           j        | j        rt	          | j                  nd          S )Nz<{} {}>okay)formattyper8   rM   r6   r/   s    r   r7   zResult.__repr__n   s>    JJ!Sdn!5!5!5V
 
 	
r   r   )
r8   r9   r:   __doc__r   propertyr   rP   rX   r7   r)   r   r   rF   rF   F   s        == RV! ! ! !    X 
 
 X
 
 
 X

 
 
 
 
r   rF   c                   |    e Zd ZdZddZd ZddZej        dd            Z		 	 	 	 	 dd	Z
ej        d
             ZdS )	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
    NFTc                 J    |d}|| _         |pi | _        || _        || _        d S )Nzutf-8)rC   env
echo_stdin
mix_stderr)r   rC   rb   rc   rd   s        r   r   zCliRunner.__init__   s0    ?G9"$$r   c                     |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   clis     r   get_default_prog_namezCliRunner.get_default_prog_name   s    
 x!6!r   c                 \    t          | j                  }|r|                    |           |S )z8Returns the environment overrides for invoking a script.)dictrb   update)r   	overridesr   s      r   make_envzCliRunner.make_env   s.    $(^^ 	!IIi   	r   c              #     K   t          | j                  t          j        }t          j        }t          j        }t          j        }dt          _        |                     |          }t          rSt                      }| j        rt          |          |t          _        | j        st                      }	|	t          _        nt          j                    }| j        rt          |          t          j        | j                  t          j        || j                  t          _        | j        s8t          j                    }	t          j        |	| j                  t          _        | j        rt          j        t          _        t          _        dfd	}
dfd	}d }|d	fd	}t"          j        }t"          j        }t"          j        }t*          j        }|
t"          _        |t"          _        |t"          _        |t*          _        i }	 t/          |          D ]W\  }}t0          j                            |          ||<   |	 t0          j        |= 8# t6          $ r Y Dw xY w|t0          j        |<   X|| j         o|	fV  t/          |          D ]5\  }}|	 t0          j        |= # t6          $ r Y "w xY w|t0          j        |<   6|t          _        |t          _        |t          _        |t"          _        |t"          _        |t"          _        |t*          _        |t          _        dS # t/          |          D ]5\  }}|	 t0          j        |= # t6          $ r Y "w xY w|t0          j        |<   6|t          _        |t          _        |t          _        |t"          _        |t"          _        |t"          _        |t*          _        |t          _        w xY 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.

        .. 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                 8   t           j                            | pd                                                               d          }t           j                            d                    |                     t           j                                         |S )N rS   {}
)sysrP   r   r&   rstripr[   flush)promptvalr   s     r   visible_inputz*CliRunner.isolation.<locals>.visible_input   su    JV\r***..""))&11CJV]]3//000JJr   c                     t           j                            d                    | pd                     t           j                                                                                             d          S )Nrt   rs   rS   )ru   rP   r   r[   rw   r&   rv   )rx   r   s    r   hidden_inputz)CliRunner.isolation.<locals>.hidden_input   s[    JV]]6<R88999J>>##**6222r   c                     t           j                            d          }| r=t           j                            |           t           j                                         |S )Nr   )ru   stdinr"   rP   r   rw   )echochars     r   _getcharz%CliRunner.isolation.<locals>._getchar   sL    9>>!$$D #
  &&&
  """Kr   c                     | S | S r   r)   )streamcolordefault_colors     r   should_strip_ansiz.CliRunner.isolation.<locals>.should_strip_ansi   s    }(((9r   r   )NN)rD   rC   ru   r~   rP   rX   r   FORCED_WIDTHrn   r   r
   rc   r   rd   rA   rB   TextIOWrapperr   visible_prompt_funchidden_prompt_funcr   r   r   r   osenvironget	Exception)r   r   rb   r   	old_stdin
old_stdout
old_stderrold_forced_widthbytes_outputbytes_errorrz   r|   r   r   old_visible_prompt_funcold_hidden_prompt_funcold__getchar_funcold_should_strip_ansiold_envkeyvaluer   s    `                   @r   	isolationzCliRunner.isolation   s     $ "%66I	Z
Z
%2"$
mmC   	R#::L :$UL99%CJ? )&jj(
:<<L :$UL99$UT\BBBE),NNNCJ? R jll-kDLQQQ
? 	$CJ		 	 	 	 	 		3 	3 	3 	3 	3 	3
	 	 	 	 	 	 	 	 	
 #)"<!'!:"O % 7%2"$0!""3	7'nn , ,
U!z~~c22=JsOO$    ',BJsOOT_!4!DEEEE'00 , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#&6J### (00 , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#&6J#6666sg   8L- 
IL- 
I%"L- $I%%!L- J++
J87J8-OMO
M 	OM 	 A4Oc                    d}|                      |||          5 }	d}
d}t          |t                    rt          j        |          }	 |                    d          }n%# t          $ r |                     |          }Y nw xY w	  |j        d|pd|d| n# t          $ r}t          j                    }|j        }|d}|dk    r|}
t          |t                    sMt          j                            t!          |                     t          j                            d           d}Y d}~n4d}~wt"          $ r$}|s |}
d}t          j                    }Y d}~nd}~ww xY wt          j                                         |	d                                         }| j        rd}n||	d                                         }na# t          j                                         |	d                                         }| j        rd}n|	d                                         }w xY wddd           n# 1 swxY w Y   t+          | ||||
|	          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)r   rb   r   r   	prog_namer)   )argsr   rT   r   rH   )r   r>   r	   shlexsplitpopKeyErrorri   main
SystemExitru   rN   codeintrP   r   strr   rw   getvaluerd   rF   )r   rh   r   r   rb   catch_exceptionsr   extrarN   
outstreamsrM   rL   r   erP   rX   s                   r   invokezCliRunner.invoke  s   P ^^%S^>> (	6*II$-- ){4((<!IIk22		 < < < 66s;;			<6GdjbIGGGGGG " " "<>>F	$ !I>> !I!)S11 "J$$S^^444J$$T*** !I * * *' 		<>>* 
  """#A//11? 6!FF']3355FF 
  """#A//11? 6!FF']3355F5555Q(	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6 (	6T 
 
 
 	
s   .H.
A H. B?H.BH.BG
E!#BD0+G0E!=EGE!!G$AH.AHH..H25H2c              #     K   t          j                    }t          j                    }t          j        |           	 |V  t          j        |           	 t          j        |           dS # t          t          f$ r Y dS w xY w# t          j        |           	 t          j        |           w # t          t          f$ r Y w w xY wxY w)zA context manager that creates a temporary folder and changes
        the current working directory to it for isolated filesystem tests.
        N)	r   getcwdtempfilemkdtempchdirshutilrmtreeOSErrorIOError)r   cwdts      r   isolated_filesystemzCliRunner.isolated_filesystemo  s      
 ikk
	GGGHSMMMa     W%    HSMMMa    W%   sA   B A- -BBCB0/C0CCCC)NNFTr   )NNF)NNNTF)r8   r9   r:   r]   r   ri   rn   
contextlibcontextmanagerr   r   r   r)   r   r   r`   r`   t   s         (% % % %" " "    q7 q7 q7 q7l Z
 Z
 Z
 Z
x     r   r`   )r   r   r   r   ru   r   rs   r   r   r   _compatr   r   r	   	cStringIOr
   rA   r   objectr   rD   rF   r`   r)   r   r   <module>r      s       				   



                                ! ! ! ! ! !  -"""""""III,,,,,,! ! ! ! !6 ! ! !8  &+
 +
 +
 +
 +
V +
 +
 +
\J J J J J J J J J Jr   