a
    hbòfÞ#  ã                   @   sx  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rœ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)Ú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   ú[/home/httpd/docs/test/DocsMgr/lib/python3.9/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_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   ó    z'reveal_command_args.<locals>.<listcomp>r   r%   r   r   r   Úreveal_command_args@   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u rg }|du rg }|r*t j}tj}n
t j}t}t  ¡ |k}| oL|du}|d|
ƒ tj 	¡ }|rp| 
|¡ |D ]}| |d¡ qtz0tjt| ƒtjtj|	s¤tjntj||dd�}W n8 tyî } z |rØt  d||
¡ ‚ W Y d}~n
d}~0 0 g }|	�sª|j�sJ ‚|j�sJ ‚|j ¡  |j ¡ }|�s0�qj| ¡ }| |d ¡ ||ƒ |�r|�s^J ‚| ¡  �qz| ¡  W |j�rž|j ¡  n|j�rœ|j ¡  0 d |¡}nT| ¡ \}}| ¡ D ]}||ƒ �q¾| |¡ | ¡ D ]}||ƒ �qà| |¡ |}|j�o|j|v}|�r<|�s J ‚|�r2| d¡ n
| d	¡ |�rð|d
k�r¸t |
|j|�s^|ndd�}|�r²t  !d|¡ t jdt"t#| ƒƒddid� t jdt"|�p¤dƒddid� |‚n8|dk�rÖt  $d|
|j|¡ n|dk�rân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[present-diagnostic] %sz*[bold magenta]full command[/]: [blue]%s[/]ÚmarkupT)Ú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Úcriticalr9   r8   ÚcloseÚreadlineÚrstripr   ÚspinÚwaitr$   ÚcommunicateÚ
splitlinesÚ
returncodeÚfinishr   r?   r
   r&   ÚwarningÚ
ValueError)r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   Ú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Ê    


ø

ý



ÿ




ý
ýý
ü
rr   ).N)Úmessager   c                    s2   dt t tt ttttf  ddœ‡ fdd„}|S )zÜProvide a subprocess_runner that shows a spinner message.

    Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
    an API that matches what's expected by Pep517HookCaller.subprocess_runner.
    N)r,   r.   r1   r   c                    s>   t ˆ ƒ�"}t| ˆ |||d� W d   ƒ n1 s00    Y  d S )N)r6   r.   r1   r3   )r   rr   )r,   r.   r1   r3   ©rs   r   r   Úrunnerö   s    
ûz+runner_with_spinner_message.<locals>.runner)NN)r   r    r   r   r   )rs   ru   r   rt   r   Úrunner_with_spinner_messageï   s    	  ýürv   )	FNr+   NNNNTF)#rI   rM   r   rR   Ú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   r    ÚCommandArgsr   r&   r*   ÚboolÚintrr   rv   r   r   r   r   Ú<module>   sP   ( 	         ö

ó )