
    /hI                       d dl mZ d dlm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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 ddlmZ  G d d          Zej        d#d            Z G d dej                  Z G d d          Z  G d dej!                  Z"d$dZ# G d d           Z$ G d! d"          Z%dS )%    )annotationsN)TracebackType   )_compat)
formatting)termui)utils)_find_binary_reader)ReadableBuffer)Commandc                  \    e Zd ZddZdd
ZddZdddZdddZdddZddZ	d dZ
d!dZdS )"EchoingStdininput
t.BinaryIOoutputreturnNonec                0    || _         || _        d| _        d S )NF)_input_output_paused)selfr   r   s      @/var/www/html/venv/lib/python3.11/site-packages/click/testing.py__init__zEchoingStdin.__init__   s        xstrt.Anyc                ,    t          | j        |          S N)getattrr   )r   r   s     r   __getattr__zEchoingStdin.__getattr__    s    t{A&&&r   rvbytesc                H    | j         s| j                            |           |S r    )r   r   write)r   r#   s     r   _echozEchoingStdin._echo#   s'    | 	#Lr"""	r   nintc                \    |                      | j                            |                    S r    )r'   r   readr   r)   s     r   r,   zEchoingStdin.read)   s$    zz$+**1--...r   c                \    |                      | j                            |                    S r    )r'   r   read1r-   s     r   r/   zEchoingStdin.read1,   s$    zz$+++A..///r   c                \    |                      | j                            |                    S r    )r'   r   readliner-   s     r   r1   zEchoingStdin.readline/   s$    zz$+..q11222r   list[bytes]c                N      fd j                                         D             S )Nc                :    g | ]}                     |          S  r'   .0r   r   s     r   
<listcomp>z*EchoingStdin.readlines.<locals>.<listcomp>3   s#    ???!

1???r   )r   	readlinesr   s   `r   r:   zEchoingStdin.readlines2   s+    ????t{'<'<'>'>????r   cabc.Iterator[bytes]c                D     t           fd j        D                       S )Nc              3  B   K   | ]}                     |          V  d S r    r6   r7   s     r   	<genexpr>z(EchoingStdin.__iter__.<locals>.<genexpr>6   s-      77aDJJqMM777777r   )iterr   r;   s   `r   __iter__zEchoingStdin.__iter__5   s(    77774;777777r   c                *    t          | j                  S r    )reprr   r;   s    r   __repr__zEchoingStdin.__repr__8   s    DK   r   N)r   r   r   r   r   r   )r   r   r   r   )r#   r$   r   r$   )r(   )r)   r*   r   r$   )r   r2   )r   r<   r   r   )__name__
__module____qualname__r   r"   r'   r,   r/   r1   r:   rA   rD   r5   r   r   r   r      s           
' ' ' '   / / / / /0 0 0 0 03 3 3 3 3@ @ @ @8 8 8 8! ! ! ! ! !r   r   streamEchoingStdin | Noner   cabc.Iterator[None]c              #  >   K   | d V  d S d| _         d V  d| _         d S )NTF)r   )rI   s    r   _pause_echorM   <   s3      ~r   c                  <     e Zd ZdZd fdZd fdZd fdZ xZS )BytesIOCopyzdPatch ``io.BytesIO`` to let the written stream be copied to another.

    .. versionadded:: 8.2
    copy_to
