Current File : //lib/python3.9/site-packages/pip/_internal/__pycache__/configuration.cpython-39.pyc
a

[��fa3�@s>dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZddlmZddlmZddlmZmZejZe
d	e�Zer�d
ndZdZed
ddddd�Zejej ej!ej"ej#fZ$ej ejej!fZ%ee&�Z'eed�dd�Z(ee	ed�dd�Z)eee	efd�dd�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�globalZsite�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.9/site-packages/pip/_internal/configuration.py�_normalize_name2s
r%cCs&d|vrd�|�}t|��|�dd�S)N�.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?�)�formatr	�split)rZ
error_messager#r#r$�_disassemble_key:s��r*�rcCstdd�t�d�D�}tj�tjt�}tj�tj�d�t	r<dndt�}tj�t�
d�t�}tj|tj
|gtj||giS)NcSsg|]}tj�|t��qSr#)�os�path�join�CONFIG_BASENAME)�.0r-r#r#r$�
<listcomp>Esz+get_configuration_files.<locals>.<listcomp>Zpip�~z.pip)rZsite_config_dirsr,r-r.�sys�prefixr/�
expanduserrZuser_config_dir�kindsrrr)Zglobal_config_filesZsite_config_fileZlegacy_config_fileZnew_config_filer#r#r$�get_configuration_filesDs�

�
�r7cs�eZdZdZd6eeedd��fdd�
Zdd�dd�Zee	d�d	d
�Z
eee	e
fd�dd�Ze	e
d
�dd�Ze	e
dd�dd�Ze	dd
�dd�Zdd�dd�Zdd�dd�Zeee	e
fd�dd��Zdd�dd�Zee	ed�dd�Ze	ed �d!d"�Zdd�d#d$�Ze	eee	e
fee	e
fd%�d&d'�Zeee	e	fd�d(d)�Zeeeee	fd�d*d+�Zeee	e
fd,�d-d.�Z ee	efd�d/d0�Z!e	edd1�d2d3�Z"e	d�d4d5�Z#�Z$S)7�
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���|dur4|tvr4td�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#�r0�variantr#r#r$�
<dictcomp>rsz*Configuration.__init__.<locals>.<dictcomp>cSsi|]
}|i�qSr#r#r;r#r#r$r=us)�super�__init__�VALID_LOAD_ONLYr	r(r.�map�reprr9r:�OVERRIDE_ORDER�_parsers�_config�_modified_parsers)�selfr9r:��	__class__r#r$r?es 
����zConfiguration.__init__r+cCs|��|js|��dS)z<Loads configuration from configuration files and environmentN)�_load_config_filesr9�_load_environment_vars�rGr#r#r$�loadzszConfiguration.loadcCs:|jdusJd��z|��dWSty4YdS0dS)z7Returns the file with highest priority in configurationNz)Need to be specified a file to be editingr)r:�_get_parser_to_modify�
IndexErrorrLr#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�itemsrLr#r#r$rR�szConfiguration.items)�keyrcCs2z|j|WSty,td|����Yn0dS)z#Get a value from the configuration.�No such key - N)rQ�KeyErrorr	)rGrSr#r#r$�	get_value�szConfiguration.get_value)rS�valuercCst|��|jsJ�|��\}}|durTt|�\}}|�|�sF|�|�|�|||�||j|j|<|�||�dS)z$Modify a value in the configuration.N)	�_ensure_have_load_onlyr:rNr*�has_sectionZadd_section�setrE�_mark_as_modified)rGrSrW�fname�parser�sectionrr#r#r$�	set_value�s


zConfiguration.set_valuecCs�|��|jsJ�||j|jvr0td|����|��\}}|dur�t|�\}}|�|�rf|�||�sntd��|�|�s�|�	|�|�
||�|j|j|=dS)z#Unset a value in the configuration.rTNz4Fatal Internal error [id=1]. Please report as a bug.)rXr:rEr	rNr*rYZ
remove_optionrRZremove_sectionr[)rGrSr\r]r^rr#r#r$�unset_value�s$
�
��

