a c>@sddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddlmZejrddlmZGd d d Zejejeejdd d d ZGdddejZejejeeejfeejdddZ GdddZ!GdddZ"dS)N) TracebackType) formatting)termui)utils)_find_binary_reader) BaseCommandc@seZdZejejddddZeejdddZe e dd d Z de e d d dZ de e d ddZ de e d ddZeje dddZeje dddZedddZdS) EchoingStdinN)inputoutputreturncCs||_||_d|_dS)NF)_input_output_paused)selfr r rZ/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/click/testing.py__init__szEchoingStdin.__init__)xr cCs t|j|SN)getattrr )rrrrr __getattr__szEchoingStdin.__getattr__)rvr cCs|js|j||Sr)rrwrite)rrrrr_echos zEchoingStdin._echo)nr cCs||j|Sr)rr readrrrrrr#szEchoingStdin.readcCs||j|Sr)rr read1rrrrr&szEchoingStdin.read1cCs||j|Sr)rr readlinerrrrr )szEchoingStdin.readliner csfddjDS)Ncsg|]}|qSrr.0rrrr -z*EchoingStdin.readlines..)r readlinesr%rr%rr(,szEchoingStdin.readlinescstfddjDS)Nc3s|]}|VqdSrr"r#r%rr 0r'z(EchoingStdin.__iter__..)iterr r%rr%r__iter__/szEchoingStdin.__iter__cCs t|jSr)reprr r%rrr__repr__2szEchoingStdin.__repr__)r)r)r)__name__ __module__ __qualname__tBinaryIOrstrAnyrbytesrintrrr Listr(Iteratorr+r-rrrrr sr )streamr ccs&|durdVnd|_dVd|_dS)NTF)r)r9rrr _pause_echo6s r:csReZdZejeeejddfdd ZeedddZ eeddd Z Z S) _NamedTextIOWrapperN)buffernamemodekwargsr c s$tj|fi|||_||_dSr)superr_name_mode)rr<r=r>r? __class__rrrAsz_NamedTextIOWrapper.__init__r!cCs|jSr)rAr%rrrr=Hsz_NamedTextIOWrapper.namecCs|jSr)rBr%rrrr>Lsz_NamedTextIOWrapper.mode) r.r/r0r1r2r3r4rpropertyr=r> __classcell__rrrCrr;@s r;)r charsetr cCsdt|dr0tttj|}|dur(|Std|dur>d}nt|trR||}t tt |S)Nrz.Could not find binary reader for input stream.r') hasattrrr1castIO TypeError isinstancer3encodeioBytesIOr5)r rGrrrrmake_input_streamQs   rPc @seZdZdZddeejeejeeje ejej ej e e e fdddZ eeddd Zeedd d Zeedd d ZedddZdS)Resultz3Holds the captured result of an invoked CLI script.N CliRunnerrunner stdout_bytes stderr_bytes return_value exit_code exceptionexc_infocCs.||_||_||_||_||_||_||_dSrrS)rrTrUrVrWrXrYrZrrrrhs zResult.__init__r!cCs|jS)z(The (standard) output as unicode string.)stdoutr%rrrr sz Result.outputcCs|j|jjdddS)z&The standard output as unicode string.replace  )rUdecoderTrGr\r%rrrr[sz Result.stdoutcCs,|jdurtd|j|jjdddS)z%The standard error as unicode string.Nzstderr not separately capturedr\r]r^)rV ValueErrorr_rTrGr\r%rrrstderrs  z Result.stderrcCs,|jrt|jnd}dt|jd|dS)Nokay< >)rYr,typer.)rZexc_strrrrr-szResult.__repr__)N)r.r/r0__doc__r5r1Optionalr4r6 BaseExceptionTupleTyperrrEr3r r[rar-rrrrrQes(  rQc @sveZdZdZdeejejeejefeeddddZ d ed d d Z dejejeejefejeejefd ddZ e j dejejeeejfejejeejefeejejejejejfdddZdd ejejeejefejejeeejfejejeejefeeejedddZe j dejejeejfejedddZdS)rRaThe 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 utf-8NFT)rGenv echo_stdin mix_stderrr cCs ||_|p i|_||_||_dSr)rGrmrnro)rrGrmrnrorrrrs zCliRunner.__init__r)clir cCs |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=)rrprrrget_default_prog_nameszCliRunner.get_default_prog_name) overridesr cCst|j}|r|||S)z8Returns the environment overrides for invoking a script.)dictrmupdate)rrsrrrrmake_envs  zCliRunner.make_env)r rmcolorr c#st||j}d}tj}tj}tj}tj} dt_||}t } |j r^t t jt|| }}t||jdddt_|j rd_t| |jdddt_d} |jrtjt_nt } t| |jd dd d t_t|dt jttd fd d } t|dt jttd fdd } t|ttddd}|dt jt jt jttdfdd }tj}tj}tj}tj}| t_| t_|t_|t_i}z|D]R\}}tj !|||<|durz tj |=Wnt"yYn0n |tj |<q| | fVW|D]B\}}|dur.z tj |=Wnt"y*Yn0n |tj |<q|t_|t_|t_|t_|t_|t_|t_| t_n~|D]B\}}|durz tj |=Wnt"yYn0n |tj |<qv|t_|t_|t_|t_|t_|t_|t_| t_0dS)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)encodingr=r>rzwzbackslashreplace)rzr=r>errors)promptr cs>tj|p dd}tj|dtj|S)Nr]r^)sysr[rr rstripflush)r~val text_inputrr visible_inputs  z*CliRunner.isolation..visible_inputcs.tj|p ddtjdS)Nrr^r])rr[rrr r)r~rrr hidden_inputs z)CliRunner.isolation..hidden_input)echor cSs*tjd}|rtj|tj|S)Nr)rstdinrr[rr)rcharrrr_getchar#s    z%CliRunner.isolation.._getchar)r9rwr cs|dur S| Srr)r9rw) default_colorrrshould_strip_ansi/sz.CliRunner.isolation..should_strip_ansi)N)N)NN)#rPrGrrr[rarZ FORCED_WIDTHrvrNrOrnr1rIr2r r; _CHUNK_SIZEror:rhr3boolrJrZvisible_prompt_funcZhidden_prompt_funcrrritemsosenvironget Exception)rr rmrwZ bytes_inputZ echo_inputZ old_stdinZ old_stdoutZ old_stderrZold_forced_widthZ bytes_outputZ bytes_errorrrrrZold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold_envkeyvaluer)rrr isolations              zCliRunner.isolation)rpargsr rmcatch_exceptionsrwextrar c Ksd}|j|||d} d} d} d} t|tr8t|}z|d} Wntyb||} Yn0z&z|jf|pvd| d|} Wnt y}z|t }t t jt jtt jf|j}|durd}|dkr|} t|tst jt|t jdd}|} WYd}~nFd}~0tyX}z$|s4|} d} t }WYd}~n d}~00Wt j| d}|jrd}n | d}n2t j| d}|jrd}n | d}0Wdn1s0Yt|||| | | |d S) 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 rmrwr prog_namer)rrr^rrS)rrLr3shlexsplitpopKeyErrorrrmain SystemExitrrZr1rIrhUnionr6r4coder[rrrgetvaluerorQ)rrprr rmrrwrrZZ outstreamsrWrYrXreZe_coder[rarrrinvoke]sd,           .zCliRunner.invoke)temp_dirr ccst}tj|d}t|zFtt|VWt||durzt |Wqt ybYq0n6t||durzt |Wnt yYn00dS)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) rgetcwdtempfilemkdtempchdirr1rIr3shutilrmtreeOSError)rrcwddtrrrisolated_filesystems"      zCliRunner.isolated_filesystem)rlNFT)N)NNF)NNNTF)N)r.r/r0rgr3r1rhMappingrrrrrv contextlibcontextmanagerrr5rJr8rjrNrOrSequencer4rQrrPathLikerrrrrrRsd   erR)#rrNrrrrrtypingr1typesrrrrr_compatr TYPE_CHECKINGcorerr rrhr8r: TextIOWrapperr;rr3r5rJr2rPrQrRrrrrs.      "  :