Viewing File: /opt/hc_python/lib/python3.12/site-packages/pip/_internal/__pycache__/configuration.cpython-312.pyc

�

T�*j�8����dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
mZddlmZddlmZdd	lmZdd
lmZmZej0Zede�Zerdnd
ZdZeddddd��Zej<ej>ej@ejBejDfZ#ej>ej<ej@fZ$ee%�Z&dd�Z'dd�Z(dd�Z)Gd�d�Z*y)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
�)�annotationsN)�Iterable)�Any�NewType)�ConfigurationError�!ConfigurationFileCouldNotBeLoaded)�appdirs)�WINDOWS)�	getLogger)�
ensure_dir�enum�Kindzpip.inizpip.conf)�version�help�user�global�site�envzenv-var)�USER�GLOBAL�SITE�ENV�ENV_VARc�h�|j�jdd�}|jd�}|S)zAMake a name consistent regardless of source (environment or file)�_�-z--)�lower�replace�removeprefix)�names �J/opt/hc_python/lib/python3.12/site-packages/pip/_internal/configuration.py�_normalize_namer"5s/���:�:�<����S�)�D����T�"�D��K�c�P�d|vrd|�d�}t|��|jdd�S)N�.zVKey does not contain dot separated section and key. Perhaps you wanted to use 'global.z
' instead?�)r�split)r �
error_messages  r!�_disassemble_keyr)<s>��
�$��
1�15��j�
B�	�!��/�/��:�:�c�1��r#c�d�tjd�D�cgc]&}tjj	|t
���(}}tjj	tjt
�}tjj	tjjd�trdndt
�}tjj	tjd�t
�}tj|tj|gtj||giScc}w)N�pip�~z.pip)r	�site_config_dirs�os�path�join�CONFIG_BASENAME�sys�prefix�
expanduserr
�user_config_dir�kindsrrr)r/�global_config_files�site_config_file�legacy_config_file�new_config_files     r!�get_configuration_filesr;Fs���8?�8P�8P�QV�8W��8W�������T�?�+�8W����w�w�|�|�C�J�J��@�������
�����3����f����
�g�g�l�l�7�#:�#:�5�#A�?�S�O�
���)�
�
�
�%�&�
�
�
�'��9����s�+D-c����eZdZdZdd�fd�
Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Ze
dd��Zdd�Zd d
�Zd!d�Zdd�Z						d"d�Zd#d�Zd$d�Zd%d�Zd&d�Zd'd�Zd(d�Z�xZS))�
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.
    c
