
    dh8                       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j0                  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jB                  ejD                  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*y)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_VARc                r    | j                         j                  dd      } | j                  d      r| dd } | S )zAMake a name consistent regardless of source (environment or file)_-z--   N)lowerreplace
startswith)names    ]/var/www/html/vivango/api/ia/venv/lib/python3.12/site-packages/pip/_internal/configuration.py_normalize_namer#   5   s6    ::<S)DtABxK    c                P    d| vrd|  d}t        |      | j                  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*   =   s>    
$115jB 	 !//::c1r$   c                 d   t        j                  d      D  cg c]&  } t        j                  j	                  | t
              ( }} t        j                  j	                  t        j                  t
              }t        j                  j	                  t        j                  j                  d      t        rdndt
              }t        j                  j	                  t        j                  d      t
              }t        j                  |t        j                  |gt        j                  ||giS c c} w )Npip~z.pip)r	   site_config_dirsospathjoinCONFIG_BASENAMEsysprefix
expanduserr
   user_config_dirkindsr   r   r   )r0   global_config_filessite_config_filelegacy_config_filenew_config_files        r"   get_configuration_filesr<   G   s    8?8P8PQV8W04T?+  ww||CJJ@
3f
 ggll7#:#:5#A?SO)

%&

'9 s   +D-c                       e Zd ZdZdd fdZddZddZddZddZddZ	ddZ
dd	Zdd
Zedd       ZddZd dZd!dZddZ	 	 	 	 	 	 d"dZd#dZd$dZd%dZd&dZd'dZd(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.
    c           
     R   t         |           |C|t        vr;t        dj	                  dj                  t        t        t                                || _        || _	        t        D ci c]  }|g  c}| _        t        D ci c]  }|i  c}| _        g | _        y c c}w c c}w )Nz5Got invalid value for load_only - should be one of {}z, )super__init__VALID_LOAD_ONLYr   formatr1   mapreprisolated	load_onlyOVERRIDE_ORDER_parsers_config_modified_parsers)selfrF   rG   variant	__class__s       r"   rA   zConfiguration.__init__h   s     Yo%E$GNNIIc$89 
 !" (6H
#GRKH
 (6?
#GRK?
 EGH
?
s   +
B
B$c                ^    | j                          | j                  s| j                          yy)z<Loads configuration from configuration files and environmentN)_load_config_filesrF   _load_environment_varsrL   s    r"   loadzConfiguration.load}   s&    !}}'') r$   c                n    | j                   J d       	 | j                         d   S # t        $ r Y yw xY w)z7Returns the file with highest priority in configurationNz)Need to be specified a file to be editingr   )rG   _get_parser_to_modify
IndexErrorrR   s    r"   get_file_to_editzConfiguration.get_file_to_edit   sC    ~~)V+VV)	--/22 		s   ( 	44c                6    | j                   j                         S )z`Returns key-value pairs like dict.items() representing the loaded
        configuration
        )_dictionaryitemsrR   s    r"   rZ   zConfiguration.items   s     %%''r$   c                    |}t        |      }	 i }| j                  j                         D ]  }|j                  |        ||   S # t        $ r t        |       t        d|       w xY w)z#Get a value from the configuration.No such key - )r#   rY   valuesupdateKeyErrorr*   r   )rL   keyorig_keyclean_configfile_valuess        r"   	get_valuezConfiguration.get_value   s    c"		B+-L#//668 1##K01$$ 	B S!$~hZ%@AA		Bs   6A #A)c                   t        |      }| j                          | j                  sJ | j                         \  }}|Ct	        |      \  }}|j                  |      s|j                  |       |j                  |||       | j                  | j                     j                  |i        || j                  | j                     |   |<   | j                  ||       y)z$Modify a value in the configuration.N)r#   _ensure_have_load_onlyrG   rU   r*   has_sectionadd_sectionsetrJ   
