
     f>                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ej        rddlmZ  G d	 d
          Ze j        dej        e         dej        d         fd            Z G d dej                  Zdej        ej        eeej        ej                 f                  dedej         fdZ! G d d          Z" G d d          Z#dS )    N)TracebackType   )
formatting)termui)utils)_find_binary_reader)BaseCommandc                       e Zd Zdej        dej        ddfdZdedej        fdZde	de	fd	Z
ddede	fdZddede	fdZddede	fdZdej        e	         fdZdej        e	         fdZdefdZdS )EchoingStdininputoutputreturnNc                 0    || _         || _        d| _        d S )NF)_input_output_paused)selfr   r   s      P/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/click/testing.py__init__zEchoingStdin.__init__   s        xc                 ,    t          | j        |          S N)getattrr   )r   r   s     r   __getattr__zEchoingStdin.__getattr__   s    t{A&&&r   rvc                 H    | j         s| j                            |           |S r   )r   r   write)r   r   s     r   _echozEchoingStdin._echo   s'    | 	#Lr"""	r   nc                 \    |                      | j                            |                    S r   )r   r   readr   r!   s     r   r#   zEchoingStdin.read#   s$    zz$+**1--...r   c                 \    |                      | j                            |                    S r   )r   r   read1r$   s     r   r&   zEchoingStdin.read1&   s$    zz$+++A..///r   c                 \    |                      | j                            |                    S r   )r   r   readliner$   s     r   r(   zEchoingStdin.readline)   s$    zz$+..q11222r   c                 N      fd j                                         D             S )Nc                 :    g | ]}                     |          S  r   .0r   r   s     r   
<listcomp>z*EchoingStdin.readlines.<locals>.<listcomp>-   s#    ???!

1???r   )r   	readlinesr   s   `r   r0   zEchoingStdin.readlines,   s+    ????t{'<'<'>'>????r   c                 D     t           fd j        D                       S )Nc              3   B   K   | ]}                     |          V  d S r   r,   r-   s     r   	<genexpr>z(EchoingStdin.__iter__.<locals>.<genexpr>0   s-      77aDJJqMM777777r   )iterr   r1   s   `r   __iter__zEchoingStdin.__iter__/   s(    77774;777777r   c                 *    t          | j                  S r   )reprr   r1   s    r   __repr__zEchoingStdin.__repr__2   s    DK   r   )r    )__name__
__module____qualname__tBinaryIOr   strAnyr   bytesr   intr#   r&   r(   Listr0   Iteratorr6   r9   r+   r   r   r   r      s_       aj !*     
'S 'QU ' ' ' ' %    / /c /5 / / / /0 0s 0E 0 0 0 03 3# 3u 3 3 3 3@16%= @ @ @ @8!*U+ 8 8 8 8!# ! ! ! ! ! !r   r   streamr   c              #   >   K   | d V  d S d| _         d V  d| _         d S )NTF)r   )rE   s    r   _pause_echorG   6   s3      ~r   c            
            e Zd Zdej        dededej        ddf
 fdZedefd            Z	edefd	            Z
 xZS )
_NamedTextIOWrapperbuffernamemodekwargsr   Nc                 X     t                      j        |fi | || _        || _        d S r   )superr   _name_mode)r   rJ   rK   rL   rM   	__class__s        r   r   z_NamedTextIOWrapper.__init__A   s6     	**6***



r   c                     | j         S r   )rP   r1   s    r   rK   z_NamedTextIOWrapper.nameH   
    zr   c                     | j         S r   )rQ   r1   s    r   rL   z_NamedTextIOWrapper.modeL   rT   r   )r:   r;   r<   r=   r>   r?   r@   r   propertyrK   rL   __classcell__)rR   s   @r   rI   rI   @   s        j(+36BC%	      c    X c    X    r   rI   r   charsetc                 F   t          | d          rOt          t          j        t          j        t          j                 |                     }||S t          d          | d} n*t          | t                    r| 	                    |          } t          j        |           S )Nr#   z.Could not find binary reader for input stream.r   )hasattrr   r=   castIOr@   	TypeError
