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/__pycache__/configuration.cpython-310.pyc
o

@%Nes3�@sBdZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZddlmZddlmZddlmZmZejZe
d	e�ZerRd
ndZdZed
ddddd�Zejej ej!ej"ej#fZ$ej ejej!fZ%ee&�Z'dedefdd�Z(dede	efdd�Z)deee	effdd�Z*Gdd�d�Z+dS)aConfiguration management setup

Some terminology:
- name
  As written in config files.
- value
  Value associated with a name
- key
  Name combined with it's section (section.name)
- variant
  A single word describing where the configuration key-value pair came from
�N)�Any�Dict�Iterable�List�NewType�Optional�Tuple)�ConfigurationError�!ConfigurationFileCouldNotBeLoaded)�appdirs)�WINDOWS)�	getLogger)�
ensure_dir�enum�Kindzpip.inizpip.conf)�version�help�user�global�site�envzenv-var)�USER�GLOBAL�SITE�ENV�ENV_VAR�name�returncCs*|���dd�}|�d�r|dd�}|S)zAMake a name consistent regardless of source (environment or file)�_�-z--�N)�lower�replace�
startswith)r�r$�=/usr/lib/python3/dist-packages/pip/_internal/configuration.py�_normalize_name2s
r&cCs&d|vr
d�|�}t|��|�dd�S)N�.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?�)�formatr	�split)r�
error_messager$r$r%�_disassemble_key:s�r,cCstdd�t�d�D�}tj�tjt�}tj�tj�d�t	rdndt�}tj�t�
d�t�}tj|tj
|gtj||giS)NcSsg|]	}tj�|t��qSr$)�os�path�join�CONFIG_BASENAME)�.0r.r$r$r%�
<listcomp>Es�z+get_configuration_files.<locals>.<listcomp>�pip�~z.pip)r�site_config_dirsr-r.r/�sys�prefixr0�
expanduserr�user_config_dir�kindsrrr)�global_config_files�site_config_file�legacy_config_file�new_config_filer$r$r%�get_configuration_filesDs�

�
�r?cs�eZdZdZd7dedeeddf�fdd�
Zd8dd	�Zdee	fd
d�Z
deee	e
ffdd
�Zde	de
fdd�Zde	de
ddfdd�Zde	ddfdd�Zd8dd�Zd8dd�Zedee	e
ffdd��Zd8dd�Zdede	defd d!�Zde	defd"d#�Zd8d$d%�Zd&e	d'eee	e
fdee	e
ffd(d)�Zdeee	e	ffd*d+�Zdeeeee	ffd,d-�Zdedee	e
ffd.d/�Z dee	effd0d1�Z!de	d2eddfd3d4�Z"de	fd5d6�Z#�Z$S)9�
Configurationa�Handles management of configuration.

    Provides an interface to accessing and managing configuration files.

    This class converts provides an API that takes "section.key-name" style
    keys and stores the value associated with it as "key-name" under the
    section "section".

    This allows for a clean interface wherein the both the section and the
    key-name are preserved in an easy to manage form in the configuration files
    and the data stored is also nice.
    N�isolated�	load_onlyrcsjt���|dur|tvrtd�d�ttt�����||_||_	dd�t
D�|_dd�t
D�|_g|_
dS)Nz5Got invalid value for load_only - should be one of {}z, cSsi|]}|g�qSr$r$�r1�variantr$r$r%�
<dictcomp>r��z*Configuration.__init__.<locals>.<dictcomp>cSsi|]}|i�qSr$r$rCr$r$r%rEurF)�super�__init__�VALID_LOAD_ONLYr	r)r/�map�reprrArB�OVERRIDE_ORDER�_parsers�_config�_modified_parsers)�selfrArB��	__class__r$r%rHes 
����
zConfiguration.__init__cCs|��|js
|��dSdS)z<Loads configuration from configuration files and environmentN)�_load_config_filesrA�_load_environment_vars�rPr$r$r%�loadzs�zConfiguration.loadcCs6|jdus	Jd��z|��dWStyYdSw)z7Returns the file with highest priority in configurationNz)Need to be specified a file to be editingr)rB�_get_parser_to_modify�
IndexErrorrUr$r$r%�get_file_to_edit�s�zConfiguration.get_file_to_editcCs
|j��S)z`Returns key-value pairs like dict.items() representing the loaded
        configuration
        )�_dictionary�itemsrUr$r$r%r[�s
zConfiguration.items�keycCs*z|j|WStytd|����w)z#Get a value from the configuration.�No such key - )rZ�KeyErrorr	)rPr\r$r$r%�	get_value�s
�zConfiguration.get_value�valuecCst|��|js	J�|��\}}|dur*t|�\}}|�|�s#|�|�|�|||�||j|j|<|�||�dS)z$Modify a value in the configuration.N)	�_ensure_have_load_onlyrBrWr,�has_section�add_section�setrN�_mark_as_modified)rPr\r`�fname�parser�sectionrr$r$r%�	set_value�s


