
    /h4                        d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ej        Z e
d	e          Zerd
ndZdZ eddddd          Zej        ej         ej!        ej"        ej#        fZ$ej         ej        ej!        fZ% ee&          Z'dedefdZ(dede	e         fdZ)deee	e         f         fdZ* G d d          Z+dS )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)AnyDictIterableListNewTypeOptionalTuple)ConfigurationError!ConfigurationFileCouldNotBeLoaded)appdirs)WINDOWS)	getLogger)
ensure_direnumKindzpip.inizpip.conf)versionhelpuserglobalsiteenvzenv-var)USERGLOBALSITEENVENV_VARnamereturnc                     |                                                      dd          } |                     d          r
| dd         } | S )zAMake a name consistent regardless of source (environment or file)_-z--   N)lowerreplace
startswith)r   s    N/var/www/html/venv/lib/python3.11/site-packages/pip/_internal/configuration.py_normalize_namer'   2   sE    ::<<S))Dt ABBxK    c                 ~    d| vr$d                     |           }t          |          |                     dd          S )N.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?   )formatr
   split)r   error_messages     r&   _disassemble_keyr/   :   sD    
$=
&,, 	 !///::c1r(   c                     d t          j        d          D             } t          j                            t
          j        t                    }t          j                            t          j                            d          t          rdndt                    }t          j                            t          j
        d          t                    }t          j        | t          j        |gt          j        ||giS )Nc                 X    g | ]'}t           j                            |t                    (S  )ospathjoinCONFIG_BASENAME).0r4   s     r&   
<listcomp>z+get_configuration_files.<locals>.<listcomp>E   s5       04T?++  r(   pip~z.pip)r   site_config_dirsr3   r4   r5   sysprefixr6   
expanduserr   user_config_dirkindsr   r   r   )global_config_filessite_config_filelegacy_config_filenew_config_files       r&   get_configuration_filesrE   D   s     8?8PQV8W8W   w||CJ@@
3$f 
 gll7#:5#A#A?SSO)
%&
'9 r(   c                   "    e Zd ZdZd"dedee         ddf fdZd#dZdee	         fdZ
deee	ef                  fd	Zd
e	defdZd
e	deddfdZd
e	ddfdZd#dZd#dZedee	ef         fd            Zd#dZdede	defdZde	defdZd#dZde	deee	ef                  dee	ef         fdZdeee	e	f                  fdZdeeeee	         f                  fdZdedee	ef         fdZ dee	ef         fdZ!de	deddfd Z"de	fd!Z# xZ$S )$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_onlyr   c           
      z   t                                                       |V|t          vrMt          d                    d                    t          t          t                                                  || _        || _	        d t          D             | _        d t          D             | _        g | _        d S )Nz5Got invalid value for load_only - should be one of {}z, c                     i | ]}|g S r2   r2   r7   variants     r&   
<dictcomp>z*Configuration.__init__.<locals>.<dictcomp>r   s-     H
 H
 H
#GRH
 H
 H
r(   c                     i | ]}|i S r2   r2   rL   s     r&   rN   z*Configuration.__init__.<locals>.<dictcomp>u   s'     4
 4
 4
#GR4
 4
 4
r(   )super__init__VALID_LOAD_ONLYr
   r,   r5   mapreprrH   rI   OVERRIDE_ORDER_parsers_config_modified_parsers)selfrH   rI   	__class__s      r&   rQ   zConfiguration.__init__e   s     Yo%E%E$GNNIIc$8899   
 !"H
 H
'5H
 H
 H
4
 4
