Dd>ddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddlmZej"rddlmZGd d Zej*d ej,ed ej.dfd ZGddej2Zdej,ej6eeej<ej>fded ej@fdZ!GddZ"GddZ#y)N) TracebackType) formatting)termui)utils)_find_binary_reader) BaseCommandc eZdZdejdejddfdZdedejfdZde de fd Z dd e de fd Z dd e de fd Z dd e de fd Zdeje fdZdej"e fdZdefdZy) EchoingStdininputoutputreturnNc.||_||_d|_y)NF)_input_output_paused)selfr r s //usr/lib/python3/dist-packages/click/testing.py__init__zEchoingStdin.__init__s   xc.t|j|SN)getattrrrrs r __getattr__zEchoingStdin.__getattr__st{{A&&rrvcT|js|jj||Sr)rrwrite)rrs r_echozEchoingStdin._echos || LL  r " rncV|j|jj|Sr)r rreadrr!s rr#zEchoingStdin.read#s zz$++**1-..rcV|j|jj|Sr)r rread1r$s rr&zEchoingStdin.read1&s zz$++++A.//rcV|j|jj|Sr)r rreadliner$s rr(zEchoingStdin.readline)s zz$++..q122rcz|jjDcgc]}|j|c}Scc}wr)r readlinesr rs rr*zEchoingStdin.readlines,s+'+{{'<'<'>?! 1 ???s8c@tfdjDS)Nc3@K|]}j|ywr)r ).0rrs r z(EchoingStdin.__iter__..0s7aDJJqM7s)iterrrs`r__iter__zEchoingStdin.__iter__/s74;;777rc,t|jSr)reprrr0s r__repr__zEchoingStdin.__repr__2sDKK  r))__name__ __module__ __qualname__tBinaryIOrstrAnyrbytesr intr#r&r(Listr*Iteratorr1r4rrr r sajj!** 'S'QUU'% /c/5/0s0E03#3u3@166%=@8!**U+8!#!rr streamrc#>K|dyd|_dd|_yw)NTF)r)rBs r _pause_echorD6s ~  sc eZdZdejdededej ddf fd ZedefdZ edefd Z xZ S) _NamedTextIOWrapperbuffernamemodekwargsrNc Bt||fi|||_||_yr)superr_name_mode)rrGrHrIrJ __class__s rrz_NamedTextIOWrapper.__init__As% *6*  rc|jSr)rMr0s rrHz_NamedTextIOWrapper.nameH zzrc|jSr)rNr0s rrIz_NamedTextIOWrapper.modeLrQr) r6r7r8r9r:r;r<rpropertyrHrI __classcell__)rOs@rrFrF@snjj(+36BC%% ccrrFr charsetc*t|drMttjtjtj |}||St d|d}n!t|tr|j|}tj|S)Nr#z.Could not find binary reader for input stream.r) hasattrrr9castIOr< TypeError isinstancer;encodeioBytesIO)r rUrs rmake_input_streamr_Qsvuf QUU U!; < >IHII } E3  W% ::e rc"eZdZdZ ddddedej edejded ej e d ej ejeje e e ffd Z ed efd Zed efdZed efdZd efdZy)Resultz3Holds the captured result of an invoked CLI script.Nrunner CliRunner stdout_bytes stderr_bytes return_value exit_code exceptionexc_infocf||_||_||_||_||_||_||_yrrbrdrerfrgrhri)rrbrdrerfrgrhris rrzResult.__init__hs: (()""  rrc|jS)z(The (standard) output as unicode string.)stdoutr0s rr z Result.outputs{{rc|jj|jjdj ddS)z&The standard output as unicode string.replace  )rddecoderbrUror0s rrmz Result.stdouts9  '' (;(;YGOO D  rc|j td|jj|jjdj ddS)z%The standard error as unicode string.zstderr not separately capturedrorprq)re ValueErrorrrrbrUror0s rstderrz Result.stderrsQ    $=> >  '' (;(;YGOO D  rc|jrt|jnd}dt|jd|dS)Nokay< >)rhr3typer6)rexc_strs rr4zResult.__repr__s8*...$t~~&f4:&&'q 33rr)r6r7r8__doc__r=r9Optionalr<r> BaseExceptionTupleTyperrrSr;r rmrur4rArrraraes= !!!jj' ! ee !  !::m,!** GGAFF=)=-G H !:      4#4rraceZdZdZ ddedej ejeej efdededdf dZ d d defd Z dd ej ejeej efdejeej effd Z e j ddej ejeeej ej"fdej ejeej efdedej$ej&ej*ej ej*ffdZ dd d dej ejeej.efdej ejeeej ej"fdej ejeej efdededej"defdZe j ddej ejedfdej$efdZy)rcaThe 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 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 NrUenv echo_stdin mix_stderrrcD||_|xsi|_||_||_yr)rUrrr)rrUrrrs rrzCliRunner.__init__s$ 47I2$$rclir c"|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)rH)rrs rget_default_prog_namezCliRunner.get_default_prog_names xx!6!r overridescVt|j}|r|j||S)z8Returns the environment overrides for invoking a script.)dictrupdate)rrrs rmake_envzCliRunner.make_envs%$((^  IIi  rr colorc#0 Kt||j}d}tj}tj}tj }t j} dt _|j|}tj} |jr0tjtjt|| x}}t!||jddxt_|jrd_t!| |jddt_d} |j$rtjt_n7tj} t!| |jd dd t_t'|dd tj(t*d t*ffd } t'|dd tj(t*d t*ffd } t'|dt,d t*fd}| ddtj(tj.tj0dtj(t,d t,ffd }t2j4}t2j6}t2j8}t:j<}| t2_| t2_|t2_|t:_i} |j?D]O\}}t@jBjE|||<| t@jB|==|t@jB|<Q| | f|j?D]-\}}| t@jB|=|t@jB|</|t_|t_|t_|t2_|t2_|t2_|t:_| t _y#tF$rYwxYw#tF$rYwxYw#|j?D]<\}}|" t@jB|=#tF$rY&wxYw|t@jB|<>|t_|t_|t_|t2_|t2_|t2_|t:_| t _wxYww)anA 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. .. versionchanged:: 8.0 ``stderr`` is opened with ``errors="backslashreplace"`` instead of the default ``"strict"``. .. versionchanged:: 4.0 Added the ``color`` parameter. NPzr)encodingrHrIrzwzbackslashreplace)rrHrIerrorspromptrc tjj|xsdjj d}tjj|dtjj |S)Nrprq)sysrmrr(rstripflush)rval text_inputs r visible_inputz*CliRunner.isolation..visible_inputs_ JJ  V\r *%%'..v6C JJ  uBZ ( JJ   Jrctjj|xsddtjjj j dS)Nrrqrp)rrmrrr(r)rrs r hidden_inputz)CliRunner.isolation..hidden_inputsJ JJ   "~R0 1 JJ   &&(//7 7rechoctjjd}|rtjj |tjj |S)Nr)rstdinr#rmrr)rchars r_getcharz%CliRunner.isolation.._getchar#s>99>>!$D   & JJ   KrrBrc| S| SrrA)rBr default_colors rshould_strip_ansiz.CliRunner.isolation..should_strip_ansi/s}(((9 rr)NN)$r_rUrrrmrur FORCED_WIDTHrr]r^rr9rXr:r rF _CHUNK_SIZErrDr~r;boolrYr<rvisible_prompt_funchidden_prompt_funcrrritemsosenvironget Exception)rr rr bytes_input echo_input old_stdin old_stdout old_stderrold_forced_width bytes_output bytes_errorrrrrold_visible_prompt_funcold_hidden_prompt_funcold__getchar_funcold_should_strip_ansiold_envkeyvaluerrs @@r isolationzCliRunner.isolations6(t||<  II ZZ ZZ %22"$ mmC zz| ??'(vv LlC( K*"5 $,,YS"   J ??&'J "( 4<F %/FO&;E #&6J #+%% &mmo , U=JJsO$',BJJsO ,$CJ#CJ!CI)@F &(>F %/FO&;E #&6J #sKR :O*O O*3R OA/R OO*OO* O'$R&O''R*RPR P" R!P" "A1RRargscatch_exceptionsextrac d}|j|||5} d} d} d} t|trtj|} |j d} |jd|xsd| d|} tj&j-| dj/}|j0rd}n| dj/} dddt3|   | S#t $r|j|} YwxYw#t$r}tj}tjtjtjt tj"f|j$}|d}|dk7r|} t|t sItj&j)t|tj&j)dd}|} Yd}~md}~wt*$r&}|s|} d} tj}Yd}~d}~wwxYw#tj&j-| dj/}|j0rd}w| dj/}wxYw#1swYxYw) aInvokes 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``. :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. .. 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 rrr prog_namerA)rrrqrrk)rr[r;shlexsplitpopKeyErrorrmain SystemExitrrir9rXr~Unionr>r<codermrrrgetvaluerra)rrrr rrrrri outstreamsrfrhrgree_codermrus rinvokezCliRunner.invoke]sX ^^%S^ >, 6*L37II$${{4( <!IIk2  6'sxxVTZR9VPUV 2   "#A//1??!F']335FY, 6\%  I < 66s;  <  #<<> 1773:+> ?H>FQ; !I!&#.JJ$$S[1JJ$$T*F"  *'  <<>  *   "#A//1??!F']335FY, 6, 6st,I)CC=/AI)C:7I)9C::I)= HCGH H(H H HHAI&&I))I3temp_dirzos.PathLike[str]c#Ktj}tj|}tj| |tj|| t j |yy#t$rYywxYw#tj||& t 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. )dirN)rgetcwdtempfilemkdtempchdirshutilrmtreeOSError)rrcwddts risolated_filesystemzCliRunner.isolated_filesystems iik   ( +   H HHSMMM"%  HHSMMM"% sfACBCA64C6 B?CBCCB43C4 C=C?CCC)zutf-8NFTr)NNF)NNNTF)r6r7r8r}r;r9r~Mappingrrrr contextlibcontextmanagerrr=rYr<r@rr]r^rSequencerarrrArrrcrcs(;?  % %ZZ #qzz#"67 8 % %  %  %""3"HLAIIc1::c?.B$CD 3 3' (?C;? L7zz!''#uadd155k"9:;L7ZZ #qzz#"67 8L7 L7 AGGBJJ 2::(>>? @ L7L7b;?>B;?!%c c jjajjo!567c zz!''#uadd155k"9:; c ZZ #qzz#"67 8 c  c c c  c JGK 17730B+B#CD Crrc)$rr]rrrrrtypingr9typesrrrrr_compatr TYPE_CHECKINGcorer r rr~r@rD TextIOWrapperrFrr;r=rYr<r:r_rarcrArrrs (??!!!D  <0QZZ5E"**" ::aggc5!$$quu+56 7BEZZ(7474t@@r