io.BytesIOr   r   c                V    t                                                       || _        d S r    )superr   rP   )r   rP   	__class__s     r   r   zBytesIOCopy.__init__L   s$    r   c                z    t                                                       | j                                         d S r    )rS   flushrP   )r   rT   s    r   rV   zBytesIOCopy.flushP   s.    r   br   r*   c                z    | j                             |           t                                          |          S r    )rP   r&   rS   )r   rW   rT   s     r   r&   zBytesIOCopy.writeT   s/    1ww}}Qr   )rP   rQ   r   r   r   r   )rW   r   r   r*   )rF   rG   rH   __doc__r   rV   r&   __classcell__rT   s   @r   rO   rO   F   s         
                             r   rO   c                      e Zd ZdZddZdS )StreamMixerzMixes `<stdout>` and `<stderr>` streams.

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

    .. versionadded:: 8.2
    r   r   c                    t          j                    | _        t          | j                  | _        t          | j                  | _        d S )N)rP   )ioBytesIOr   rO   stdoutstderrr;   s    r   r   zStreamMixer.__init__a   s;    "$*,,"-dk"B"B"B"-dk"B"B"Br   NrY   )rF   rG   rH   rZ   r   r5   r   r   r^   r^   Y   s8         C C C C C Cr   r^   c                  \     e Zd Zd fd
Zedd            Zedd            Zd fdZ xZS )_NamedTextIOWrapperbufferr   namer   modekwargsr   r   r   c                X     t                      j        |fi | || _        || _        d S r    )rS   r   _name_mode)r   rf   rg   rh   ri   rT   s        r   r   z_NamedTextIOWrapper.__init__h   s6     	**6***



r   c                    | j         S r    )rk   r;   s    r   rg   z_NamedTextIOWrapper.nameo   
    zr   c                    | j         S r    )rl   r;   s    r   rh   z_NamedTextIOWrapper.modes   rn   r   c                    	 t                                                      }n!# t          $ r}t                      |d }~ww xY w|S r    )rS   __next__StopIterationEOFError)r   lineerT   s      r   rq   z_NamedTextIOWrapper.__next__w   sO    	$77##%%DD 	$ 	$ 	$**!#	$s    $ 
A=A)
rf   r   rg   r   rh   r   ri   r   r   r   rE   )	rF   rG   rH   r   propertyrg   rh   rq   r[   r\   s   @r   re   re   g   s                 X    X         r   re   r    str | bytes | t.IO[t.Any] | Nonecharsetr   r   c                   t          | d          r5t          t          j        d|                     }||S t	          d          | d} n*t          | t                    r|                     |          } t          j	        |           S )Nr,   zt.IO[t.Any]z.Could not find binary reader for input stream.r   )
hasattrr
   tcast	TypeError
