
    Wh8                       d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	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dZ'd dZ(d!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
    )annotationsN)Iterable)AnyNewType)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str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    m/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/pip/_internal/configuration.py_normalize_namer%   5   sE    ::<<S))Dt ABBxK    	list[str]c                `    d| vrd|  d}t          |          |                     dd          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-   =   sO    
$B15B B B 	 !///::c1r&   dict[Kind, list[str]]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).0r3   s     r$   
<listcomp>z+get_configuration_files.<locals>.<listcomp>H   s5       04T?++  r&   pip~z.pip)r	   site_config_dirsr2   r3   r4   sysprefixr5   
expanduserr
   user_config_dirkindsr   r   r   )global_config_filessite_config_filelegacy_config_filenew_config_files       r$   get_configuration_filesrD   G   s     8?8PQV8W8W   w||CJ@@
3$f 
 gll7#:5#A#A?SSO)
%&
'9 r&   c                       e Zd ZdZd0d1 fd	Zd2d
Zd3dZd4dZd5dZd6dZ	d7dZ
d2dZd2dZed8d            Zd2dZd9dZd:d Zd2d!Zd;d%Zd<d'Zd=d)Zd>d*Zd?d,Zd@d.ZdAd/Z xZS )B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bool	load_onlyKind | Noner   Nonec           
     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 r1   r1   r6   variants     r$   
<dictcomp>z*Configuration.__init__.<locals>.<dictcomp>u   s-     H
 H
 H
#GRH
 H
 H
r&   c                    i | ]}|i S r1   r1   rN   s     r$   rP   z*Configuration.__init__.<locals>.<dictcomp>x   s'     ?
 ?
 ?
#GR?
 ?
 ?
r&   )super__init__VALID_LOAD_ONLYr   formatr4   mapreprrG   rI   OVERRIDE_ORDER_parsers_config_modified_parsers)selfrG   rI   	__class__s      r$   rS   zConfiguration.__init__h   s     Yo%E%E$GNNIIc$8899   
 !"H
 H
'5H
 H
 H
?
 ?
'5?
 ?
 ?
 EGr&   c                h    |                                   | j        s|                                  dS dS )z<Loads configuration from configuration files and environmentN)_load_config_filesrG   _load_environment_varsr\   s    r$   loadzConfiguration.load}   s@    !!!} 	*'')))))	* 	*r&   
str | Nonec                |    | 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
IndexErrorra   s    r$   get_file_to_editzConfiguration.get_file_to_edit   sW    ~))+V)))	--//22 	 	 	44	s   - 
;;Iterable[tuple[str, Any]]c                4    | j                                         S )z`Returns key-value pairs like dict.items() representing the loaded
        configuration
        )_dictionaryitemsra   s    r$   rk   zConfiguration.items   s     %%'''r&   keyr   r   c                    |}t          |          }	 i }| j                                        D ]}|                    |           ||         S # t          $ r" t          |           t          d|           w xY w)z#Get a value from the configuration.No such key - )r%   rj   valuesupdateKeyErrorr-   r   )r\   rl   orig_keyclean_configfile_valuess        r$   	get_valuezConfiguration.get_value   s    c""		B+-L#/6688 1 1##K0000$$ 	B 	B 	B S!!!$%@h%@%@AAA		Bs   :A ,A:valuec                   t          |          }|                                  | j        sJ |                                 \  }}|St	          |          \  }}|                    |          s|                    |           |                    |||           | j        | j                 	                    |i            || j        | j                 |         |<   | 
                    ||           dS )z$Modify a value in the configuration.N)r%   _ensure_have_load_onlyrI   re   r-   has_sectionadd_sectionsetrZ   
setdefault_mark_as_modified)r\   rl   rv   fnameparsersectionr   s          r$   	set_valuezConfiguration.set_value   s    c""##%%%~2244v,S11MGT %%g.. ,""7+++JJwe,,,T^$//r:::38T^$U+C0uf-----r&   c                   |}t          |          }|                                  | j        sJ |                                 \  }}|| j        | j                 |         vr&|| j        | j                 vrt          d|           |t          |          \  }}|                    |          r|                    ||          st          d          |	                    |          s|
                    |           |                     ||           	 | j        | j                 |         |= dS # t          $ r | j        | j                 |= Y dS w xY w)z#Unset a value in the configuration.rn   Nz4Fatal Internal error [id=1]. Please report as a bug.)r%   rx   rI   re   rZ   r   r-   ry   remove_optionrk   remove_sectionr}   rq   )r\   rl   rr   r~   r   r   r   s          r$   unset_valuezConfiguration.unset_value   s   c""##%%%~2244v t|DN3E:::4<777$%@h%@%@AAA,S11MGT""7++060D0DWd0S0S )J  
 <<(( /%%g...""5&111	2T^,U3C888 	2 	2 	2T^,S1111	2s   D0 0EEc                   |                                   | j        D ]\  }}t                              d|           t	          t
          j                            |                     	 t          |d          5 }|	                    |           ddd           n# 1 swxY w Y   # t          $ r}t          d| d|           d}~ww xY wdS )z!Save the current in-memory state.zWriting to %swNz:An error occurred while writing to the configuration file z: )rx   r[   loggerinfor   r2   r3   dirnameopenwriteOSErrorr   )r\   r~   r   ferrors        r$   savezConfiguration.save   s-   ##%%%!3 	 	ME6KK/// rwu--...%%% $LLOOO$ $ $ $ $ $ $ $ $ $ $ $ $ $ $   ((( ( %( (  	 	s<   )B'9BB'B	B'"B	#B''
C1CC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   debugra   s    r$   rx   z$Configuration._ensure_have_load_only   s6    >!$%NOOO;T^LLLLLr&   dict[str, dict[str, Any]]c                ^    i }t           D ]"}|                    | j        |                    #|S )z3A dictionary representing the loaded configuration.)rX   rp   rZ   )r\   retvalrO   s      r$   rj   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   r2   devnullr   r   rk   rI   
_load_filerY   append)r\   config_filesrO   filesr~   r   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&   rO   r   r~   RawConfigParserc                v   t                               d||           |                     |          }|                                D ]r}|                    |          }| j        |                             |i            | j        |         |                             |                     ||                     s|S )Nz'For variant '%s', will try loading '%s')	r   verbose_construct_parsersectionsrk   rZ   r|   rp   _normalized_keys)r\   rO   r~   r   r   rk   s         r$   r   zConfiguration._load_file  s    @'5QQQ''..(( 	W 	WGLL))EL!,,UB777L!%(//0E0Egu0U0UVVVV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)reasonr~   )r   )configparserr   r2   r3   existslocalegetpreferredencodingreadUnicodeDecodeErrorr   Error)r\   r~   r   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i            | j         t          j                 d                             |                     d|                                                      dS )z.Loads configuration from environment variablesz:env:N)rZ   r?   r   r|   rp   r   get_environ_varsra   s    r$   r`   z$Configuration._load_environment_vars7  sp    U]#..w;;;U]#G,33!!'4+@+@+B+BCC	
 	
 	
 	
 	
r&   r   rk   dict[str, Any]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%   )r\   r   rk   
normalizedr   valrl   s          r$   r   zConfiguration._normalized_keys>  sC     
 	" 	"ID#C-/$"7"77C!JsOOr&   Iterable[tuple[str, str]]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)r2   environrk   r#   r!   ENV_NAMES_IGNORED)r\   rl   r   r   s       r$   r   zConfiguration.get_environ_varsL  st      
((** 	$ 	$HC~~f%% $122w}}000)OOO		$ 	$r&    Iterable[tuple[Kind, list[str]]]c              #    K   t           j                            dd          }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  |t          j        |gfV  dS t          j        g fV  dS )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)r2   r   getrD   r?   r   rG   r3   r   r   r   r   )r\   env_config_filer   should_load_user_configs       r$   r   zConfiguration.iter_config_filesU  s       *..):DAA.00lL66666 '+m"3 #
? ? ?9
 # 	7*l5:66666 j,uz22222&)o.......)R-r&   c                    | j         |         S )z#Get values present in a config file)rZ   )r\   rO   s     r$   get_values_in_configz"Configuration.get_values_in_configu  s    |G$$r&   tuple[str, RawConfigParser]c                j    | j         sJ | j        | j                  }|st          d          |d         S )Nz4Fatal Internal error [id=2]. Please report as a bug.)rI   rY   r   )r\   parserss     r$   re   z#Configuration._get_parser_to_modifyy  sG    ~-/ 	$F  
 r{r&   r   c                X    ||f}|| j         vr| j                             |           d S d S N)r[   r   )r\   r~   r   file_parser_tuples       r$   r}   zConfiguration._mark_as_modified  s@    "FOD$:::"))*;<<<<< ;:r&   c                0    | j         j         d| j        dS )N())r]   __name__rj   ra   s    r$   __repr__zConfiguration.__repr__  s!    .)AAD,<AAAAr&   r   )rG   rH   rI   rJ   r   rK   )r   rK   )r   rc   )r   rh   )rl   r   r   r   )rl   r   rv   r   r   rK   )rl   r   r   rK   )r   r   )rO   r   r~   r   r   r   )r~   r   r   r   )r   r   rk   rh   r   r   )r   r   )r   r   )rO   r   r   r   )r   r   )r~   r   r   r   r   rK   )r   r   )r   
__module____qualname____doc__rS   rb   rg   rk   ru   r   r   r   rx   propertyrj   r_   r   r   r`   r   r   r   r   re   r}   r   __classcell__)r]   s   @r$   rF   rF   Z   s        G G G G G G G** * * *   ( ( ( (B B B B. . . .( 2  2  2  2D   0M M M M
 	 	 	 X	? ? ? ?.	 	 	 	   *
 
 
 
   $ $ $ $       @% % % %   = = = =
B B B B B B B Br&   rF   )r   r   r   r   )r   r   r   r'   )r   r.   )+r   
__future__r   r   r   r2   r;   collections.abcr   typingr   r   pip._internal.exceptionsr   r   pip._internal.utilsr	   pip._internal.utils.compatr
   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   r   r   r   r5   r   r?   r   r   r   r   r   rX   rT   r   r   r%   r-   rD   rF   r1   r&   r$   <module>r      s    # " " " " "      				 



 $ $ $ $ $ $                ( ' ' ' ' ' . . . . . . 1 1 1 1 1 1 5 5 5 5 5 5 5 5.wvs&6))J%  				 	 	 uz5:uy%-O*elEJ6	8		         &sB sB sB sB sB sB sB sB sB sBr&   