setdefault_mark_as_modified)rL   r`   valuefnameparsersectionr!   s          r"   	set_valuezConfiguration.set_value   s    c"##%~~~224v,S1MGT %%g.""7+JJwe,T^^$//r:38T^^$U+C0uf-r$   c                   |}t        |      }| j                          | j                  sJ | j                         \  }}|| j                  | j                     |   vr)|| j                  | j                     vrt        d|       |pt        |      \  }}|j                  |      r|j                  ||      st        d      |j                  |      s|j                  |       | j                  ||       	 | j                  | j                     |   |= y# t        $ r | j                  | j                     |= Y yw xY w)z#Unset a value in the configuration.r\   Nz4Fatal Internal error [id=1]. Please report as a bug.)r#   rf   rG   rU   rJ   r   r*   rg   remove_optionrZ   remove_sectionrk   r_   )rL   r`   ra   rm   rn   ro   r!   s          r"   unset_valuezConfiguration.unset_value   s0   c"##%~~~224v t||DNN3E::4<<77$~hZ%@AA,S1MGT""7+0D0DWd0S )J 
 <<(%%g.""5&1	2T^^,U3C8 	2T^^,S1	2s   9D #D=<D=c                r   | j                          | j                  D ]j  \  }}t        j                  d|       t	        t
        j                  j                  |             	 t        |d      5 }|j                  |       ddd       l y# 1 sw Y   xY w# t        $ r}t        d| d|       d}~ww xY w)z!Save the current in-memory state.zWriting to %swNz:An error occurred while writing to the configuration file z: )rf   rK   loggerinfor   r/   r0   dirnameopenwriteOSErrorr   )rL   rm   rn   ferrors        r"   savezConfiguration.save   s    ##%!33 	ME6KK/ rwwu-.%% $LLO$	$ $ (PgRw( s0   "B.B BB	B	B6 B11B6c                r    | j                   t        d      t        j                  d| j                          y )Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rG   r   rw   debugrR   s    r"   rf   z$Configuration._ensure_have_load_only   s+    >>!$%NOO;T^^Lr$   c                \    i }t         D ]   }|j                  | j                  |          " |S )z3A dictionary representing the loaded configuration.)rH   r^   rJ   )rL   retvalrM   s      r"   rY   zConfiguration._dictionary   s4    
 % 	1GMM$,,w/0	1 r$   c                   t        | j                               }|t        j                     dd t        j
                  gk(  rt        j                  d       y|j                         D ]q  \  }}|D ]g  }| j                  '|| j                  k7  rt        j                  d||       6| j                  ||      }| j                  |   j                  ||f       i s y)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_filesr7   r   r/   devnullrw   r   rZ   rG   
_load_filerI   append)rL   config_filesrM   filesrm   rn   s         r"   rP   z Configuration._load_config_files   s    D2245		"1Q'BJJ<7LLA *002 	?NGU 
? >>-'T^^2KLL!CUGT%8 g&--ufo>
?	?r$   c                B   t         j                  d||       | j                  |      }|j                         D ]c  }|j	                  |      }| j
                  |   j                  |i        | j
                  |   |   j                  | j                  ||             e |S )Nz'For variant '%s', will try loading '%s')	rw   verbose_construct_parsersectionsrZ   rJ   rj   r^   _normalized_keys)rL   rM   rm   rn   ro   rZ   s         r"   r   zConfiguration._load_file  s    @'5Q''.( 	WGLL)ELL!,,UB7LL!%(//0E0Egu0UV	W
 r$   c                B   t        j                         }t        j                  j	                  |      r+t        j                  d      }	 |j                  ||       |S |S # t        $ r t        d| d|      t         j                  $ r}t        |      d }~ww xY w)NF)encodingzcontains invalid z characters)reasonrm   )r~   )configparserRawConfigParserr/   r0   existslocalegetpreferredencodingreadUnicodeDecodeErrorr   Error)rL   rm   rn   locale_encodingr~   s        r"   r   zConfiguration._construct_parser"  s    --/
 77>>% $99%@O