isinstancer   encoder`   ra   )r   rx   r#   s      r   make_input_streamr      s     uf J u!=!=>>>IHIII}	E3		 &W%%:er   c                  n    e Zd ZdZ	 dddZedd            Zedd            Zedd            ZddZ	dS )ResultaC  Holds 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	                v    || _         || _        || _        || _        || _        || _        || _        || _        d S r    r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   s	            r   r   zResult.__init__   sD     (((("" r   r   r   c                t    | j                             | j        j        d                              dd          S )a  The 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

)r   decoder   rx   r   r;   s    r   r   zResult.output   s9      ''(;YGGOOD
 
 	
r   c                t    | j                             | j        j        d                              dd          S )z&The standard output as unicode string.r   r   r   )r   r   r   rx   r   r;   s    r   rb   zResult.stdout   s9      ''(;YGGOOD
 
 	
r   c                t    | j                             | j        j        d                              dd          S )zThe standard error as unicode string.

        .. versionchanged:: 8.2
            No longer raise an exception, always returns the `<stderr>` string.
        r   r   r   )r   r   r   rx   r   r;   s    r   rc   zResult.stderr   s9      ''(;YGGOOD
 
 	
r   c                r    | j         rt          | j                   nd}dt          |           j         d| dS )Nokay< >)r   rC   typerF   )r   exc_strs     r   rD   zResult.__repr__   s?    *..D$t~&&&f34::&333333r   r    )r   r   r   r$   r   r$   r   r$   r   r   r   r*   r   r   r   r   rE   )
rF   rG   rH   rZ   r   rv   r   rb   rc   rD   r5   r   r   r   r      s         > ! ! ! ! !* 	
 	
 	
 X	
 
 
 
 X
 
 
 
 X
4 4 4 4 4 4r   r   c                      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/d%            ZdS )0r   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 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-8NFTrx   r   env$cabc.Mapping[str, str | None] | None
echo_stdinboolcatch_exceptionsr   r   c                B    || _         |pi | _        || _        || _        d S r    )rx   r   r   r   )r   rx   r   r   r   s        r   r   zCliRunner.__init__   s+     25)$ 0r   clir   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)rg   )r   r   s     r   get_default_prog_namezCliRunner.get_default_prog_name  s    
 x!6!r   	overridescabc.Mapping[str, str | None]c                \    t          | j                  }|r|                    |           |S )z8Returns the environment overrides for invoking a script.)dictr   update)r   r   r#   s      r   make_envzCliRunner.make_env
  s0     $(^^ 	!IIi   	r   r   rw   color8cabc.Iterator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]]c              #    K   t          || j                  }d}t          j        }t          j        }t          j        }t          j        }	dt          _        |                     |          }t                      }
| j
        r4t          j        t          j        t          ||
j                            x}}t          || j        dd          xt          _        | j
        rd_        t          |
j        | j        dd          t          _        t          |
j        | j        d	dd
          t          _        t#          |          ddfd            }t#          |          ddfd            }t#          |          dd            }|	 ddfd}t$          j        }t$          j        }t$          j        }t,          j        }t0          j        }|t$          _        |t$          _        |t$          _        |t,          _        |t0          _        i }	 |                                D ]W\  }}t4          j                            |          ||<   |	 t4          j        |= 8# t:          $ r Y Dw xY w|t4          j        |<   X|
j        |
j        |
j        fV  |                                D ]5\  }}|	 t4          j        |= # t:          $ r Y "w xY w|t4          j        |<   6|t          _        |t          _        |t          _        |t$          _        |t$          _        |t$          _        |t,          _        |t0          _        |	t          _        dS # |                                D ]5\  }}|	 t4          j        |= # t:          $ r Y "w xY w|t4          j        |<   6|t          _        |t          _        |t          _        |t$          _        |t$          _        |t$          _        |t,          _        |t0          _        |	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.

        :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.
        NP   z<stdin>r)encodingrg   rh   r   z<stdout>wz<stderr>backslashreplace)r   rg   rh   errorsprompt
str | Noner   r   c                   t           j                            | pd           t                                        d          }t           j                            | d           t           j                                         |S )N r   r   )sysrb   r&   nextrstriprV   )r   val
text_inputs     r   visible_inputz*CliRunner.isolation.<locals>.visible_input\  sm    JV\r***z""))&11CJZZZ(((JJr   c                    t           j                            | pd d           t           j                                         t	                                        d          S )Nr   r   r   )r   rb   r&   rV   r   r   )r   r   s    r   hidden_inputz)CliRunner.isolation.<locals>.hidden_inputd  sV    J"000111J
##**6222r   echor   c                    t           j                            d          }| rt           j                            |           t           j                                         |S )Nr   )r   stdinr,   rb   r&   rV   )r   chars     r   _getcharz%CliRunner.isolation.<locals>._getcharj  sL    9>>!$$D '
  &&&JKr   rI   t.IO[t.Any] | Noner   bool | Nonec                    | S | S r    r5   )rI   r   default_colors     r   should_strip_ansiz.CliRunner.isolation.<locals>.should_strip_ansiv  s     }(((9r   r    )r   r   r   r   )r   r   r   r   )NN)rI   r   r   r   r   r   )r   rx   r   r   rb   rc   r   FORCED_WIDTHr   r^   r   r{   r|   BinaryIOr   re   _CHUNK_SIZErM   r   visible_prompt_funchidden_prompt_funcr   r	   r   r   itemsosenvironget	Exceptionr   )r   r   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   s                          @@r   	isolationzCliRunner.isolation  s=     D (t|<<
I	Z
Z
%2"$
mmC  "}}? 	'(v
Ll6IJJ( ( K* "5$,YS"
 "
 "
 	
	J ? 	' &'J"($,Zc
 
 

 )\%
 
 

 
Z	 	 	 	 	 	 	 	 
!	 	 
Z	 	 	3 	3 	3 	3 	3 	3 
!	 	3
 
Z	 	 	 	 	 
!	 	  EI	 	 	 	 	 	 	 #)"<!'!:"O % 7(/(A%%2"$0!""3$5!	7!iikk , ,
U!z~~c22=JsOO$    ',BJsOO&(;\=PQQQQ%mmoo , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#(EG%&6J###! &mmoo , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#(EG%&6J#6666sg   =M IM 
I&#M %I&&)M +J99
KKO?$M21O?2
M?	<O?>M?	?B O?argsstr | cabc.Sequence[str] | Noner   extrar   r   c           
        d}|| j         }|                     |||          5 }	d}
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                    }t          j        d|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                                         t          j                                         |	d                                         }|	d	                                         }|	d
                                         }n# t          j                                         t          j                                         |	d                                         }|	d	                                         }|	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.

        :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_namer5   )r   r   zint | t.Any | Noner   r      r   )r   r   r~   r   shlexsplitpopKeyErrorr   main
SystemExitr   r   r{   r|   coder*   rb   r&   r   rV   rc   getvaluer   )r   r   r   r   r   r   r   r   r   
outstreamsr   r   r   r   ru   e_coderb   rc   r   s                      r   invokezCliRunner.invoke  s+   j ##4^^%S^>> +	2*L.2II$$$ ){4((<!IIk22		 < < < 66s;;			<2'sxVTZR9VVPUVV # # #<>> 4af==>FQ;; !I!&#.. J$$S[[111J$$T***F"						 * * *' 		<>>* 
  """
  """#A//11#A//11#A//11	 
  """
  """#A//11#A//11#A//111111W+	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2 +	2Z %	
 	
 	
 		
s   0J+A+*J++B
J+BJ+B$#H$
F.BEHFE<7H<FHBJ+BJJ++J/2J/temp_dirstr | os.PathLike[str] | Nonecabc.Iterator[str]c              #    K   t          j                    }t          j        |          }t          j        |           	 |V  t          j        |           |(	 t          j        |           dS # t          $ r Y dS w xY wdS # t          j        |           |&	 t          j        |           w # t          $ r Y w w xY ww xY w)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dts       r   isolated_filesystemzCliRunner.isolated_filesystem  s        ikk(+++
		HHHHSMMMM"%%%%%   DD   HSMMMM"%%%%   D  sB    B A1 1
A?>A?CB10C1
B>;C=B>>C)r   NFT)
rx   r   r   r   r   r   r   r   r   r   )r   r   r   r   r    )r   r   r   r   )NNF)r   rw   r   r   r   r   r   r   )NNNNF)r   r   r   r   r   rw   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )rF   rG   rH   rZ   r   r   r   
contextlibcontextmanagerr   r   r  r5   r   r   r   r      s        . 48 !%
1 
1 
1 
1 
1" " " " AE      3748	Q7 Q7 Q7 Q7 Q7l 152648(,o
 o
 o
 o
 o
b 8<      r   r   )rI   rJ   r   rK   )r   rw   rx   r   r   r   )&
__future__r   collections.abcabccabcr	  r`   r   r   r  r   r   typingr{   typesr   r   r   r   r   r	   r
   TYPE_CHECKING	_typeshedr   corer   r   r
  rM   ra   rO   r^   TextIOWrapperre   r   r   r   r5   r   r   <module>r     sh   " " " " " "           				 				   



                                    ( ( ( ( ( (? ((((((! ! ! ! ! ! ! !D             "*      &C C C C C C C C    "*   0   (K4 K4 K4 K4 K4 K4 K4 K4\T T T T T T T T T Tr   