zConfiguration.unset_valuec	Csl|��|jD]X\}}t�d|�ttj�|��t|d��}|�	|�Wd�q1s\0YqdS)z!Save the current in-memory state.z
Writing to %s�wN)
rXrF�logger�inforr,r-�dirname�open�write)rGr\r]�fr#r#r$�save�szConfiguration.savecCs$|jdurtd��t�d|j�dS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)r:r	rb�debugrLr#r#r$rX�s
z$Configuration._ensure_have_load_onlycCs"i}tD]}|�|j|�q|S)z3A dictionary representing the loaded configuration.)rC�updaterE)rGZretvalr<r#r#r$rQ�szConfiguration._dictionarycCs�t|���}|tjdd�tjgkr4t�d�dS|��D]V\}}|D]H}|j	durp||j	krpt�d||�qH|�
||�}|j|�||f�qHq<dS)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_filesr6rr,�devnullrbrirRr:�
_load_filerD�append)rG�config_filesr<�filesr\r]r#r#r$rJ�s�z Configuration._load_config_files)r<r\rcCsLt�d||�|�|�}|��D]&}|�|�}|j|�|�||��q |S)Nz'For variant '%s', will try loading '%s')rb�verbose�_construct_parserZsectionsrRrErj�_normalized_keys)rGr<r\r]r^rRr#r#r$rn�s

zConfiguration._load_file)r\rc
Cs�t��}tj�|�r|z|�|�WnXtyLtd�t	�
d��|d��Yn0tjyz}zt|d��WYd}~n
d}~00|S)Nzcontains invalid {} charactersF)�reasonr\)�error)�configparser�RawConfigParserr,r-�exists�read�UnicodeDecodeErrorr
r(�locale�getpreferredencoding�Error)rGr\r]rvr#r#r$rss��
 zConfiguration._construct_parsercCs"|jtj�|�d|����dS)z.Loads configuration from environment variablesz:env:N)rEr6rrjrt�get_environ_varsrLr#r#r$rKs�z$Configuration._load_environment_vars)r^rRrcCs.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%)rGr^rRZ
normalizedr�valrSr#r#r$rt"s

zConfiguration._normalized_keysccsDtj��D]4\}}|�d�r
|dd���}|tvr
||fVq
dS)z@Returns a generator with all environmental vars with prefix PIP_ZPIP_�N)r,�environrRr"r �ENV_NAMES_IGNORED)rGrSr�rr#r#r$r0s

zConfiguration.get_environ_varsccs�tj�dd�}|dur&tj|gfVntjgfVt�}tj|tjfV|job|o`tj�	|�}|rztj
|tj
fVtj|tjfVdS)zYields variant and configuration files associated with it.

        This should be treated like items of a dictionary.
        ZPIP_CONFIG_FILEN)r,r��getr6rr7rr9r-ryrr)rGZconfig_filerpZshould_load_user_configr#r#r$rl9s�zConfiguration.iter_config_files)r<rcCs
|j|S)z#Get values present in a config file)rE)rGr<r#r#r$�get_values_in_configWsz"Configuration.get_values_in_configcCs*|js
J�|j|j}|s"td��|dS)Nz4Fatal Internal error [id=2]. Please report as a bug.���)r:rDr	)rG�parsersr#r#r$rN[s
�z#Configuration._get_parser_to_modify)r\r]rcCs"||f}||jvr|j�|�dS)N)rFro)rGr\r]Zfile_parser_tupler#r#r$r[is
zConfiguration._mark_as_modifiedcCs|jj�d|j�d�S)N�(�))rI�__name__rQrLr#r#r$�__repr__nszConfiguration.__repr__)N)%r��
__module__�__qualname__�__doc__�boolrrr?rM�strrPrrrrRrVr_r`rhrX�propertyrrQrJrxrnrsrKrtrrrlr�rNr[r��
__classcell__r#r#rHr$r8Ws2
	

�	r8),r�rwr|r,r3�typingrrrrrrrZpip._internal.exceptionsr	r
Zpip._internal.utilsrZpip._internal.utils.compatrZpip._internal.utils.loggingr
Zpip._internal.utils.miscrrrxr�rr/r�r6rrrrrrCr@r�rbr%r*r7r8r#r#r#r$�<module>s8
$
