XjZgXUddlmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZddlmZdd lmZe j,r dd lmZdd lmZe j6d k(re j8d Zded<ne j8dZded<ee e!e!efZ"ded<GddZ#ejHd"dZ%GddZ&GddejNZ(GddZ)GddejTZ+ d#dZ,GddZ-Gd d!Z.y)$) annotationsN) TracebackType)_compat) formatting)termui)utils)_find_binary_reader)ReadableBuffer)Commandwin32sysz t.TypeAlias CaptureMode)rfd ExceptionInfoczeZdZUded<ded<ded<ddZddZddZddd Zddd Zddd Z dd Z dd Z ddZ y) EchoingStdin t.BinaryIO_input_outputbool_pausedc.||_||_d|_y)NF)rrr)selfinputoutputs a/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/click/testing.py__init__zEchoingStdin.__init__%s   c.t|j|SN)getattrrrxs r __getattr__zEchoingStdin.__getattr__*st{{A&&rcT|js|jj||Sr!)rrwrite)rrvs r_echozEchoingStdin._echo-s || LL  r " rcV|j|jj|Sr!)r)rreadrns rr+zEchoingStdin.read3s zz$++**1-..rcV|j|jj|Sr!)r)rread1r,s rr/zEchoingStdin.read16s zz$++++A.//rcV|j|jj|Sr!)r)rreadliner,s rr1zEchoingStdin.readline9s zz$++..q122rcz|jjDcgc]}|j|c}Scc}wr!)r readlinesr)r#s rr3zEchoingStdin.readlines<s+'+{{'<'<'>?! 1 ???s8c@tfdjDS)Nc3@K|]}j|ywr!)r)).0r$rs r z(EchoingStdin.__iter__..@s7aDJJqM7s)iterrrs`r__iter__zEchoingStdin.__iter__?s74;;777rc,t|jSr!)reprrr9s r__repr__zEchoingStdin.__repr__BsDKK  rN)rrrrreturnNone)r$strr>t.Any)r(bytesr>rB))r-intr>rB)r>z list[bytes])r>zcabc.Iterator[bytes]r>r@) __name__ __module__ __qualname____annotations__rr%r)r+r/r1r3r:r=rrrr sA   M ' /03@8!rrc#>K|dyd|_dd|_yw)NTF)r)streams r _pause_echorMFs ~  scHeZdZUdZded<ded<ded<d dZd dZd d Zy ) _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 rD _targetfdsaved_fdzt.BinaryIO | None_tmpfilec.||_d|_d|_yNrC)rPrQrR)rtargetfds rrz_FDCapture.__init___s!  rctj|j|_t j d|_tj|j j|jy)Nr) buffering) osduprPrQtempfile TemporaryFilerRdup2filenor9s rstartz_FDCapture.startdsGt~~.  ..;   $$&7rcx|jJdtj|j|jtj |jd|_|jj d|jj}|jj d|_|S)Nz!_FDCapture.start() was not calledrCr)rRrXr\rQrPcloseseekr+)rdatas rstopz_FDCapture.stopis}}(M*MM(  t~~.   1}}!!#   rN)rUrDr>r?r>r?)r>rB)rFrGrH__doc__rIrr^rcrJrrrOrOPs(NM 8 rrOcHeZdZUdZded<dfd Zdfd Zd fd ZxZS) BytesIOCopyzdPatch ``io.BytesIO`` to let the written stream be copied to another. .. versionadded:: 8.2 io.BytesIOcopy_toc0t|||_yr!)superrri)rri __class__s rrzBytesIOCopy.__init__}s  rcVt||jjyr!)rkflushrirrls rrnzBytesIOCopy.flushs   rcX|jj|t||Sr!)rir'rk)rbrls rr'zBytesIOCopy.writes$ 1w}Qr)rirhr>r?rd)rqr r>rD) rFrGrHrerIrrnr' __classcell__rls@rrgrgus$   rrgc8eZdZUdZded<ded<ded<d dZy) StreamMixerzMixes `` and `` streams. The result is available in the ``output`` attribute. .. versionadded:: 8.2 rhrrgstdoutstderrctj|_t|j|_t|j|_y)N)ri)ioBytesIOrrgrvrwr9s rrzStreamMixer.__init__s/jjl !$++6 !$++6 rNrd)rFrGrHrerIrrJrrrurus    7rruceZdZUdZded<ded<ded< d fd Zd dZdfd Zedd Z edd Z 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_moderD _original_fdc Pt||fi|||_||_d|_yrT)rkrr}r~r)rbuffernamemodekwargsrls rrz_NamedTextIOWrapper.__init__s- *6*  rcy)zThe buffer this object contains belongs to some other object, so prevent the default ``__del__`` implementation from closing that buffer. .. versionadded:: 8.3.2 NrJr9s rr`z_NamedTextIOWrapper.closesrcV|jdk\r |jSt| S)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)rrkr]ros rr]z_NamedTextIOWrapper.filenos,    !$$ $w~rc|jSr!)r}r9s rrz_NamedTextIOWrapper.name zzrc|jSr!)r~r9s rrz_NamedTextIOWrapper.moderr) rrrr@rr@rrAr>r?rd)r>rDrE) rFrGrHrerIrr`r]propertyrrrrrss@rr|r|s  J J          rr|ct|dr.ttjd|}||St d|d}n!t |t r|j|}tj|S)Nr+z t.IO[t.Any]z.Could not find binary reader for input stream.r) hasattrr tcast TypeError isinstancer@encoderyrz)rcharsetr(s rmake_input_streamrsjuf  u!= > >IHII } E3  W% ::e rceZdZUdZded<ded<ded<ded<ded <d ed <d ed <ded< d ddZeddZeddZeddZ ddZ y)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``. CliRunnerrunnerrB stdout_bytes stderr_bytes output_bytesrA return_valuerD exit_codeBaseException | None exceptionExceptionInfo | Noneexc_infoNc t||_||_||_||_||_||_||_||_yr!rrrrrrrr) rrrrrrrrrs rrzResult.__init__s@ ((((""  rc|jj|jjdj ddS)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  )rdecoderrrr9s rrz Result.outputs9  '' (;(;YGOO D  rc|jj|jjdj ddS)z&The standard output as unicode string.rrr)rrrrrr9s rrvz Result.stdout&s9  '' (;(;YGOO D  rc|jj|jjdj ddS)zThe standard error as unicode string. .. versionchanged:: 8.2 No longer raise an exception, always returns the `` string. rrr)rrrrrr9s rrwz Result.stderr-s9  '' (;(;YGOO D  rc|jrt|jnd}dt|jd|dS)Nokay< >)rr<typerF)rexc_strs rr=zResult.__repr__8s8*...$t~~&f4:&&'q 33rr!)rrrrBrrBrrBrrArrDrrrrr>r?rE) rFrGrHrerIrrrrvrwr=rJrrrrs* N##""*.!!! !  !  !!(!'! !(        4rrc&eZdZUdZded<ded<ded<ded<d ed < d dd Zdd Z d ddZej d ddZ d ddZ ej d ddZ y )raThe 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_exceptionsrcaptureNc|dvrtd|d|dk(r"tjdk(rtd|d||_|xsi|_||_||_||_y)N>rrzcapture=z) is not valid. Choose from 'sys' or 'fd'.rr z( is not supported on Windows. Use 'sys'.) ValueErrorrplatformrrrrr)rrrrrrs rrzCliRunner.__init__hs~ - '7+%NO  d?s||w67+%MN  9"$ 0 rc"|jxsdS)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)rclis rget_default_prog_namezCliRunner.get_default_prog_name~s xx!6!rcVt|j}|r|j||S)z8Returns the environment overrides for invoking a script.)dictrupdate)r overridesr(s rmake_envzCliRunner.make_envs%$((^  IIi  rc#@ Kt||j}d}tj}tj}tj }t j} dt _|j|}t} |jr:tjtjt|| jx}}t||jddxt_|jrd_t| j|jddt_t| j |jd dd t_t#|ddfd } t#|ddfd } t#|dd} | d dfd }t$j&}t$j(}t$j*}t,j.}t0j.}t2j4j6| t$_| t$_| t$_|t,_|t0_ d dfd }|t2j4_i} |j9D]O\}}t:j<j?|||<| t:j<|==|t:j<|<Q| j| j | jBf|j9D]-\}}| t:j<|=|t:j<|</|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _t2j4_y#t@$rY|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _t2j4_wxYww)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)rrrerrorsc<tjj|xsd tj d}tjj|dtjj|S#t $r}t |d}~wwxYw)Nrr)rrvr'nextrstrip StopIterationEOFErrorrn)promptvale text_inputs r visible_inputz*CliRunner.isolation..visible_inputs~ JJ  V\r * (:&--f5 JJ  uBZ ( JJ   J ! (ja' (sB B BBctjj|xsddtjj t j dS#t $r}t|d}~wwxYw)Nrrr)rrvr'rnrrrr)rrrs r hidden_inputz)CliRunner.isolation..hidden_inputse JJ   "~R0 1 JJ    (J'..v66  (ja' (sA!! A:* A55A:ctjjd}|rtjj |tjj |S)Nr)rstdinr+rvr'rn)echochars r_getcharz%CliRunner.isolation.._getchars>99>>!$D   & JJ   Krc| S| Sr!rJ)rLcolor default_colors rshould_strip_ansiz.CliRunner.isolation..should_strip_ansis}(((9 rch|tj}|tj}|f|||d|y)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) completekeyrrv)r __stdin__ __stdout__)rrrrvr old_pdb_inits r_patched_pdb_initz.CliRunner.isolation.._patched_pdb_init s@:} ~  "-U6 MS rr!)rz str | Noner>r@)rrr>r@)NN)rLzt.IO[t.Any] | Noner bool | Noner>r)tabNN) rzpdb.Pdbrr@rt.IO[str] | NonervrrrAr>r?)"rrrrrvrwr FORCED_WIDTHrrurrrBinaryIOrr| _CHUNK_SIZErMrvisible_prompt_funchidden_prompt_funcrr rrpdbPdbritemsrXenvironget 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.isolations)D(t||<  II ZZ ZZ %22"$ mmC "} ??'(vv Ll6I6IJ( K*"5 $,,YS"   J ??&'J "(   \\   )   \\%    Z   !  Z  ( ! ( Z   !  EI & 6A   #)"<"<!'!:!:"OO % 7 7(/(A(A%ww'' %2"$0!""3$5! %&*'+ # # # $# % #   #   # J- ,!iik , U!zz~~c2 =JJsO',BJJsO , && (;(;\=P=PQ Q%mmo , U=JJsO',BJJsO ,$CJ#CJ!CI)@F &(>F %/FO&;E #(EG %&6J #+CGG /%% &mmo , U=JJsO$',BJJsO ,$CJ#CJ!CI)@F &(>F %/FO&;E #(EG %&6J #+CGG sI-R3:O.N3?;O:RO$BR3 O<O?OO O RORR,O>=R> P R P BRRc d}| |j}d} d} |jdk(r7td} td} | j| j|j |||5} | @| >| j tj_ | j tj_ d} d} d}t|trtj|} |jd} |j$d|xsd|d |} tjj7tjj7| N| L| j9}| j9}|r| dj3||r| dj3|| dj;}| dj;}| dj;} dddt=|  | S#t$rdx} } YwxYw#t $r|j#|}Y,wxYw#t&$r}tj(}t+j,d |j.}|d}|dk7r|} t|t0sItjj3t|tjj3d d}|}Yd}~d}~wt4$r&}|s|} d}tj(}Yd}~d}~wwxYw#tjj7tjj7| N| L| j9}| j9}|r| dj3||r| dj3|| dj;}| dj;}| dj;}wxYw#1swYxYw) 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_namerJ)argsrzint | t.Any | Nonerr)rrrOr^OSErrorrrQrrvrrwrr@shlexsplitpopKeyErrorrmain SystemExitrrrcoderDr'rrnrcgetvaluer)rrrrrrrextrarcap_outcap_err outstreamsrrrrre_codefd_outfd_errrvrwrs rinvokezCliRunner.invokeTsoj  ##44 &*%) <<4  mG mG )  ^^%S^ >> 2*"w':*1*:*: '*1*:*: 'L.2II$${{4( <!IIk2 * 2'sxxVTZR9VPUV 2   "   " &7+>$\\^F$\\^F"1 ++F3"1 ++F3#A//1#A//1#A//1}> 2@%  G )$((' )( < 66s;  <  #<<> 4aff=>FQ; !I!&#.JJ$$S[1JJ$$T*F"  *'  <<>  *   "   " &7+>$\\^F$\\^F"1 ++F3"1 ++F3#A//1#A//1#A//1}> 2> 2s G*/A.OG>0H CO* G;:G;>HOHO K:(BKK= K:K5/K=5K::K==COOOc#Ktj}tj|}tj| |tj||ddl} |j |yy#t$rYywxYw#tj||&ddl} |j |w#t$rYwwxYwwxYww)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)rXgetcwdrZmkdtempchdirshutilrmtreer)rtemp_dircwddtrs risolated_filesystemzCliRunner.isolated_filesystems iik   ( +   H HHSMMM"%   HHSMMM"%  sfACBC#A64C6 B?CBCC"B43C4 C=C?CCC)zutf-8NFTr) rr@r$cabc.Mapping[str, str | None] | Nonerrrrrrr>r?)rr r>r@r!)rr$r>r)NNF)r str | bytes | t.IO[t.Any] | Nonerr$rrr>z9cabc.Generator[tuple[io.BytesIO, io.BytesIO, io.BytesIO]])NNNNF)rr rzstr | cabc.Sequence[str] | Nonerr%rr$rrrrrrAr>r)r zstr | os.PathLike[str] | Noner>zcabc.Generator[str]) rFrGrHrerIrrr contextlibcontextmanagerrrr#rJrrrr=s"HL && 48 !%$ 2      ,"AE= &3748 C,/C,2C, C, C C,C,P152648(,O O .O 0 O 2 O & O O O  O b8<5 rr)rLzEchoingStdin | Noner>zcabc.Generator[None])rr%rr@r>r)/ __future__rcollections.abcabccabcr&ryrXrr rrZtypingrtypesrrrrrr r TYPE_CHECKING _typeshedr corer rLiteralrrItupler BaseExceptionrrr'rMrOrzrgru TextIOWrapperr|rrrrJrrr5s"" (??(<<7 yy/K/ yy5K5"4 #6 }#TU {U#!#!L ""J "** *77$4"**4n +69(S4S4lGGr