isinstancer?   encodeioBytesIO)r   rX   r   s      r   make_input_streamrb   Q   s     uf J QUU!;!;<<>IHIII}	E3		 &W%%:er   c                      e Zd ZdZ	 ddddedej        e         dej        ded	ej        e	         d
ej        ej
        ej        e	         e	ef                  fdZedefd            Zedefd            Zedefd            ZdefdZdS )Resultz3Holds the captured result of an invoked CLI script.Nrunner	CliRunnerstdout_bytesstderr_bytesreturn_value	exit_code	exceptionexc_infoc                 h    || _         || _        || _        || _        || _        || _        || _        d S r   re   rg   rh   ri   rj   rk   rl   )r   re   rg   rh   ri   rj   rk   rl   s           r   r   zResult.__init__h   s>     (( )"" r   r   c                     | j         S )z(The (standard) output as unicode string.)stdoutr1   s    r   r   zResult.output   s     {r   c                 t    | j                             | j        j        d                              dd          S )z&The standard output as unicode string.replace

)rg   decodere   rX   rr   r1   s    r   rp   zResult.stdout   s9      ''(;YGGOOD
 
 	
r   c                     | j         t          d          | j                             | j        j        d                              dd          S )z%The standard error as unicode string.Nzstderr not separately capturedrr   rs   rt   )rh   
ValueErrorru   re   rX   rr   r1   s    r   stderrzResult.stderr   sQ     $=>>> ''(;YGGOOD
 
 	
r   c                 r    | j         rt          | j                   nd}dt          |           j         d| dS )Nokay< >)rk   r8   typer:   )r   exc_strs     r   r9   zResult.__repr__   s?    *..D$t~&&&f34::&333333r   r   )r:   r;   r<   __doc__rA   r=   Optionalr@   rB   BaseExceptionTupleTyper   r   rV   r?   r   rp   rx   r9   r+   r   r   rd   rd   e   s;       == ! !! ! j'	!
 e! ! :m,! *GAF=)=-GH
! ! ! !:     X 
 
 
 
 X
 
 
 
 
 X
4# 4 4 4 4 4 4r   rd   c                      e Zd ZdZ	 	 	 	 ddedej        ej        eej        e         f                  ded	ed
df
dZ	ddd
efdZ
	 ddej        ej        eej        e         f                  d
ej        eej        e         f         fdZej        	 	 	 ddej        ej        eeej        ej                 f                  dej        ej        eej        e         f                  ded
ej        ej        ej        ej        ej                 f                  fd            Z	 	 	 	 	 ddddej        ej        eej        e         f                  dej        ej        eeej        ej                 f                  dej        ej        eej        e         f                  dededej        d
efdZej        	 ddej        ej        edf                  d
ej        e         fd            ZdS )rf   a  The 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-8NFTrX   env
echo_stdin
mix_stderrr   c                 B    || _         |pi | _        || _        || _        d S r   )rX   r   r   r   )r   rX   r   r   r   s        r   r   zCliRunner.__init__   s(     47I2$$r   clir	   c                     |j         pdS )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)rK   )r   r   s     r   get_default_prog_namezCliRunner.get_default_prog_name   s    
 x!6!r   	overridesc                 \    t          | j                  }|r|                    |           |S )z8Returns the environment overrides for invoking a script.)dictr   update)r   r   r   s      r   make_envzCliRunner.make_env   s0     $(^^ 	!IIi   	r   r   colorc              #     K   t          || j                  }d}t          j        }t          j        }t          j        }t          j        }	dt          _        |                     |          }t          j
                    }
| j        r/t          j        t          j        t          ||
                    x}}t!          || j        dd          xt          _        | j        rd_        t!          |