EEO< v & 7..?{K   %% E7eDDEs   
A! !,BBBc                    | j                   t        j                     j                  di        | j                   t        j                     d   j	                  | j                  d| j                                      y)z.Loads configuration from environment variablesz:env:N)rJ   r7   r   rj   r^   r   get_environ_varsrR   s    r"   rQ   z$Configuration._load_environment_vars7  sX    U]]#..w;U]]#G,33!!'4+@+@+BC	
r$   c                J    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#   )rL   ro   rZ   
normalizedr!   valr`   s          r"   r   zConfiguration._normalized_keys>  s@     
 	"ID#C-/$"77C!JsO	" r$   c              #     K   t         j                  j                         D ]9  \  }}|j                  d      s|dd j	                         }|t
        vs4||f ; yw)z@Returns a generator with all environmental vars with prefix PIP_PIP_   N)r/   environrZ   r    r   ENV_NAMES_IGNORED)rL   r`   r   r!   s       r"   r   zConfiguration.get_environ_varsL  sU     

((* 	$HC~~f%12w}}00)O		$s   6AA	Ac              #     K   t         j                  j                  dd      }t               }t        j
                  |t        j
                     f | j                   xr$ |xr t         j                  j                  |       }|r%t        j                  |t        j                     f t        j                  |t        j                     f |t        j                  |gf yt        j                  g f 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<   r7   r   rF   r0   r   r   r   r   )rL   env_config_filer   should_load_user_configs       r"   r   zConfiguration.iter_config_filesU  s      **..):DA.0llL666 '+mm"3 #
? ?9
 #**l5::666 jj,uzz222&))o...))R-s   C<C>c                     | j                   |   S )z#Get values present in a config file)rJ   )rL   rM   s     r"   get_values_in_configz"Configuration.get_values_in_configu  s    ||G$$r$   c                t    | j                   sJ | j                  | j                      }|st        d      |d   S )Nz4Fatal Internal error [id=2]. Please report as a bug.)rG   rI   r   )rL   parserss     r"   rU   z#Configuration._get_parser_to_modifyy  s?    ~~~--/$F 
 r{r$   c                `    ||f}|| j                   vr| j                   j                  |       y y N)rK   r   )rL   rm   rn   file_parser_tuples       r"   rk   zConfiguration._mark_as_modified  s4    "FOD$:$::""))*;< ;r$   c                N    | j                   j                   d| j                  dS )N())rN   __name__rY   rR   s    r"   __repr__zConfiguration.__repr__  s'    ..))*!D,<,<+?qAAr$   r   )rF   boolrG   zKind | NonereturnNone)r   r   )r   z
str | None)r   Iterable[tuple[str, Any]])r`   strr   r   )r`   r   rl   r   r   r   )r`   r   r   r   )r   zdict[str, dict[str, Any]])rM   r   rm   r   r   r   )rm   r   r   r   )ro   r   rZ   r   r   dict[str, Any])r   zIterable[tuple[str, str]])r   z Iterable[tuple[Kind, list[str]]])rM   r   r   r   )r   ztuple[str, RawConfigParser])rm   r   rn   r   r   r   )r   r   )r   
__module____qualname____doc__rA   rS   rW   rZ   rd   rp   rt   r   rf   propertyrY   rP   r   r   rQ   r   r   r   r   rU   rk   r   __classcell__)rN   s   @r"   r>   r>   Z   s    G**(B.( 2D0M
 	 	?.	*
#<	$ @%=
Br$   r>   )r!   r   r   r   )r!   r   r   z	list[str])r   zdict[Kind, list[str]])+r   
__future__r   r   r   r/   r3   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   r2   r   r7   r   r   r   r   r   rH   rB   r   rw   r#   r*   r<   r>    r$   r"   <module>r      s    #   	 
 $  ( . 1 5..vs&)J%  				 uzz5::uyy%--O**ellEJJ6	8	&sB sBr$   