o
    c#                     @   s  d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZ d dlmZ erNd dlmZ e	eeef  Zd	eeeef d
efddZd	ee	e ef d
efddZd	ee	e ef d
e	e fddZ									d&dee	e ef dedee dddeee   dee
eef  deee  dee dee dee ded
efd d!Z!d"ed
ed# fd$d%Z"dS )'    N)TYPE_CHECKINGAnyCallableIterableListMappingOptionalUnion)escape)SpinnerInterfaceopen_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger)
HiddenText)Literalargsreturnc                  G   s2   g }| D ]}t |tr|| q|| q|S )z&
    Create a CommandArgs object.
    )
isinstancelistextendappend)r   command_argsarg r   K/opt/certbot/lib/python3.10/site-packages/pip/_internal/utils/subprocess.pymake_command    s   
r   c                 C   s   d dd | D S )z/
    Format command arguments for display.
     c                 s   s2    | ]}t |trtt|nt|V  qd S )N)r   r   shlexquotestr.0r   r   r   r   	<genexpr>:   s
     
z&format_command_args.<locals>.<genexpr>)joinr   r   r   r   format_command_args1   s   
	r&   c                 C   s   dd | D S )z=
    Return the arguments in their raw, unredacted form.
    c                 S   s    g | ]}t |tr|jn|qS r   )r   r   secretr!   r   r   r   
<listcomp>D   s     z'reveal_command_args.<locals>.<listcomp>r   r%   r   r   r   reveal_command_args@   s   r)   FraiseTcmdshow_stdoutcwdon_returncodez"Literal["raise", "warn", "ignore"]extra_ok_returncodesextra_environunset_environspinnerlog_failed_cmdstdout_onlycommand_descc
             
   C   s  |du rg }|du rg }|rt j}tj}nt j}t}t  |k}| o&|du}|d|
 tj	 }|r8|
| |D ]}||d q:ztjt| tjtj|	sRtjntj||dd}W n tyq } z
|rlt d||
  d}~ww g }|	s|js{J |jsJ |j  	 |j }|sn| }||d  || |r|sJ |  qz|  W |jr|j  n
|jr|j  w w d|}n(| \}}| D ]}|| q|| | D ]}|| q|| |}|jo|j|v}|r|sJ |r|d	 n|d
 |rh|dkrIt |
|j|s|ndd}|rGt !d| t jdt"t#| ddid t jdt"|p@dddid ||dkrYt $d|
|j| |S |dkra	 |S t%d||S )a  
    Args:
      show_stdout: if true, use INFO to log the subprocess's stderr and
        stdout streams.  Otherwise, use DEBUG.  Defaults to False.
      extra_ok_returncodes: an iterable of integer return codes that are
        acceptable, in addition to 0. Defaults to None, which means [].
      unset_environ: an iterable of environment variable names to unset
        prior to calling subprocess.Popen().
      log_failed_cmd: if false, failed commands are not logged, only raised.
      stdout_only: if true, return only stdout, else return both. When true,
        logging of both stdout and stderr occurs when the subprocess has
        terminated, else logging occurs as subprocess output is produced.
    NzRunning command %sbackslashreplace)stdinstdoutstderrr-   enverrorsz#Error %s while executing command %sT
 errordoner*   )command_description	exit_codeoutput_linesz[present-rich] %sz*[bold magenta]full command[/]: [blue]%s[/]markup)extraz[bold magenta]cwd[/]: %sz	[inherit]warnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=)&r   infologgingINFOverboser   getEffectiveLevelosenvironcopyupdatepop
subprocessPopenr)   PIPESTDOUT	Exceptioncriticalr8   r7   closereadlinerstripr   spinwaitr$   communicate
splitlines
returncodefinishr   r>   r
   r&   warning
ValueError)r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   log_subprocess
used_levelshowing_subprocessuse_spinnerr:   nameprocexc
all_outputlineoutputouterrout_lineerr_lineproc_had_errorr>   r   r   r   call_subprocessG   s   




















rq   message).Nc              
      s<   		ddt t dtt dttttf  ddf fdd}|S )	zProvide a subprocess_runner that shows a spinner message.

    Intended for use with for BuildBackendHookCaller. Thus, the runner has
    an API that matches what's expected by BuildBackendHookCaller.subprocess_runner.
    Nr+   r-   r0   r   c                    s@   t  }t|  |||d W d    d S 1 sw   Y  d S )N)r5   r-   r0   r2   )r   rq   )r+   r-   r0   r2   rr   r   r   runner   s   
"z+runner_with_spinner_message.<locals>.runner)NN)r   r    r   r   r   )rr   rt   r   rs   r   runner_with_spinner_message   s   	ru   )	FNr*   NNNNTF)#rH   rL   r   rQ   typingr   r   r   r   r   r   r   r	   pip._vendor.rich.markupr
   pip._internal.cli.spinnersr   r   pip._internal.exceptionsr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   r    CommandArgsr   r&   r)   boolintrq   ru   r   r   r   r   <module>   sh    ("	

	

 )