a
    ˆÀàgr*  ã                
   @   sú   d dl mZ d dlZd dlZd dl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 d dlmZmZ d d	lmZ erÀd d
lmZmZmZmZmZmZmZmZ eeeef  Z dZ!dd„ Z"dd„ Z#dd„ Z$dd„ Z%ddd„Z&dd„ Z'dS )é    )Úabsolute_importN)Úshlex_quote)ÚSpinnerInterfaceÚopen_spinner)ÚInstallationSubprocessError)Úconsole_to_strÚstr_to_display)Úsubprocess_logger)Ú
HiddenTextÚpath_to_display)ÚMYPY_CHECK_RUNNING)ÚAnyÚCallableÚIterableÚListÚMappingÚOptionalÚTextÚUnionz(----------------------------------------c                  G   s2   g }| D ]$}t |tƒr"| |¡ q| |¡ q|S )z&
    Create a CommandArgs object.
    )Ú
isinstanceÚlistÚextendÚappend)ÚargsZcommand_argsÚarg© r   úW/var/www/sistema_ama/venv/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   s,   | ]$}t |tƒrtt|ƒƒnt|ƒV  qd S )N)r   r
   r   Ústr©Ú.0r   r   r   r   Ú	<genexpr>5   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>@   s   z'reveal_command_args.<locals>.<listcomp>r   r$   r   r   r   Úreveal_command_args;   s    ÿr(   c           	      C   sD   t | ƒ}t|dd�}t|ƒ}d |¡}dj|||t|ƒ|td�}|S )z§
    Create and return the error message to use to log a subprocess error
    with command output.

    :param lines: A list of lines, each ending with a newline.
    zcommand bytes)ÚdescÚ zŸCommand errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider})Úexit_statusÚcommand_displayÚcwd_displayZ
line_countÚoutputZdivider)r%   r   r   r#   ÚformatÚlenÚLOG_DIVIDER)	Úcmd_argsÚcwdÚlinesr+   Úcommandr,   r-   r.   Úmsgr   r   r   Úmake_subprocess_output_errorE   s    
ü	òr7   FÚraiseTc              
   C   sâ  |du rg }|du rg }|r*t j}tj}nt j}tj}t  ¡ |k}| oN|du}|du r`t| ƒ}|d|ƒ tj	 
¡ }|r‚| |¡ |D ]}| |d¡ q†z.tjt| ƒtjtj|
s¶tjntj||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 ¡  t|j ¡ ƒ}|�sD�q~| ¡ }| |d ¡ ||ƒ |�r,|�srJ ‚| ¡  �q,z| ¡  W |j�r²|j ¡  n|j�r°|j ¡  0 d |¡}nd| ¡ \}}t|ƒ}| ¡ D ]}||ƒ �qÚ| |¡ t|ƒ}| ¡ D ]}||ƒ �q| |¡ |}|j �o2|j |v}|�r`|�sDJ ‚|�rV| !d¡ n
| !d¡ |�rÞ|d	k�r¦|�s˜|	�r˜t"| |||j d
�}t  #|¡ t$|j |ƒ‚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)ÚstdinÚstdoutÚstderrr3   Úenvz#Error %s while executing command %sÚ
r*   ÚerrorÚdoner8   )r2   r3   r4   r+   Úwarnz$Command "%s" had error code %s in %sÚignorez!Invalid value: on_returncode={!r})(r	   ÚinfoÚloggingÚINFOÚdebugÚDEBUGÚgetEffectiveLevelr%   ÚosÚenvironÚcopyÚupdateÚpopÚ
subprocessÚPopenr(   ÚPIPEÚSTDOUTÚ	ExceptionÚcriticalr:   r9   Úcloser   ÚreadlineÚrstripr   ZspinÚwaitr#   ÚcommunicateÚ
splitlinesÚ
returncodeÚfinishr7   r>   r   ÚwarningÚ
ValueErrorr/   )ÚcmdÚshow_stdoutr3   Zon_returncodeZextra_ok_returncodesZcommand_descÚextra_environZunset_environÚspinnerZlog_failed_cmdÚstdout_onlyZlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerr<   ÚnameÚprocÚexcZ
all_outputÚliner.   Z	out_bytesZ	err_bytesÚoutZout_lineÚerrZerr_lineZproc_had_errorr6   r   r   r   Úcall_subprocesso   sÀ    


ù
	ÿ


ÿ

ÿ


ü

ü
ÿrh   c                    s   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.
    Nc                    s<   t ˆ ƒ� }t| |||d� W d   ƒ n1 s.0    Y  d S )N)r3   r_   r`   )r   rh   )r]   r3   r_   r`   ©Úmessager   r   Úrunner  s    
üz+runner_with_spinner_message.<locals>.runner)NNr   )rj   rk   r   ri   r   Úrunner_with_spinner_message  s    
  ýrl   )
FNr8   NNNNNTF)(Ú
__future__r   rC   rH   rM   Zpip._vendor.six.movesr   Zpip._internal.cli.spinnersr   r   Úpip._internal.exceptionsr   Úpip._internal.utils.compatr   r   Úpip._internal.utils.loggingr	   Úpip._internal.utils.miscr
   r   Úpip._internal.utils.typingr   Útypingr   r   r   r   r   r   r   r   r   ZCommandArgsr1   r   r%   r(   r7   rh   rl   r   r   r   r   Ú<module>   s>   (
,          õ
 '