;iJddlmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl mZddlmZddlmZddlmZddlmZdd lmZe jr dd lmZdd lmZGd d Zejd#dZGddejZGddZGddej Z!d$dZ"Gdd Z#Gd!d"Z$dS)%) annotationsN) TracebackType)_compat) formatting)termui)utils)_find_binary_reader)ReadableBuffer)Commandc\eZdZddZdd Zdd ZdddZdddZdddZddZ d dZ d!dZ dS)" EchoingStdininput t.BinaryIOoutputreturnNonec0||_||_d|_dS)NF)_input_output_paused)selfrrs AC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\click/testing.py__init__zEchoingStdin.__init__s   xstrt.Anyc,t|j|SN)getattrr)rrs r __getattr__zEchoingStdin.__getattr__st{A&&&rrvbytescH|js|j||Sr )rrwrite)rr#s r_echozEchoingStdin._echo"s'| # L  r " " " rnintc\||j|Sr )r'rreadrr)s rr,zEchoingStdin.read(s$zz$+**1--...rc\||j|Sr )r'rread1r-s rr/zEchoingStdin.read1+s$zz$+++A..///rc\||j|Sr )r'rreadliner-s rr1zEchoingStdin.readline.s$zz$+..q11222r list[bytes]cNfdjDS)Nc:g|]}|Sr'.0rrs r z*EchoingStdin.readlines..2s#???! 1 ???r)r readlinesrs`rr:zEchoingStdin.readlines1s+????t{'<'<'>'>????rcabc.Iterator[bytes]cDtfdjDS)Nc3BK|]}|VdSr r6r7s r z(EchoingStdin.__iter__..5s-77aDJJqMM777777r)iterrr;s`r__iter__zEchoingStdin.__iter__4s(77774;777777rc*t|jSr )reprrr;s r__repr__zEchoingStdin.__repr__7sDK   rN)rrrrrr)rrrr)r#r$rr$)r()r)r*rr$)rr2)rr<rr) __name__ __module__ __qualname__rr"r'r,r/r1r:rArDr5rrrrs '''' /////0000033333@@@@8888!!!!!!rrstreamEchoingStdin | Nonercabc.Iterator[None]c#>K|dVdSd|_dVd|_dS)NTF)r)rIs r _pause_echorM;s3 ~  rc<eZdZdZd fd Zd fd Zdfd ZxZS) BytesIOCopyzdPatch ``io.BytesIO`` to let the written stream be copied to another. .. versionadded:: 8.2 copy_to io.BytesIOrrcVt||_dSr )superrrP)rrP __class__s rrzBytesIOCopy.__init__Ks$  rczt|jdSr )rSflushrP)rrTs rrVzBytesIOCopy.flushOs.   rbr r*cz|j|t|Sr )rPr&rS)rrWrTs rr&zBytesIOCopy.writeSs/ 1ww}}Qr)rPrQrrrr)rWr rr*)rFrGrH__doc__rrVr& __classcell__rTs@rrOrOEs           rrOc"eZdZdZddZddZdS) StreamMixerzMixes `` and `` streams. The result is available in the ``output`` attribute. .. versionadded:: 8.2 rrctj|_t|j|_t|j|_dS)N)rP)ioBytesIOrrOstdoutstderrr;s rrzStreamMixer.__init__`s;"$*,, "-dk"B"B"B "-dk"B"B"B rc|j|j|jdS)z Guarantee that embedded file-like objects are closed in a predictable order, protecting against races between self.output being closed and other streams being flushed on close .. versionadded:: 8.2.2 N)rccloserbrr;s r__del__zStreamMixer.__del__esF   rNrY)rFrGrHrZrrfr5rrr^r^XsJCCCC      rr^cPeZdZd fd Zedd Zedd ZxZS)_NamedTextIOWrapperbufferrnamermodekwargsrrrc Xtj|fi|||_||_dSr )rSr_name_mode)rrirjrkrlrTs rrz_NamedTextIOWrapper.__init__ss6 **6***  rc|jSr )rnr;s rrjz_NamedTextIOWrapper.namez zrc|jSr )ror;s rrkz_NamedTextIOWrapper.mode~rqr) rirrjrrkrrlrrrrE)rFrGrHrpropertyrjrkr[r\s@rrhrhrs}XXrrhr str | bytes | t.IO[t.Any] | Nonecharsetrrct|dr5ttjd|}||St d|d}n*t |t r||}tj |S)Nr,z t.IO[t.Any]z.Could not find binary reader for input stream.r) hasattrr tcast TypeError isinstancerencoder`ra)rrur#s rmake_input_streamr}sufJ  u!=!= > > >IHIII } E3  & W%% :e  rcneZdZdZ dddZeddZeddZeddZddZ 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``. Nrunner CliRunner stdout_bytesr$ stderr_bytes output_bytes return_valuer exit_coder* exceptionBaseException | Noneexc_info?tuple[type[BaseException], BaseException, TracebackType] | Nonec v||_||_||_||_||_||_||_||_dSr rrrrrrrr) rrrrrrrrrs rrzResult.__init__sD ((((""  rrrct|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  )rdecoderrurr;s rrz Result.outputs9 '' (;YGGOO D   rct|j|jjdddS)z&The standard output as unicode string.rrr)rrrrurr;s rrbz Result.stdouts9 '' (;YGGOO D   rct|j|jjdddS)zThe standard error as unicode string. .. versionchanged:: 8.2 No longer raise an exception, always returns the `` string. rrr)rrrrurr;s rrcz Result.stderrs9 '' (;YGGOO D   rcr|jrt|jnd}dt|jd|dS)Nokay< >)rrCtyperF)rexc_strs rrDzResult.__repr__s?*..D$t~&&&f34::&333333rr )rrrr$rr$rr$rrrr*rrrrrE) rFrGrHrZrrsrrbrcrDr5rrrrs>!!!!!*    X     X    X 444444rrceZdZdZ d&d'dZd(dZ d)d*dZej d+d,dZ d-d.d!Z ej d)d/d%Z dS)0raThe 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`. .. versionchanged:: 8.2 Added the ``catch_exceptions`` parameter. .. versionchanged:: 8.2 ``mix_stderr`` parameter has been removed. utf-8NFTrurenv$cabc.Mapping[str, str | None] | None echo_stdinboolcatch_exceptionsrrcB||_|pi|_||_||_dSr )rurrr)rrurrrs rrzCliRunner.__init__s+ 25)$ 0rclir 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)rj)rrs rget_default_prog_namezCliRunner.get_default_prog_names x!6!r overridescabc.Mapping[str, str | None]c\t|j}|r|||S)z8Returns the environment overrides for invoking a script.)dictrupdate)rrr#s rmake_envzCliRunner.make_envs0$(^^  ! IIi  rrrtcolor8cabc.Iterator[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#|ddfd } t#|ddfd } t#|dd} | ddfd }t$j}t$j}t$j}t,j}t0j}| t$_| t$_| t$_|t,_|t0_i} |D]W\}}t4j|||<| t4j|=8#t:$rYDwxYw|t4j|<X| j| j| jfV|D]5\}}| t4j|=#t:$rY"wxYw|t4j|<6|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _dS#|D]5\}}| t4j|=#t:$rY"wxYw|t4j|<6|t_|t_|t_|t$_|t$_|t$_|t,_|t0_| t _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)encodingrjrkrzwzbackslashreplace)rrjrkerrorsprompt str | NonerrcTtj|pd td}n!#t $r}t |d}~wwxYwtj|dtj|S)Nrr)sysrbr&nextrstrip StopIterationEOFErrorrV)rvale text_inputs r visible_inputz*CliRunner.isolation..visible_input`s J  V\r * * * (:&&--f55  ( ( (jja' ( J  ZZZ ( ( ( J     Js"A A%A  A%ctj|pddtj t dS#t $r}t|d}~wwxYw)Nrrr)rrbr&rVrrrr)rrrs r hidden_inputz)CliRunner.isolation..hidden_inputks J   "000 1 1 1 J      (J''..v666  ( ( (jja' (s!A'' B1BBechorctjd}|rtj|tj|S)Nr)rstdinr,rbr&rV)rchars r_getcharz%CliRunner.isolation.._getchartsL9>>!$$D '   &&& J     KrrIt.IO[t.Any] | Noner bool | Nonec| S| Sr r5)rIr default_colors rshould_strip_ansiz.CliRunner.isolation..should_strip_ansis}(((9 rr )rrrr)rrrr)NN)rIrrrrr)r}rurrrbrcr FORCED_WIDTHrr^rrxryBinaryIOrrh _CHUNK_SIZErMrvisible_prompt_funchidden_prompt_funcrr rritemsosenvironget 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_ansiold_envkeyvaluerrs @@r isolationzCliRunner.isolations=D(t|<<  I Z Z %2"$ mmC  "}} ? '(v Ll6IJJ(( K*"5 $,YS" " "   J ? '&'J "(  $,Zc    )  \%      Z        !   Z  ( ( ( ( ( ( !  ( Z     !   EI       #)"<!'!:"O % 7(/(A%%2"$0!""3$5! 7!iikk , , U!z~~c22 =JsOO$',BJsOO& (;\=PQ 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 IM I&#M%I&&)M+ J99 KKO?$ M21O?2 M? <O?>M? ?BO?argsstr | cabc.Sequence[str] | Nonerextrarrc d}||j}||||5} d} d} d} t|trt j|} |d} n%#t$r||} YnwxYw |j d|pd| d|} n#t$r}tj }tjd|j}|d}|dkr|} t|t sMtjt|tjdd }|} Yd}~n4d}~wt&$r$}|s|} d } tj }Yd}~nd}~wwxYwtjtj| d}| d }| d }n#tjtj| 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. N)rrrr prog_namer5)rrzint | t.Any | Nonerrr)rrr{rshlexsplitpopKeyErrorrmain SystemExitrrrxrycoder*rbr&rrVrcgetvaluer)rrrrrrrrr outstreamsrrrrre_coderbrcrs rinvokezCliRunner.invokes+j  ##4  ^^%S^ > >+ 2*L.2II$$$ ){4(( <!IIk22  < < < 66s;;  < 2'sxVTZR9VVPUVV  # # #<>> 4af==>FQ;; !I!&#..J$$S[[111J$$T***F"  * * *'  <>>  *   """   """#A//11#A//11#A//11    """   """#A//11#A//11#A//111111W+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+ 2Z%    s0J+A+*J++B  J+ B  J+B$#H$ F.BE H FE<7H<FHB J+B JJ++J/2J/temp_dirstr | os.PathLike[str] | Nonecabc.Iterator[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)rgetcwdtempfilemkdtempchdirshutilrmtreeOSError)rrcwddtrs risolated_filesystemzCliRunner.isolated_filesystem"s ikk  ( + + +   HHH HSMMM MM"%%%%%DD   HSMMM MM"%%%%D  sBB A66 BB C %B;:C ; CC CC )rNFT) rurrrrrrrrr)rr rrr )rrrr)NNF)rrtrrrrrr)NNNNF)rr rrrrtrrrrrrrrrr)rrrr) rFrGrHrZrrr contextlibcontextmanagerrrrr5rrrrs.48 !% 1 1 1 1 1""""AE3748 W7W7W7W7W7x152648(,o o o o o b8<rr)rIrJrrK)rrtrurrr)% __future__rcollections.abcabccabcr r`rrrrtypingrxtypesrrrrrr r TYPE_CHECKING _typeshedr corer rr rMrarOr^ TextIOWrapperrhr}rrr5rrrsW"""""" ((((((?((((((!!!!!!!!D      "*   &4"*"(K4K4K4K4K4K4K4K4\\\\\\\\\\\r