zConfiguration.set_valuecCs�|��|js	J�||j|jvrtd|����|��\}}|durGt|�\}}|�|�r3|�||�s7td��|�|�sA|�	|�|�
||�|j|j|=dS)z#Unset a value in the configuration.r]Nz4Fatal Internal error [id=1]. Please report as a bug.)rarBrNr	rWr,rb�
remove_optionr[�remove_sectionre)rPr\rfrgrhrr$r$r%�unset_value�s$
�
��

zConfiguration.unset_valuec	Csl|��|jD],\}}t�d|�ttj�|��t|d��
}|�	|�Wd�n1s.wYqdS)z!Save the current in-memory state.z
Writing to %s�wN)
rarO�logger�inforr-r.�dirname�open�write)rPrfrg�fr$r$r%�save�s���zConfiguration.savecCs$|jdur	td��t�d|j�dS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rBr	rn�debugrUr$r$r%ra�s
z$Configuration._ensure_have_load_onlycCs"i}tD]
}|�|j|�q|S)z3A dictionary representing the loaded configuration.)rL�updaterN)rP�retvalrDr$r$r%rZ�szConfiguration._dictionarycCs�t|���}|tjdd�tjgkrt�d�dS|��D]+\}}|D]$}|j	dur8||j	kr8t�d||�q$|�
||�}|j|�||f�q$qdS)z,Loads configuration from configuration filesrr(zZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNz Skipping file '%s' (variant: %s))
�dict�iter_config_filesr:rr-�devnullrnrur[rB�
_load_filerM�append)rP�config_filesrD�filesrfrgr$r$r%rS�s���z Configuration._load_config_filesrDrfcCsLt�d||�|�|�}|��D]}|�|�}|j|�|�||��q|S)Nz'For variant '%s', will try loading '%s')rn�verbose�_construct_parser�sectionsr[rNrv�_normalized_keys)rPrDrfrgrhr[r$r$r%r{�s

zConfiguration._load_filec
Cs|t��}tj�|�r<t�d�}z
|j||d�W|Sty*t	d|�d�|d��tj
y;}zt	|d��d}~ww|S)NF)�encodingzcontains invalid z characters)�reasonrf)�error)�configparser�RawConfigParserr-r.�exists�locale�getpreferredencoding�read�UnicodeDecodeErrorr
�Error)rPrfrg�locale_encodingr�r$r$r%r�s 

�
�
��zConfiguration._construct_parsercCs"|jtj�|�d|����dS)z.Loads configuration from environment variablesz:env:N)rNr:rrvr��get_environ_varsrUr$r$r%rTs�z$Configuration._load_environment_varsrhr[cCs.i}|D]\}}|dt|�}|||<q|S)z�Normalizes items to construct a dictionary with normalized keys.

        This routine is where the names become keys and are made the same
        regardless of source - configuration files or environment.
        r')r&)rPrhr[�
normalizedr�valr\r$r$r%r�!s

zConfiguration._normalized_keysccsF�tj��D]\}}|�d�r |dd���}|tvr ||fVqdS)z@Returns a generator with all environmental vars with prefix PIP_�PIP_�N)r-�environr[r#r!�ENV_NAMES_IGNORED)rPr\r�rr$r$r%r�/s�

��zConfiguration.get_environ_varsccs��tj�dd�}|durtj|gfVntjgfVt�}tj|tjfV|jo2|o1tj�	|�}|r>tj
|tj
fVtj|tjfVdS)zYields variant and configuration files associated with it.

        This should be treated like items of a dictionary.
        �PIP_CONFIG_FILEN)r-r��getr:rr?rrAr.r�rr)rP�config_filer}�should_load_user_configr$r$r%ry8s��zConfiguration.iter_config_filescCs
|j|S)z#Get values present in a config file)rN)rPrDr$r$r%�get_values_in_configVs
z"Configuration.get_values_in_configcCs*|jsJ�|j|j}|std��|dS)Nz4Fatal Internal error [id=2]. Please report as a bug.���)rBrMr	)rP�parsersr$r$r%rWZs
�z#Configuration._get_parser_to_modifyrgcCs&||f}||jvr|j�|�dSdS�N)rOr|)rPrfrg�file_parser_tupler$r$r%rehs
�zConfiguration._mark_as_modifiedcCs|jj�d|j�d�S)N�(�))rR�__name__rZrUr$r$r%�__repr__mszConfiguration.__repr__r�)rN)%r��
__module__�__qualname__�__doc__�boolrrrHrV�strrYrrrr[r_rirlrtra�propertyrrZrSr�r{r�rTr�r�rryr�rWrer��
__classcell__r$r$rQr%r@Ws< 
	




��

�	r@),r�r�r�r-r6�typingrrrrrrr�pip._internal.exceptionsr	r
�pip._internal.utilsr�pip._internal.utils.compatr�pip._internal.utils.loggingr
�pip._internal.utils.miscrrr�r�rr0r�r:rrrrrrLrIr�rnr&r,r?r@r$r$r$r%�<module>s:
$