�R��t�|��|�C|tvr;tdj	djt
tt�����||_||_	tD�cic]}|g��c}|_tD�cic]}|i��c}|_g|_
ycc}wcc}w)Nz5Got invalid value for load_only - should be one of {}z, )�super�__init__�VALID_LOAD_ONLYr�formatr0�map�repr�isolated�	load_only�OVERRIDE_ORDER�_parsers�_config�_modified_parsers)�selfrErF�variant�	__class__s    �r!r@zConfiguration.__init__gs����
����� �Y�o�%E�$�G�N�N��I�I�c�$��8�9���
�
!��
�"���(6�H
�'5�G�G�R�K�~�H
��
�(6�?
�'5�G�G�R�K�~�?
���EG����
H
��?
s�+
B�
B$c�^�|j�|js|j�yy)z<Loads configuration from configuration files and environmentN)�_load_config_filesrE�_load_environment_vars�rKs r!�loadzConfiguration.load|s&�����!��}�}��'�'�)�r#c�n�|j�Jd��	|j�dS#t$rYywxYw)z7Returns the file with highest priority in configurationNz)Need to be specified a file to be editingr)rF�_get_parser_to_modify�
IndexErrorrQs r!�get_file_to_editzConfiguration.get_file_to_edit�sC���~�~�)�V�+V�V�)�	��-�-�/��2�2���	��	�s�(�	4�4c�6�|jj�S)z`Returns key-value pairs like dict.items() representing the loaded
        configuration
        )�_dictionary�itemsrQs r!rYzConfiguration.items�s�����%�%�'�'r#c���|}t|�}	i}|jj�D]}|j|��||S#t$rt|�t
d|����wxYw)z#Get a value from the configuration.�No such key - )r"rX�values�update�KeyErrorr)r)rK�key�orig_key�clean_config�file_valuess     r!�	get_valuezConfiguration.get_value�s{�����c�"��		B�+-�L�#�/�/�6�6�8���#�#�K�0� 9���$�$���	B�
�S�!�$�~�h�Z�%@�A�A�		B�s�6A�#A)c��t|�}|j�|jsJ�|j�\}}|�Ct	|�\}}|j|�s|j
|�|j|||�|j|jj|i�||j|j||<|j||�y)z$Modify a value in the configuration.N)r"�_ensure_have_load_onlyrFrTr)�has_section�add_section�setrI�
setdefault�_mark_as_modified)rKr_�value�fname�parser�sectionr s       r!�	set_valuezConfiguration.set_value�s����c�"���#�#�%��~�~��~��2�2�4�
��v���,�S�1�M�G�T��%�%�g�.��"�"�7�+��J�J�w��e�,����T�^�^�$�/�/��r�:�38����T�^�^�$�U�+�C�0����u�f�-r#c��|}t|�}|j�|jsJ�|j�\}}||j|j|vr)||j|jvrtd|����|�pt
|�\}}|j|�r|j||�std��|j|�s|j|�|j||�	|j|j||=y#t$r|j|j|=YywxYw)z#Unset a value in the configuration.r[Nz4Fatal Internal error [id=1]. Please report as a bug.)
r"rerFrTrIrr)rf�
remove_optionrY�remove_sectionrjr^)rKr_r`rlrmrnr s       r!�unset_valuezConfiguration.unset_value�s0�����c�"���#�#�%��~�~��~��2�2�4�
��v�
�t�|�|�D�N�N�3�E�:�:��4�<�<����7�7�$�~�h�Z�%@�A�A���,�S�1�M�G�T��"�"�7�+��0D�0D�W�d�0S�)�J���
�<�<��(��%�%�g�.��"�"�5�&�1�	2����T�^�^�,�U�3�C�8���	2����T�^�^�,�S�1�	2�s�9D�#D=�<D=c�r�|j�|jD]j\}}tjd|�t	t
jj|��	t|d�5}|j|�ddd��ly#1swY�xYw#t$r}td|�d|����d}~wwxYw)z!Save the current in-memory state.z
Writing to %s�wNz:An error occurred while writing to the configuration file z: )rerJ�logger�inforr.r/�dirname�open�write�OSErrorr)rKrlrm�f�errors     r!�savezConfiguration.save�s����#�#�%�!�3�3�M�E�6��K�K���/�
�r�w�w���u�-�.�
��%��%���L�L��O�&��4�&�%���
�(�P��g�R��w�(����
�s0�"B�.B�B�B	�B�	B6� B1�1B6c�r�|j�td��tjd|j�y)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rFrrv�debugrQs r!rez$Configuration._ensure_have_load_only�s+���>�>�!�$�%N�O�O����;�T�^�^�Lr#c�\�i}tD] }|j|j|��"|S)z3A dictionary representing the loaded configuration.)rGr]rI)rK�retvalrLs   r!rXzConfiguration._dictionary�s/��
��%�G��M�M�$�,�,�w�/�0�&��
r#c��t|j��}|tjddtj
gk(rtjd�y|j�D]q\}}|D]g}|j�'||jk7rtjd||��6|j||�}|j|j||f��i�sy)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.�devnullrvr�rYrF�
_load_filerH�append)rK�config_filesrL�filesrlrms      r!rOz Configuration._load_config_files�s����D�2�2�4�5����	�	�"�1�Q�'�B�J�J�<�7��L�L�A�
�
�*�0�0�2�N�G�U����>�>�-�'�T�^�^�2K��L�L�!C�U�G�T������%�8���
�
�g�&�-�-�u�f�o�>��3r#c�B�tjd||�|j|�}|j�D]c}|j	|�}|j
|j
|i�|j
||j|j||���e|S)Nz'For variant '%s', will try loading '%s')	rv�verbose�_construct_parser�sectionsrYrIrir]�_normalized_keys)rKrLrlrmrnrYs      r!r�zConfiguration._load_files������@�'�5�Q��'�'��.�����(�G��L�L��)�E��L�L��!�,�,�U�B�7��L�L��!�%�(�/�/��0E�0E�g�u�0U�V�)�
�
r#c�B�tj�}tjj	|�r+tjd�}	|j||��|S|S#t$rtd|�d�|���tj$r}t|���d}~wwxYw)NF)�encodingzcontains invalid z characters)�reasonrl)r})�configparser�RawConfigParserr.r/�exists�locale�getpreferredencoding�read�UnicodeDecodeErrorr�Error)rKrlrm�locale_encodingr}s     r!r�zConfiguration._construct_parser!s����-�-�/��
�7�7�>�>�%� �$�9�9�%�@�O�

