U
    cUh#                     @   sh  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eeef  Zeeeef edd	d
Zeee ef edddZeee ef ee dddZdeee ef eee deee  ee
eef  eee  ee ee ee eedddZ eed dddZ!dS )    N)AnyCallableIterableListLiteralMappingOptionalUnion)escape)SpinnerInterfaceopen_spinner)InstallationSubprocessError)VERBOSEsubprocess_logger)
HiddenText)argsreturnc                  G   s2   g }| D ]$}t |tr"|| q|| q|S )z&
    Create a CommandArgs object.
    )
isinstancelistextendappend)r   Zcommand_argsarg r   ^/opt/bot/vods_filmes/script/venv/lib/python3.8/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   s0   | ](}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_args"   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>5   s     z'reveal_command_args.<locals>.<listcomp>r   r#   r   r   r   reveal_command_args1   s    r'   FraiseTz"Literal["raise", "warn", "ignore"])cmdshow_stdoutcwdon_returncodeextra_ok_returncodesextra_environunset_environspinnerlog_failed_cmdstdout_onlycommand_descr   c
             
   C   s  |dkrg }|dkrg }|r*t j}tj}n
t j}t}t  |k}| oL|dk	}|d|
 tj	 }|rp|
| |D ]}||d qtz0tjt| tjtj|	stjntj||dd}W n6 tk
r } z|rt d||
  W 5 d}~X Y nX g }|	s|jst|jst|j  |j }|s.qh| }||d  || |r|s\t|  qz|  W 5 |jr|j  X d|}nT| \}}| D ]}|| q|| | D ]}|| q|| |}|jo|j|k}|r(|st|r| d n
| d	 |r|d
krt!|
|j|sJ|ndd}|rt j"d|ddid t jdt#t$| ddid t jdt#|pdddid |n8|dkrt %d|
|j| n|dkrn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 %s
 errordoner(   )command_description	exit_codeoutput_linesz%srichT)extraz*[bold magenta]full command[/]: [blue]%s[/]markupz[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criticalr6   AssertionErrorr5   closereadlinerstripr   spinwaitr"   communicate
splitlines
returncodefinishr   r<   r
   r$   warning
ValueError)r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   Zlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerr8   nameprocexcZ
all_outputlineoutputouterrZout_lineZerr_lineZproc_had_errorr<   r   r   r   call_subprocess8   s    















ri   ).N)messager   c                    s2   dt t tt ttttf  dd 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.
    N)r)   r+   r.   r   c              	      s*   t  }t|  |||d W 5 Q R X d S )N)r3   r+   r.   r0   )r   ri   )r)   r+   r.   r0   rj   r   r   runner   s    
z+runner_with_spinner_message.<locals>.runner)NN)r   r   r   r   r   )rj   rl   r   rk   r   runner_with_spinner_message   s    	  rm   )	FNr(   NNNNTF)"rG   rK   r   rP   typingr   r   r   r   r   r   r   r	   Zpip._vendor.rich.markupr
   pip._internal.cli.spinnersr   r   pip._internal.exceptionsr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   ZCommandArgsr   r$   r'   boolintri   rm   r   r   r   r   <module>   sL   ( 	         

 )