4V=jZgRUddlmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZddlmZdd lmZe jr dd lmZdd lmZe jd kre jd Zded<ne jdZded<ee e!e!efZ"ded<GddZ#ej$d+dZ%GddZ&Gddej'Z(GddZ)Gdd ej*Z+d,d&Z,Gd'd(Z-Gd)d*Z.dS)-) annotationsN) TracebackType)_compat) formatting)termui)utils)_find_binary_reader)ReadableBuffer)Commandwin32sysz t.TypeAlias CaptureMode)rfd ExceptionInfoc|eZdZUded<ded<ded<dd ZddZd dZd!d"dZd!d"dZd!d"dZ d#dZ d$dZ d%dZ dS)& EchoingStdin t.BinaryIO_input_outputbool_pausedinputoutputreturnNonec0||_||_d|_dS)NF)rrr)selfrrs ;C:\PYTHON\_runtimes\venv\Lib\site-packages\click/testing.py__init__zEchoingStdin.__init__%s   xstrt.Anyc,t|j|SN)getattrr)rr"s r __getattr__zEchoingStdin.__getattr__*st{A&&&r!rvbytescH|js|j||Sr&)rrwrite)rr)s r_echozEchoingStdin._echo-s'| # L  r " " " r!nintc\||j|Sr&)r-rreadrr/s rr2zEchoingStdin.read3s$zz$+**1--...r!c\||j|Sr&)r-rread1r3s rr5zEchoingStdin.read16s$zz$+++A..///r!c\||j|Sr&)r-rreadliner3s rr7zEchoingStdin.readline9s$zz$+..q11222r! list[bytes]cNfdjDS)Nc:g|]}|Sr-.0r"rs r z*EchoingStdin.readlines..=s#???! 1 ???r!)r readlinesrs`rr@zEchoingStdin.readlines<s+????t{'<'<'>'>????r!cabc.Iterator[bytes]cDtfdjDS)Nc3BK|]}|VdSr&r<r=s r z(EchoingStdin.__iter__..@s-77aDJJqMM777777r!)iterrrAs`r__iter__zEchoingStdin.__iter__?s(77774;777777r!c*t|jSr&)reprrrAs r__repr__zEchoingStdin.__repr__BsDK   r!N)rrrrrr)r"r#rr$)r)r*rr*)r.)r/r0rr*)rr8)rrBrr#) __name__ __module__ __qualname____annotations__r r(r-r2r5r7r@rGrJr;r!rrr sMMM '''' /////0000033333@@@@8888!!!!!!r!rstreamEchoingStdin | Nonercabc.Generator[None]c#>K|dVdSd|_dVd|_dS)NTF)r)rPs r _pause_echorTFs3 ~  r!cJeZdZUdZded<ded<ded<dd Zdd Zdd ZdS) _FDCaptureaVRedirect a file descriptor to a temporary file for capture. Saves the current target of *targetfd* via :func:`os.dup`, then redirects it to a temporary file via :func:`os.dup2`. On :meth:`stop`, restores the original ``fd`` and returns the captured bytes. Inspired by Pytest's ``FDCapture``. .. versionadded:: 8.4.0 r0 _targetfdsaved_fdzt.BinaryIO | None_tmpfiletargetfdrrc0||_d|_d|_dSNr.)rWrXrY)rrZs rr z_FDCapture.__init___s!  r!ctj|j|_t jd|_tj|j|jdS)Nr) buffering) osduprWrXtempfile TemporaryFilerYdup2filenorAs rstartz_FDCapture.startdsRt~..  .;;;   $$&&77777r!r*cL|j Jdtj|j|jtj|jd|_|jd|j}|jd|_|S)Nz!_FDCapture.start() was not calledr.r)rYr_rcrXrWcloseseekr2)rdatas rstopz_FDCapture.stopis}((*M(((  t~...   1}!!##   r!N)rZr0rrrr)rr*)rLrMrN__doc__rOr rerjr;r!rrVrVPs|NNNMMM 8888      r!rVcHeZdZUdZded<d fd Zd fd Zdfd ZxZS) BytesIOCopyzdPatch ``io.BytesIO`` to let the written stream be copied to another. .. versionadded:: 8.2 io.BytesIOcopy_torrcVt||_dSr&)superr rp)rrp __class__s rr zBytesIOCopy.__init__}s$  r!czt|jdSr&)rrflushrprrss rruzBytesIOCopy.flushs.   r!br r0cz|j|t|Sr&)rpr,rr)rrwrss rr,zBytesIOCopy.writes/ 1ww}}Qr!)rprorrrk)rwr rr0) rLrMrNrlrOr rur, __classcell__rss@rrnrnus           r!rnc:eZdZUdZded<ded<ded<d d Zd S) StreamMixerzMixes `` and `` streams. The result is available in the ``output`` attribute. .. versionadded:: 8.2 rorrnstdoutstderrrrctj|_t|j|_t|j|_dS)N)rp)ioBytesIOrrnr}r~rAs rr zStreamMixer.__init__s;jll !$+666 !$+666 r!Nrk)rLrMrNrlrOr r;r!rr|r|sZ777777r!r|ceZdZUdZded<ded<ded<dfd ZddZdfd ZeddZ eddZ xZ S)_NamedTextIOWrapperaA :class:`~io.TextIOWrapper` with custom ``name`` and ``mode`` that does not close its underlying buffer. When ``CliRunner`` runs in ``fd`` mode, ``_original_fd`` is patched to point at the saved (pre-redirection) ``fd``, so C-level consumers that call :meth:`fileno` (like ``faulthandler`` or ``subprocess``) keep working. In the default ``sys`` mode ``_original_fd`` stays at ``-1`` and :meth:`fileno` raises :exc:`io.UnsupportedOperation`, matching the pre-``8.3.3`` behavior. r#_name_moder0 _original_fdbufferrnamemodekwargsr$rrc ftj|fi|||_||_d|_dSr\)rrr rrr)rrrrrrss rr z_NamedTextIOWrapper.__init__s@ **6***  r!cdS)zThe buffer this object contains belongs to some other object, so prevent the default ``__del__`` implementation from closing that buffer. .. versionadded:: 8.3.2 Nr;rAs rrgz_NamedTextIOWrapper.closesr!ch|jdkr|jStS)zReturn the file descriptor of the saved original stream when ``CliRunner`` runs in ``fd`` mode. Otherwise delegate to :class:`~io.TextIOWrapper`, which raises :exc:`io.UnsupportedOperation` for a ``BytesIO``-backed buffer. r)rrrrdrvs rrdz_NamedTextIOWrapper.filenos0   ! !$ $ww~~r!c|jSr&)rrAs rrz_NamedTextIOWrapper.name zr!c|jSr&)rrAs rrz_NamedTextIOWrapper.moderr!) rrrr#rr#rr$rrrk)rr0rK) rLrMrNrlrOr rgrdpropertyrrryrzs@rrrs  JJJJJJ                XXr!rr str | bytes | t.IO[t.Any] | Nonecharsetr#rct|dr5ttjd|}||St d|d}n*t |t r||}tj |S)Nr2z t.IO[t.Any]z.Could not find binary reader for input stream.r!) hasattrr tcast TypeError isinstancer#encoderr)rrr)s rmake_input_streamrsufJ  u!=!= > > >IHIII } E3  & W%% :e  r!ceZdZUdZded<ded<ded<ded<ded <d ed <d ed <ded< dddZeddZeddZeddZ ddZ 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``. CliRunnerrunnerr* stdout_bytes stderr_bytes output_bytesr$ return_valuer0 exit_codeBaseException | None exceptionExceptionInfo | Noneexc_infoNrrc v||_||_||_||_||_||_||_||_dSr&rrrrrrrr) rrrrrrrrrs rr zResult.__init__sD ((((""  r!r#ct|j|jjdddS)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 `` and ``, in the order they were written. replace  )rdecoderrrrAs rrz Result.outputs9 '' (;YGGOO D   r!ct|j|jjdddS)z&The standard output as unicode string.rrr)rrrrrrAs rr}z Result.stdout&s9 '' (;YGGOO D   r!ct|j|jjdddS)zThe standard error as unicode string. .. versionchanged:: 8.2 No longer raise an exception, always returns the `` string. rrr)rrrrrrAs rr~z Result.stderr-s9 '' (;YGGOO D   r!cr|jrt|jnd}dt|jd|dS)Nokay< >)rrItyperL)rexc_strs rrJzResult.__repr__8s?*..D$t~&&&f34::&333333r!r&)rrrr*rr*rr*rr$rr0rrrrrrrK) rLrMrNrlrOr rrr}r~rJr;r!rrrs*NNN####""""*.!!!!!(    X     X    X 444444r!rceZdZUdZded<ded<ded<ded<d ed < d)d*dZd+dZ d,d-dZej d.d/dZ d0d1d$Z ej d,d2d(Z d S)3raThe 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 `` writes to ``. 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`. :param capture: Selects the output capture strategy. ``sys`` (default) captures Python-level writes only and leaves :meth:`sys.stdout.fileno` raising :exc:`io.UnsupportedOperation`, so user code that calls :func:`os.dup2` on ``sys.stdout.fileno()`` cannot clobber the host runner's stdout. ``fd`` redirects file descriptors ``1`` and ``2`` via :func:`os.dup2` to a temporary file, also catching output from stale stream references, C extensions, and subprocesses. ``fd`` is not supported on Windows. .. versionchanged:: 8.4.0 Added the ``capture`` parameter. The default ``sys`` mode no longer exposes the original fd through :meth:`fileno`, reverting the change introduced in ``8.3.3`` that broke Pytest's ``fd``-level capture teardown. Use ``capture="fd"`` to restore that behavior with proper isolation. :issue:`3384` .. versionchanged:: 8.2 Added the ``catch_exceptions`` parameter. .. versionchanged:: 8.2 ``mix_stderr`` parameter has been removed. r#rcabc.Mapping[str, str | None]envr echo_stdincatch_exceptionsrcaptureutf-8NFTr$cabc.Mapping[str, str | None] | Nonerrc|dvrtd|d|dkr#tjdkrtd|d||_|pi|_||_||_||_dS)N>rrzcapture=z) is not valid. Choose from 'sys' or 'fd'.rr z( is not supported on Windows. Use 'sys'.) ValueErrorrplatformrrrrr)rrrrrrs rr zCliRunner.__init__hs - ' 'O7OOO  d??s|w66N7NNN  9"$ 0 r!clir c|jpdS)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)r)rrs rget_default_prog_namezCliRunner.get_default_prog_name~s x!6!r! overridesc\t|j}|r|||S)z8Returns the environment overrides for invoking a script.)dictrupdate)rrr)s rmake_envzCliRunner.make_envs0$(^^  ! IIi  r!rrcolor9cabc.Generator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]]c#Kt||j}d}tj}tj}tj}t j} dt _||}t} |j r4tj tj t|| jx}}t||jddxt_|j rd_t| j|jddt_t| j|jd dd t_t#|d%d&fd } t#|d%d&fd } t#|d'd} | d(d)fd }t$j}t$j}t$j}t,j}t0j}t2jj| t$_| t$_| t$_|t,_|t0_ d*d+fd$ }|t2j_i} |D]W\}}t:j|||<| t:j|=8#t@$rYDwxYw|t:j|<X| j| j| j!fV|D]5\}}| t:j|=#t@$rY"wxYw|t:j|<6|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _t2j_dS#|D]5\}}| t:j|=#t@$rY"wxYw|t:j|<6|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _t2j_wxYw),a\A context manager that sets up the isolation for invoking of a command line tool. This sets up `` 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 `` and `` streams. .. versionchanged:: 8.2 Always returns the `` stream. .. versionchanged:: 8.0 `` is opened with ``errors="backslashreplace"`` instead of the default ``"strict"``. .. versionchanged:: 4.0 Added the ``color`` parameter. NPzr)encodingrrrzwzbackslashreplace)rrrerrorsprompt str | Nonerr#cTtj|pd td}n!#t $r}t |d}~wwxYwtj|dtj|S)Nrr)rr}r,nextrstrip StopIterationEOFErrorru)rvale text_inputs r visible_inputz*CliRunner.isolation..visible_inputs J  V\r * * * (:&&--f55  ( ( (jja' ( J  ZZZ ( ( ( J     Js"A A%A  A%ctj|pddtj t dS#t $r}t|d}~wwxYw)Nrrr)rr}r,rurrrr)rrrs r hidden_inputz)CliRunner.isolation..hidden_inputs J   "000 1 1 1 J      (J''..v666  ( ( (jja' (s!A'' B1BBechorctjd}|rtj|tj|S)Nr)rstdinr2r}r,ru)rchars r_getcharz%CliRunner.isolation.._getcharsL9>>!$$D '   &&& J     Kr!rPt.IO[t.Any] | Noner bool | Nonec| S| Sr&r;)rPr default_colors rshould_strip_ansiz.CliRunner.isolation..should_strip_ansis}(((9 r!tabrpdb.Pdb completekeyrt.IO[str] | Noner}rr$rcZ| tj}| tj}|f|||d|dS)abDefault ``pdb.Pdb`` to real terminal streams during ``CliRunner`` isolation. Without this patch, ``pdb.Pdb.__init__`` inherits from ``cmd.Cmd`` which falls back to ``sys.stdin``/``sys.stdout`` when no explicit streams are provided. During isolation those are ``BytesIO``-backed wrappers, so the debugger reads from an empty buffer and writes to captured output, making interactive debugging impossible. By defaulting to ``sys.__stdin__``/``sys.__stdout__`` (the original terminal streams Python preserves regardless of redirection), debuggers can interact with the user while ``click.echo`` output is still captured normally. This covers ``pdb.set_trace()``, ``breakpoint()``, ``pdb.post_mortem()``, and debuggers that subclass ``pdb.Pdb`` (ipdb, pdbpp). Explicit ``stdin``/``stdout`` arguments are honored and not overridden. Debuggers that do not subclass ``pdb.Pdb`` (pudb, debugpy) are not covered. N)rrr})r __stdin__ __stdout__)rrrr}r old_pdb_inits r_patched_pdb_initz.CliRunner.isolation.._patched_pdb_init sW:} ~ L "-U6  MS     r!r&)rrrr#)rrrr#)NN)rPrrrrr)rNN) rrrr#rrr}rrr$rr)"rrrrr}r~r FORCED_WIDTHrr|rrrBinaryIOrr _CHUNK_SIZErTrvisible_prompt_funchidden_prompt_funcrr rrpdbPdbr itemsr_environget Exceptionr)rrrr bytes_input echo_input old_stdin old_stdout old_stderrold_forced_width stream_mixerrrrrold_visible_prompt_funcold_hidden_prompt_funcold__getchar_funcold_should_strip_ansiold__compat_should_strip_ansirold_envkeyvaluerrrs @@@r isolationzCliRunner.isolationsD(t|<<  I Z Z %2"$ mmC  "}} ? '(v Ll6IJJ(( K*"5 $,YS" " "   J ? '&'J "(  \     )  \%      Z        !   Z  ( ( ( ( ( ( !  ( Z     !   EI       #)"<!'!:"O % 7(/(A%w' %2"$0!""3$5! %&*'+ # # # # # # # J- ,!iikk , , U!z~~c22 =JsOO$',BJsOO& (;\=PQ Q Q Q%mmoo , , U=JsOO$',BJsOO#CJ#CJ!CI)@F &(>F %/FO&;E #(EG %&6J #+CG   #&mmoo , , U=JsOO$',BJsOO#CJ#CJ!CI)@F &(>F %/FO&;E #(EG %&6J #+CG  + + + +sg:=N8 JN JNJ)N K&& K32K3Q" N0/Q0 N= :Q<N= =BQargsstr | cabc.Sequence[str] | Nonerextrar$rc hd}||j}d} d} |jdkr\td} td} | | n#t$rdx} } YnwxYw||||5} | .| ,| jtj_ | jtj _ d} d} d}t|trtj|} |d}n%#t $r||}YnwxYw |jd|pd|d |} n#t&$r}tj}t+jd |j}|d}|dkr|} t|t0sMtjt|tjd d}|}Yd}~n4d}~wt4$r$}|s|} d}tj}Yd}~nd}~wwxYwtjtj | d| b| }| }|r| d||r| d|| d}| d}| d}n#tjtj | d| b| }| }|r| d||r| d|| d}| d}| d}wxYw dddn #1swxYwYt=||||| || | 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. Nrr)rrrr prog_namer;)rrzint | t.Any | Nonerr)rrrVreOSErrorrrXrr}rr~rr#shlexsplitpopKeyErrorrmain SystemExitrrrcoder0r,rrurjgetvaluer)rrrrrrrrrcap_outcap_err outstreamsrrrrre_codefd_outfd_errr}r~rs rinvokezCliRunner.invokeTsj  ##4 &*%) <4   mmG mmG )   ) ) )$((''' )^^%S^ > >> 2*"w':*1*: '*1*: 'L.2II$$$ ){4(( <!IIk22  < < < 66s;;  <* 2'sxVTZR9VVPUVV  # # #<>> 4af==>FQ;; !I!&#..J$$S[[111J$$T***F"  * * *'  <>>  *   """   """ &7+>$\\^^F$\\^^F4"1 ++F3334"1 ++F333#A//11#A//11#A//11!   """   """ &7+>$\\^^F$\\^^F4"1 ++F3334"1 ++F333#A//11#A//11#A//111111}> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2> 2@%    s(A##A43A4A P0DPD(%P'D((P,D?>L? H BG+&L+ H8HLHLC1PC2PPPPtemp_dirstr | os.PathLike[str] | Nonecabc.Generator[str]c#Ktj}tj|}tj| |Vtj||-ddl} ||dS#t$rYdSwxYwdS#tj||+ddl} ||w#t$rYwwxYwwxYw)aA 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. )dirNr)r_getcwdramkdtempchdirshutilrmtreer)rr(cwddtr0s risolated_filesystemzCliRunner.isolated_filesystems ikk  ( + + +   HHH HSMMM MM"%%%%%DD   HSMMM MM"%%%%D  sBB A66 BB C %B;:C ; CC CC )rNFTr) rr#rrrrrrrrrr)rr rr#r&)rrrr)NNF)rrrrrrrr)NNNNF)rr rrrrrrrrrrrr$rr)r(r)rr*) rLrMrNrlrOr rr contextlibcontextmanagerrr'r4r;r!rrr=sP""HLLL&&&&48 !%$ ,""""AE3748 C,C,C,C,C,P152648(,O O O O O b8<r!r)rPrQrrR)rrrr#rr)/ __future__rcollections.abcabccabcr5rr_rrrratypingrtypesrrrrrr r TYPE_CHECKING _typeshedr corer rLiteralrrOtupler BaseExceptionrrr6rTrVrrnr| TextIOWrapperrrrrr;r!rrDs""""""" ((((((?((((((<7 y/K///// y5K5555"4 #6 }#TU UUUU#!#!#!#!#!#!#!#!L """"""""J     "*   *77777777$44444"*444n(S4S4S4S4S4S4S4S4lGGGGGGGGGGr!