E����E�O��<��
�v�
��&�
�7�.��.?�{�K���� �%�%�
E�7�e�D�D��
E�s�
A!�!,B�
B�Bc��|jtjjdi�|jtjdj	|jd|j
���y)z.Loads configuration from environment variablesz:env:N)rIr6rrir]r��get_environ_varsrQs r!rPz$Configuration._load_environment_vars6sX�����U�]�]�#�.�.�w��;����U�]�]�#�G�,�3�3��!�!�'�4�+@�+@�+B�C�	
r#c�J�i}|D]\}}|dzt|�z}|||<�|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")rKrnrY�
normalizedr �valr_s       r!r�zConfiguration._normalized_keys=s;���
��I�D�#��C�-�/�$�"7�7�C�!�J�s�O���r#c#�K�tjj�D]9\}}|jd�s�|ddj	�}|t
vs�4||f���;y�w)z@Returns a generator with all environmental vars with prefix PIP_�PIP_�N)r.�environrY�
startswithr�ENV_NAMES_IGNORED)rKr_r�r s    r!r�zConfiguration.get_environ_varsKsP�����
�
�(�(�*�H�C���~�~�f�%��1�2�w�}�}����0�0���)�O�	+�s�6A�A�	Ac#�K�tjjdd�}t�}tj
|tj
f��|jxr$|xrtjj|�}|r%tj|tjf��tj|tjf��|�tj|gf��ytjgf��y�w)a�Yields variant and configuration files associated with it.

        This should be treated like items of a dictionary. The order
        here doesn't affect what gets overridden. That is controlled
        by OVERRIDE_ORDER. However this does control the order they are
        displayed to the user. It's probably most ergonomic to display
        things in the same order as OVERRIDE_ORDER
        �PIP_CONFIG_FILEN)r.r��getr;r6rrEr/r�rrr)rK�env_config_filer��should_load_user_configs    r!r�zConfiguration.iter_config_filesTs������*�*�.�.�):�D�A��.�0���l�l�L����6�6�6�'+�m�m�"3�#
��?������� ?�9
��#��*�*�l�5�:�:�6�6�6��j�j�,�u�z�z�2�2�2��&��)�)�o�.�.�.��)�)�R�-��s�C<C>c� �|j|S)z#Get values present in a config file)rI)rKrLs  r!�get_values_in_configz"Configuration.get_values_in_configts���|�|�G�$�$r#c�t�|jsJ�|j|j}|std��|dS)Nz4Fatal Internal error [id=2]. Please report as a bug.���)rFrHr)rK�parserss  r!rTz#Configuration._get_parser_to_modifyxs?���~�~��~��-�-����/���$�F��
�
�r�{�r#c�`�||f}||jvr|jj|�yy�N)rJr�)rKrlrm�file_parser_tuples    r!rjzConfiguration._mark_as_modified�s4��"�F�O���D�$:�$:�:��"�"�)�)�*;�<�;r#c�N�|jj�d|j�d�S)N�(�))rM�__name__rXrQs r!�__repr__zConfiguration.__repr__�s'���.�.�)�)�*�!�D�,<�,<�+?�q�A�Ar#r�)rE�boolrFzKind | None�return�None)r�r�)r�z
str | None)r��Iterable[tuple[str, Any]])r_�strr�r)r_r�rkrr�r�)r_r�r�r�)r�zdict[str, dict[str, Any]])rLrrlr�r�r�)rlr�r�r�)rnr�rYr�r��dict[str, Any])r�zIterable[tuple[str, str]])r�z Iterable[tuple[Kind, list[str]]])rLrr�r�)r�ztuple[str, RawConfigParser])rlr�rmr�r�r�)r�r�)r��
__module__�__qualname__�__doc__r@rRrVrYrcrorsr~re�propertyrXrOr�r�rPr�r�r�r�rTrjr��
__classcell__)rMs@r!r=r=Ys�����G�**��(�
B�.�( 2�D�0M�
�	��	�?�.	��*
����#<��	��$� �@%��=�
Br#r=)r r�r�r�)r r�r�z	list[str])r�zdict[Kind, list[str]])+r��
__future__rr�r�r.r2�collections.abcr�typingrr�pip._internal.exceptionsrr�pip._internal.utilsr	�pip._internal.utils.compatr
�pip._internal.utils.loggingr�pip._internal.utils.miscrr
r�r�rr1r�r6rrrrrrGrAr�rvr"r)r;r=�r#r!�<module>r�s����#��
�	�
�$���(�.�1�5��.�.���v�s���&�)�J��%��	
�	��	�
��	�����u�z�z�5�:�:�u�y�y�%�-�-�O���*�*�e�l�l�E�J�J�6��	�8�	�����&sB�sBr#
Back to Directory File Manager