HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_internal/commands/__pycache__/configuration.cpython-310.pyc
o

@%Ne�"�@s�ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZmZmZmZddlmZddlmZdd	lmZmZe�e�ZGd
d�de
�ZdS)�N)�Values)�Any�List�Optional)�Command)�ERROR�SUCCESS)�
Configuration�Kind�get_configuration_files�kinds)�PipError)�
indent_log)�get_prog�write_outputc@sHeZdZdZdZdZd(dd�Zded	ee	de
fd
d�Zdedede
efd
d�Zded	ee	ddfdd�Zded	ee	ddfdd�Zded	ee	ddfdd�Zded	ee	ddfdd�Zded	ee	ddfdd�Zdeddfdd�Zd(dd�Zded	ee	ddfdd�Zd	ee	d e	d!e
defd"d#�Zd(d$d%�Zdede	fd&d'�ZdS))�ConfigurationCommandaa
    Manage local and global configuration.

    Subcommands:

    - list: List the active configuration (or from the file specified)
    - edit: Edit the configuration file in an editor
    - get: Get the value associated with name
    - set: Set the name=value
    - unset: Unset the value associated with name
    - debug: List the configuration files and values defined under them

    If none of --user, --global and --site are passed, a virtual
    environment configuration file is used if one is active and the file
    exists. Otherwise, all modifications happen to the user file by
    default.
    Ta
        %prog [<file-option>] list
        %prog [<file-option>] [--editor <editor-path>] edit

        %prog [<file-option>] get name
        %prog [<file-option>] set name value
        %prog [<file-option>] unset name
        %prog [<file-option>] debug
    �returnNcCsl|jjdddddd�|jjdddd	d
d�|jjdddd	d
d�|jjdddd	dd�|j�d|j�dS)Nz--editor�editor�storez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)�dest�action�default�helpz--global�global_file�
store_trueFz+Use the system-wide configuration file onlyz--user�	user_filez$Use the user configuration file onlyz--site�	site_filez3Use the current environment configuration file onlyr)�cmd_opts�
add_option�parser�insert_option_group��self�r#�F/usr/lib/python3/dist-packages/pip/_internal/commands/configuration.py�add_options4s:����z ConfigurationCommand.add_options�options�argsc
Cs|j|j|j|j|j|jd�}|r|d|vr$t�dd�t	|���t
S|d}z|j||dvd�}WntyO}zt�|j
d�t
WYd}~Sd}~wwt|j|d�|_|j��z||||dd��WtSty�}zt�|j
d�t
WYd}~Sd}~ww)	N)�list�edit�get�set�unset�debugrzNeed an action (%s) to perform.z, )r*r+r,r))�
need_value)�isolated�	load_only�)�list_values�open_in_editor�get_name�set_name_value�
unset_name�list_config_values�logger�error�join�sortedr�_determine_filer
r'r	�
isolated_mode�
configuration�loadr)r"r&r'�handlersrr0�er#r#r$�runZsF�
�
����
���zConfigurationCommand.runr.cCszdd�tj|jftj|jftj|jffD�}|s/|sdStdd�t�tjD��r,tjStjSt	|�dkr9|dSt
d��)NcSsg|]\}}|r|�qSr#r#)�.0�key�valuer#r#r$�
<listcomp>�s��z8ConfigurationCommand._determine_file.<locals>.<listcomp>css�|]	}tj�|�VqdS)N)�os�path�exists)rC�site_config_filer#r#r$�	<genexpr>�s
�
�
�z7ConfigurationCommand._determine_file.<locals>.<genexpr>r1rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.)r�USERr�GLOBALr�SITEr�anyr�lenr
)r"r&r.�file_optionsr#r#r$r<�s&


��

��z$ConfigurationCommand._determine_filecCs8|j|ddd�t|j���D]
\}}td||�qdS)Nr(r��n�%s=%r)�_get_n_argsr;r>�itemsr�r"r&r'rDrEr#r#r$r2�s�z ConfigurationCommand.list_valuescCs*|j|ddd�}|j�|�}td|�dS)Nz
get [name]r1rRz%s)rUr>�	get_valuerrWr#r#r$r4�szConfigurationCommand.get_namecCs.|j|ddd�\}}|j�||�|��dS)Nzset [name] [value]�rR)rUr>�	set_value�_save_configurationrWr#r#r$r5�sz#ConfigurationCommand.set_name_valuecCs(|j|ddd�}|j�|�|��dS)Nzunset [name]r1rR)rUr>�unset_valuer[)r"r&r'rDr#r#r$r6�szConfigurationCommand.unset_namec
Cs�|j|ddd�|��t|j���D]4\}}td|�|D](}t��tj�	|�}td||�|r7|�
|�Wd�n1sAwYqqdS)z9List config key-value pairs across different config filesr-rrR�%s:z%s, exists: %rN)rU�print_env_var_valuesr;r>�iter_config_filesrrrGrHrI�print_config_file_values)r"r&r'�variant�files�fname�file_existsr#r#r$r7�s

�����z'ConfigurationCommand.list_config_valuesrac	CsP|j�|���D]\}}t��td||�Wd�n1s wYqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r>�get_values_in_configrVrr)r"ra�namerEr#r#r$r`�s���z-ConfigurationCommand.print_config_file_valuescCshtdd�t��"t|j���D]\}}d|����}td||�qWd�dS1s-wYdS)z5Get key-values pairs present as environment variablesr]�env_var�PIP_rTN)rrr;r>�get_environ_vars�upper)r"rDrErgr#r#r$r^�s
�"�z)ConfigurationCommand.print_env_var_valuesc
Csd|�|�}|j��}|durtd��z
t�||g�WdStjy1}ztd�|j���d}~ww)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {})	�_determine_editorr>�get_file_to_editr
�
subprocess�
check_call�CalledProcessError�format�
returncode)r"r&r'rrcrAr#r#r$r3�s


���z#ConfigurationCommand.open_in_editor�examplerScCs8t|�|krd�|t�|�}t|��|dkr|dS|S)zAHelper to make sure the command got the right number of argumentszJGot unexpected number of arguments, expected {}. (example: "{} config {}")r1r)rPrprr
)r"r'rrrS�msgr#r#r$rU�s�z ConfigurationCommand._get_n_argscCs2z|j��WdStyt�d�td��w)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r>�save�	Exceptionr8�	exceptionr
r!r#r#r$r[�s��z(ConfigurationCommand._save_configurationcCs@|jdur|jSdtjvrtjdSdtjvrtjdStd��)N�VISUAL�EDITORz"Could not determine editor to use.)rrG�environr
)r"r&r#r#r$rks




z&ConfigurationCommand._determine_editor)rN)�__name__�
__module__�__qualname__�__doc__�ignore_require_venv�usager%rr�str�intrB�boolrr
r<r2r4r5r6r7r`r^r3rrUr[rkr#r#r#r$rs$

&-

r)�loggingrGrm�optparser�typingrrr�pip._internal.cli.base_commandr�pip._internal.cli.status_codesrr�pip._internal.configurationr	r
rr�pip._internal.exceptionsr
�pip._internal.utils.loggingr�pip._internal.utils.miscrr�	getLoggerrzr8rr#r#r#r$�<module>s