U ��.e�7�@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZer�dd lmZmZmZmZmZmZmZejZed e�Ze�e �Z!d d �Z"d d�Z#edddddd�Z$e r�dndZ%dd�Z&Gdd�de'�Z(dS)a Configuration 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)� configparser)�ConfigurationError�!ConfigurationFileCouldNotBeLoaded)�appdirs)�WINDOWS� expanduser)� ensure_dir�enum)�MYPY_CHECK_RUNNING)�Any�Dict�Iterable�List�NewType�Optional�Tuple�KindcCs*|���dd�}|�d�r&|dd�}|S)zFMake a name consistent regardless of source (environment or file) �_�-z--�N)�lower�replace� startswith)�name�r�?/usr/lib/python3.8/site-packages/pip/_internal/configuration.py�_normalize_name.s  rcCs&d|krd�|�}t|��|�dd�S)N�.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?�)�formatr�split)rZ error_messagerrr�_disassemble_key8s��r!�user�globalZsite�envzenv-var)�USER�GLOBAL�SITE�ENV�ENV_VARzpip.inizpip.confcCspdd�t�d�D�}tj�tjt�}tj�td�t r8dndt�}tj�t� d�t�}t j |t j |gt j||giS)NcSsg|]}tj�|t��qSr)�os�path�join�CONFIG_BASENAME)�.0r+rrr� Qs�z+get_configuration_files..Zpip�~z.pip)rZsite_config_dirsr*r+r,�sys�prefixr-rrZuser_config_dir�kindsr&r'r%)Zglobal_config_filesZsite_config_fileZlegacy_config_fileZnew_config_filerrr�get_configuration_filesPs(� ���r4cs�eZdZdZd)�fdd� Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z e dd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Z�ZS)*� 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. Nc s�tt|���tjtjtjdg}||krJtd�d� t t |dd������||_ ||_ tjtjtjtjtjg|_ddg|_dd�|jD�|_dd�|jD�|_g|_dS) Nz5Got invalid value for load_only - should be one of {}z, ������version�helpcSsi|] }|g�qSrr�r.�variantrrr� �sz*Configuration.__init__..cSsi|] }|i�qSrrr9rrrr;�s)�superr5�__init__r3r%r&r'rrr,�map�repr�isolated� load_onlyr(r)�_override_order�_ignore_env_names�_parsers�_config�_modified_parsers)�selfr@rAZ_valid_load_only�� __class__rrr=ts0��� ��zConfiguration.__init__cCs|��|js|��dS)zELoads configuration from configuration files and environment N)�_load_config_filesr@�_load_environment_vars�rGrrr�load�szConfiguration.loadcCs<|jdk std��z|��dWStk r6YdSXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rA�AssertionError�_get_parser_to_modify� IndexErrorrLrrr�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�itemsrLrrrrS�szConfiguration.itemscCs4z |j|WStk r.td�|���YnXdS)z,Get a value from the configuration. �No such key - {}N)rR�KeyErrorrr)rG�keyrrr� get_value�s zConfiguration.get_valuecCsj|��|��\}}|dk rJt|�\}}|�|�s<|�|�|�|||�||j|j|<|�||�dS)z-Modify a value in the configuration. N) �_ensure_have_load_onlyrOr!� has_sectionZ add_section�setrErA�_mark_as_modified)rGrV�value�fname�parser�sectionrrrr� set_value�s    zConfiguration.set_valuec Cs�|��||j|jkr&td�|���|��\}}|dk r�t|�\}}d}|�|�r`|�||�}|r�t |� |��}z t |�}Wnt k r�d}YnX|dkr�|� |�|�||�ntd��|j|j|=dS)z,Unset a value in the configuration. rTNFz4Fatal Internal error [id=1]. Please report as a bug.)rXrErArrrOr!rYZ remove_option�iterrS�next� StopIterationZremove_sectionr[) rGrVr]r^r_rZmodified_somethingZ section_iter�valrrr� unset_value�s,       �zConfiguration.unset_valuec CsX|��|jD]D\}}t�d|�ttj�|��t|d��}|� |�W5QRXqdS)z*Save the current in-memory state. z Writing to %s�wN) rXrF�logger�inforr*r+�dirname�open�write)rGr]r^�frrr�save�s   zConfiguration.savecCs$|jdkrtd��t�d|j�dS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rArrg�debugrLrrrrXs z$Configuration._ensure_have_load_onlycCs$i}|jD]}|�|j|�q |S)zs6   $    