| j        dd          t          _        d}| j        rt          j        t          _        n6t          j
                    }t!          || j        d	dd
          t          _        t'          |          ddt          j        t*                   dt*          ffd            }t'          |          ddt          j        t*                   dt*          ffd            }t'          |          dt,          dt*          fd            }|	 ddt          j        t          j        t          j                          dt          j        t,                   dt,          ffd}t2          j        }t2          j        }t2          j        }t:          j        }|t2          _        |t2          _        |t2          _        |t:          _        i }	 |                                D ]W\  }}t@          j!        "                    |          ||<   |	 t@          j!        |= 8# tF          $ r Y Dw xY w|t@          j!        |<   X|
|fV  |                                D ]5\  }}|	 t@          j!        |= # tF          $ r Y "w xY w|t@          j!        |<   6|t          _        |t          _        |t          _        |t2          _        |t2          _        |t2          _        |t:          _        |	t          _        dS # |                                D ]5\  }}|	 t@          j!        |= # tF          $ r Y "w xY w|t@          j!        |<   6|t          _        |t          _        |t          _        |t2          _        |t2          _        |t2          _        |t:          _        |	t          _        w xY w)an  A 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.
        NP   z<stdin>r)encodingrK   rL   r   z<stdout>wz<stderr>backslashreplace)r   rK   rL   errorspromptr   c                    t           j                            | pd                                                               d          }t           j                            | d           t           j                                         |S )N rs   rt   )sysrp   r   r(   rstripflush)r   val