'54
 4
 4
 EGr(   c                 h    |                                   | j        s|                                  dS dS )z<Loads configuration from configuration files and environmentN)_load_config_filesrH   _load_environment_varsrY   s    r&   loadzConfiguration.loadz   s@    !!!} 	*'')))))	* 	*r(   c                 |    | j         
J d            	 |                                 d         S # t          $ r Y dS w xY w)z7Returns the file with highest priority in configurationNz)Need to be specified a file to be editingr   )rI   _get_parser_to_modify
IndexErrorr^   s    r&   get_file_to_editzConfiguration.get_file_to_edit   sW    ~))+V)))	--//22 	 	 	44	s   - 
;;c                 4    | j                                         S )z`Returns key-value pairs like dict.items() representing the loaded
        configuration
        )_dictionaryitemsr^   s    r&   rf   zConfiguration.items   s     %%'''r(   keyc                     |}t          |          }	 | j        |         S # t          $ r" t          |           t	          d|           w xY w)z#Get a value from the configuration.No such key - )r'   re   KeyErrorr/   r
   )rY   rg   orig_keys      r&   	get_valuezConfiguration.get_value   sn    c""	B#C(( 	B 	B 	B S!!!$%@h%@%@AAA		Bs	     ,Avaluec                    t          |          }|                                  | j        sJ |                                 \  }}|St	          |          \  }}|                    |          s|                    |           |                    |||           || j        | j                 |<   | 	                    ||           dS )z$Modify a value in the configuration.N)
r'   _ensure_have_load_onlyrI   ra   r/   has_sectionadd_sectionsetrW   _mark_as_modified)rY   rg   rm   fnameparsersectionr   s          r&   	set_valuezConfiguration.set_value   s    c""##%%%~2244v,S11MGT %%g.. ,""7+++JJwe,,,,1T^$S)uf-----r(   c                    |}t          |          }|                                  | j        sJ || j        | j                 vrt	          d|           |                                 \  }}|t          |          \  }}|                    |          r|                    ||          st	          d          |	                    |          s|
                    |           |                     ||           | j        | j                 |= dS )z#Unset a value in the configuration.ri   Nz4Fatal Internal error [id=1]. Please report as a bug.)r'   ro   rI   rW   r
   ra   r/   rp   remove_optionrf   remove_sectionrs   )rY   rg   rk   rt   ru   rv   r   s          r&   unset_valuezConfiguration.unset_value   s'   c""##%%%~dl4>222$%@h%@%@AAA2244v,S11MGT""7++060D0DWd0S0S )J  
 <<(( /%%g...""5&111L(---r(   c                 P   |                                   | j        D ]\  }}t                              d|           t	          t
          j                            |                     t          |d          5 }|	                    |           ddd           n# 1 swxY w Y   dS )z!Save the current in-memory state.zWriting to %swN)
ro   rX   loggerinfor   r3   r4   dirnameopenwrite)rY   rt   ru   fs       r&   savezConfiguration.save   s    ##%%%!3 	  	 ME6KK/// rwu--...eS!!  QQ                             	  	 s   8BB	!B	c                 r    | j         t          d          t                              d| j                    d S )Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rI   r
   r~   debugr^   s    r&   ro   z$Configuration._ensure_have_load_only   s6    >!$%NOOO;T^LLLLLr(   c                 ^    i }t           D ]"}|                    | j        |                    #|S )z3A dictionary representing the loaded configuration.)rU   updaterW   )rY   retvalrM   s      r&   re   zConfiguration._dictionary   s9    
 % 	1 	1GMM$,w/0000r(   c                    t          |                                           }|t          j                 dd         t          j        gk    rt                              d           dS |                                D ]q\  }}|D ]i}| j	        (|| j	        k    rt                              d||           1| 
                    ||          }| j        |                             ||f           jrdS )z,Loads configuration from configuration filesr   r+   zZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNz Skipping file '%s' (variant: %s))dictiter_config_filesr@   r   r3   devnullr~   r   rf   rI   
_load_filerV   append)rY   config_filesrM   filesrt   ru   s         r&   r\   z Configuration._load_config_files   s   D224455	"1Q3'BJ<77LLA   F*0022 	? 	?NGU 
? 
? >-'T^2K2KLL!CUGTTT%88 g&--ufo>>>>
?	? 	?r(   rM   rt   c                 (   t                               d||           |                     |          }|                                D ]K}|                    |          }| j        |                             |                     ||                     L|S )Nz'For variant '%s', will try loading '%s')r~   verbose_construct_parsersectionsrf   rW   r   _normalized_keys)rY   rM   rt   ru   rv   rf   s         r&   r   zConfiguration._load_file  s    @'5QQQ''..(( 	P 	PGLL))EL!(()>)>w)N)NOOOOr(   c                 N   t          j                    }t          j                            |          rrt          j        d          }	 |                    ||           nE# t          $ r t          d| d|          t           j
        $ r}t          |          d }~ww xY w|S )NF)encodingzcontains invalid z characters)reasonrt   )error)configparserRawConfigParserr3   r4   existslocalegetpreferredencodingreadUnicodeDecodeErrorr   Error)rY   rt   ru   locale_encodingr   s        r&   r   zConfiguration._construct_parser  s    -//
 7>>%   	E$9%@@O
EEO<<<<%   7KKKK     % E E E7eDDDDE s   A   -B"BB"c                     | j         t          j                                     |                     d|                                                      dS )z.Loads configuration from environment variablesz:env:N)rW   r@   r   r   r   get_environ_varsr^   s    r&   r]   z$Configuration._load_environment_vars#  sL    U]#**!!'4+@+@+B+BCC	
 	
 	
 	
 	
r(   rv   rf   c                 N    i }|D ]\  }}|dz   t          |          z   }|||<    |S )zNormalizes 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'   )rY   rv   rf   
normalizedr   valrg   s          r&   r   zConfiguration._normalized_keys)  sC     
 	" 	"ID#C-/$"7"77C!JsOOr(   c              #      K   t           j                                        D ]E\  }}|                    d          r+|dd                                         }|t
          vr||fV  FdS )z@Returns a generator with all environmental vars with prefix PIP_PIP_   N)r3   environrf   r%   r#   ENV_NAMES_IGNORED)rY   rg   r   r   s       r&   r   zConfiguration.get_environ_vars7  st      
((** 	$ 	$HC~~f%% $122w}}000)OOO		$ 	$r(   c              #     K   t           j                            dd          }|t          j        |gfV  nt          j        g fV  t                      }t          j        |t          j                 fV  | j         o!|ot           j        	                    |           }|r t          j
        |t          j
                 fV  t          j        |t          j                 fV  dS )zYields variant and configuration files associated with it.

        This should be treated like items of a dictionary.
        PIP_CONFIG_FILEN)r3   r   getr@   r   rE   r   rH   r4   r   r   r   )rY   config_filer   should_load_user_configs       r&   r   zConfiguration.iter_config_files@  s       jnn%6==")k]*****)R-.00 lL66666 '+m"3 #
7BGNN;779
 # 	7*l5:66666 j,uz2222222r(   c                     | j         |         S )z#Get values present in a config file)rW   )rY   rM   s     r&   get_values_in_configz"Configuration.get_values_in_config^  s    |G$$r(   c                 j    | j         sJ | j        | j                  }|st          d          |d         S )Nz4Fatal Internal error [id=2]. Please report as a bug.)rI   rV   r
   )rY   parserss     r&   ra   z#Configuration._get_parser_to_modifyb  sG    ~-/ 	$F  
 r{r(   ru   c                 X    ||f}|| j         vr| j                             |           d S d S N)rX   r   )rY   rt   ru   file_parser_tuples       r&   rs   zConfiguration._mark_as_modifiedp  s@    "FOD$:::"))*;<<<<< ;:r(   c                 0    | j         j         d| j        dS )N())rZ   __name__re   r^   s    r&   __repr__zConfiguration.__repr__u  s!    .)AAD,<AAAAr(   r   )r   N)%r   
__module____qualname____doc__boolr   r   rQ   r_   strrc   r   r	   r   rf   rl   rw   r{   r   ro   propertyr   re   r\   r   r   r   r]   r   r   r   r   r   ra   rs   r   __classcell__)rZ   s   @r&   rG   rG   W   s=        G G G(4. GD G G G G G G** * * *(3-    (xc3h0 ( ( ( (
BS 
BS 
B 
B 
B 
B.S . . . . . .&.s .t . . . .:       "M M M M
 	T#s(^ 	 	 	 X	? ? ? ?.$ s     s     *
 
 
 
#+E#s(O#<	c3h   $(5c?"; $ $ $ $38E$S	/,B#C 3 3 3 3<%D %T#s(^ % % % %uS/-A'B    =s =O = = = = =
B# B B B B B B B Br(   rG   ),r   r   r   r3   r<   typingr   r   r   r   r   r   r	   pip._internal.exceptionsr
   r   pip._internal.utilsr   pip._internal.utils.compatr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   r   r   r   r6   r   r@   r   r   r   r   r   rU   rR   r   r~   r'   r/   rE   rG   r2   r(   r&   <module>r      s-         				 



 F F F F F F F F F F F F F F F F F F        ( ' ' ' ' ' . . . . . . 1 1 1 1 1 1 5 5 5 5 5 5 5 5.wvs&6))J%  				 	 	 uz5:uy%-O*elEJ6	8		# #    3 49    dDIo!6    &_B _B _B _B _B _B _B _B _B _Br(   