text_inputs     r   visible_inputz*CliRunner.isolation.<locals>.visible_input  sq    JV\r***%%''..v66CJZZZ(((JJr   c                     t           j                            | pd d           t           j                                                                                             d          S )Nr   rt   rs   )r   rp   r   r   r(   r   )r   r   s    r   hidden_inputz)CliRunner.isolation.<locals>.hidden_input  sZ    J"000111J&&((//777r   echoc                     t           j                            d          }| rt           j                            |           t           j                                         |S )Nr   )r   stdinr#   rp   r   r   )r   chars     r   _getcharz%CliRunner.isolation.<locals>._getchar#  sL    9>>!$$D '
  &&&JKr   rE   r   c                     | S | S r   r+   )rE   r   default_colors     r   should_strip_ansiz.CliRunner.isolation.<locals>.should_strip_ansi/  s     }(((9r   r   )NN)$rb   rX   r   r   rp   rx   r   FORCED_WIDTHr   r`   ra   r   r=   r[   r>   r   rI   _CHUNK_SIZEr   rG   r   r?   boolr\   r@   r   visible_prompt_funchidden_prompt_funcr   r   r   itemsosenvironget	Exception)r   r   r   r   bytes_input
echo_input	old_stdin
old_stdout
old_stderrold_forced_widthbytes_outputbytes_errorr   r   r   r   old_visible_prompt_funcold_hidden_prompt_funcold__getchar_funcold_should_strip_ansiold_envkeyvaluer   r   s                          @@r   	isolationzCliRunner.isolation   s     6 (t|<<
I	Z
Z
%2"$
mmC  z||? 	'(v
LlCC( ( K* "5$,YS"
 "
 "
 	
	J ? 	' &'J"(4<js
 
 

 ? 
	CJJ*,,K,)  CJ 
Z	 	 	 	!*S/ 	S 	 	 	 	 	 
!	 	 
Z	 	 	8 	8C 	8C 	8 	8 	8 	8 	8 
!	 	8
 
Z	 	 	4 	C 	 	 	 
!	 	  OS	 	JqtAE{+	;<:d;K		 	 	 	 	 	 #)"<!'!:"O % 7%2"$0!""3	7!iikk , ,
U!z~~c22=JsOO$    ',BJsOO----%mmoo , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#&6J### &mmoo , ,
U=JsOO$    ',BJsOO#CJ#CJ!CI)@F&(>F%/FO&;E#&6J#6666sg   2=O 0K>=O >
LO 
LO  M
MMQ<-O;:Q<;
P	Q<P	A4Q<argscatch_exceptionsextrac           	      0   d}|                      |||          5 }	d}
d}d}t          |t                    rt          j        |          }	 |                    d          }n%# t          $ r |                     |          }Y nw xY w	  |j        d|pd|d|}
n# t          $ r}t          j                    }t          j        t          j        t          j        t           t          j        f                  |j                  }|d}|dk    r|}t          |t                     sMt          j                            t          |                     t          j                            d           d}|}Y d}~n4d}~wt*          $ r$}|s |}d}t          j                    }Y d}~nd}~ww xY wt          j                                         |	d                                         }| j        rd}n||	d                                         }na# t          j                                         |	d                                         }| j        rd}n|	d                                         }w xY wddd           n# 1 swxY w Y   t3          | |||
|||	          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``.
        :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   r   r   r   	prog_namer+   )r   r   rt   r   rn   )r   r^   r?   shlexsplitpopKeyErrorr   main
SystemExitr   rl   r=   r[   r   UnionrB   r@   coderp   r   r   r   getvaluer   rd   )r   r   r   r   r   r   r   r   rl   
outstreamsri   rk   rj   r   ee_coderp   rx   s                     r   invokezCliRunner.invoke]  s   X ^^%S^>> ,	6*L37II$$$ ){4((<!IIk22		 < < < 66s;;			<6'sxVTZR9VVPUVV # # #<>>
173:+> ?HH>FQ;; !I!&#.. J$$S[[111J$$T***F"						 * * *' 		<>>* 
  """#A//11? 6!FF']3355FF 
  """#A//11? 6!FF']3355F5555Y,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6 ,	6\ %
 
 
 	
s   0I7A"!I7"BI7BI7BH

F*&CE94H
9F*F% H
%F**H
-AI7
AI((I77I;>I;temp_dirzos.PathLike[str]c              #     K   t          j                    }t          j        |          }t          j        |           	 |V  t          j        |           |(	 t          j        |           dS # t          $ r Y dS w xY wdS # t          j        |           |&	 t          j        |           w # t          $ r Y w w xY ww xY w)a  A 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)r   getcwdtempfilemkdtempchdirshutilrmtreeOSError)r   r   cwddts       r   isolated_filesystemzCliRunner.isolated_filesystem  s        ikk(+++
		HHHHSMMMM"%%%%%   DD   HSMMMM"%%%%   D  sB    B A1 1
A?>A?CB10C1
B>;C=B>>C)r   NFTr   )NNF)NNNTF)r:   r;   r<   r   r?   r=   r   Mappingr   r   r   r   
contextlibcontextmanagerr   rA   r\   r@   rD   r   r`   ra   r   Sequencerd   r   r   r+   r   r   rf   rf      s        ( ;? 
% 
%
% Z	#qz#"678
% 	
%
 
% 

% 
% 
% 
%" "3 " " " " HL AIc1:c?.B$CD	
3
3'	(     ?C;?	L7 L7z!'#uad15k"9:;L7 Z	#qz#"678L7 	L7
 
AGBJ
2:(>>?	@L7 L7 L7 L7b ;?>B;?!%c
 c
c
 jajo!567c
 z!'#uad15k"9:;	c

 Z	#qz#"678c
 c
 c
 c
 
c
 c
 c
 c
J GK 
1730B+B#CD	
C     r   rf   )$r   r`   r   r   r   r   r   typingr=   typesr   r   r   r   r   _compatr   TYPE_CHECKINGcorer	   r   r   r   rD   rG   TextIOWrapperrI   r   r?   rA   r\   r@   r>   rb   rd   rf   r+   r   r   <module>r      s       				 				   



                              ( ( ( ( ( (? "!!!!!!! ! ! ! ! ! ! !D 
<0 QZ5E        "*   ":agc5!$qu+567BEZ   (74 74 74 74 74 74 74 74t@ @ @ @ @ @ @ @ @ @r   