zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
U
H=®d#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úRD:\z\workplace\VsCode\pyvenv\venv\Lib\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)rÚ error_messagerrrÚ_disassemble_key4sÿýr"ÚuserÚglobalÚsiteÚ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Ú
<listcomp>Nsÿz+get_configuration_files.<locals>.<listcomp>Úpipú~z.pip)rÚsite_config_dirsr,r-r.ÚsysÚprefixr/rrÚuser_config_dirÚkindsr(r)r')Úglobal_config_filesÚsite_config_fileÚlegacy_config_fileÚnew_config_filerrrÚget_configuration_filesLs(þ
ýÿýr=csÆ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(„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©r0ÚvariantrrrÚ
<dictcomp>‡sz*Configuration.__init__.<locals>.<dictcomp>cSsi|]
}|i“qSrrrBrrrrDŠs)Úsuperr>Ú__init__r8r'r(r)rrr.ÚmapÚreprÚisolatedÚ    load_onlyr*r+Ú_override_orderÚ_ignore_env_namesÚ_parsersÚ_configÚ_modified_parsers)ÚselfrIrJÚ_valid_load_only©Ú    __class__rrrFqs0ÿÿÿ
ÿÿzConfiguration.__init__cCs| ¡|js| ¡dS)zELoads configuration from configuration files and environment
        N)Ú_load_config_filesrIÚ_load_environment_vars©rPrrrÚ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)rJÚAssertionErrorÚ_get_parser_to_modifyÚ
IndexErrorrVrrrÚ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ÚitemsrVrrrr]£szConfiguration.itemscCs4z |j|WStk
r.td |¡ƒ‚YnXdS)z,Get a value from the configuration.
        úNo such key - {}N)r\ÚKeyErrorrr)rPÚkeyrrrÚ    get_valueªs zConfiguration.get_valuecCst| ¡|jst‚| ¡\}}|dk    rTt|ƒ\}}| |¡sF| |¡| |||¡||j|j|<|     ||¡dS)z-Modify a value in the configuration.
        N)
Ú_ensure_have_load_onlyrJrXrYr"Ú has_sectionÚ add_sectionÚsetrNÚ_mark_as_modified)rPr`ÚvalueÚfnameÚparserÚsectionrrrrÚ    set_value³s
 
 
zConfiguration.set_valuecCs | ¡|jst‚||j|jkr0td |¡ƒ‚| ¡\}}|dk    rŽt|ƒ\}}| |¡rf|     ||¡sntdƒ‚| 
|¡s‚|  |¡|  ||¡|j|j|=dS)z#Unset a value in the configuration.r^Nz4Fatal Internal error [id=1]. Please report as a bug.) rbrJrXrNrrrYr"rcÚ remove_optionr]Úremove_sectionrf)rPr`rhrirjrrrrÚ 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)
rbrOÚloggerÚinforr,r-ÚdirnameÚopenÚwrite)rPrhriÚ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)rJrrpÚdebugrVrrrrbõs
z$Configuration._ensure_have_load_onlycCs$i}|jD]}| |j|¡q
|S)z<A dictionary representing the loaded configuration.
        )rKÚupdaterN)rPÚretvalrCrrrr\ûs
zConfiguration._dictionarycCs˜t| ¡ƒ}|tjdd…tjgkr4t d¡dS| ¡D]V\}}|D]H}|j    dk    rp||j    krpt d||¡qH| 
||¡}|j |  ||f¡qHq<dS)z5Loads configuration from configuration files
        rrzZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNz Skipping file '%s' (variant: %s)) ÚdictÚiter_config_filesr8r*r,Údevnullrprwr]rJÚ
_load_filerMÚappend)rPÚ config_filesrCÚfilesrhrirrrrT    s" ÿÿ z Configuration._load_config_filescCsLt d||¡| |¡}| ¡D]&}| |¡}|j| | ||¡¡q |S)Nz'For variant '%s', will try loading '%s')rprwÚ_construct_parserÚsectionsr]rNrxÚ_normalized_keys)rPrCrhrirjr]rrrr}$s 
 
zConfiguration._load_filec
Cs€t ¡}tj |¡r|z| |¡WnXtk
rNtd t     
d¡¡|d‚Yn.tj k
rz}zt|d‚W5d}~XYnX|S)Nzcontains invalid {} charactersF)Úreasonrh)Úerror) rÚRawConfigParserr,r-ÚexistsÚreadÚUnicodeDecodeErrorrrÚlocaleÚgetpreferredencodingÚError)rPrhrir…rrrr/s ÿü
zConfiguration._construct_parsercCs"|jtj | d| ¡¡¡dS)z7Loads configuration from environment variables
        z:env:N)rNr8r+rxrƒÚget_environ_varsrVrrrrUFs ÿz$Configuration._load_environment_varscCs.i}|D] \}}|dt|ƒ}|||<q|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)rPrjr]Ú
normalizedrÚvalr`rrrrƒNs
 
zConfiguration._normalized_keysccsRtj ¡D]B\}}| d¡o0|dd… ¡|jk}|r
|dd… ¡|fVq
dS)z@Returns a generator with all environmental vars with prefix PIP_ÚPIP_éN)r,Úenvironr]rrrL)rPr`rÚshould_be_yieldedrrrr[s 
þzConfiguration.get_environ_varsccstj dd¡}|dk    r&tj|gfVn tjgfVtƒ}tj|tjfV|j ob|o`tj     |¡ }|rztj
|tj
fVtj |tj fVdS)zYields variant and configuration files associated with it.
 
        This should be treated like items of a dictionary.
        ÚPIP_CONFIG_FILEN) r,r’Úgetr8r*r=r(rIr-r‡r'r))rPÚ config_filerÚshould_load_user_configrrrr{gs     ÿzConfiguration.iter_config_filescCs
|j|S)z#Get values present in a config file)rN)rPrCrrrÚget_values_in_config†sz"Configuration.get_values_in_configcCs*|js
t‚|j|j}|s"tdƒ‚|dS)Nz4Fatal Internal error [id=2]. Please report as a bug.r?)rJrXrMr)rPÚparsersrrrrY‹s
 ÿz#Configuration._get_parser_to_modifycCs"||f}||jkr|j |¡dS)N)rOr~)rPrhriÚfile_parser_tuplerrrrfšs
zConfiguration._mark_as_modifiedcCsd |jj|j¡S)Nz{}({!r}))rrSÚ__name__r\rVrrrÚ__repr__ szConfiguration.__repr__)N)r›Ú
__module__Ú __qualname__Ú__doc__rFrWr[r]rarkrnrvrbÚpropertyr\rTr}rrUrƒrr{r˜rYrfrœÚ __classcell__rrrRrr>cs.      
   r>))rŸrŠÚloggingr,r5Úpip._vendor.six.movesrÚpip._internal.exceptionsrrZpip._internal.utilsrÚpip._internal.utils.compatrrÚpip._internal.utils.miscrr    Úpip._internal.utils.typingr
Útypingr r r rrrrr†ÚstrrÚ    getLoggerr›rprr"r8r/r=Úobjectr>rrrrÚ<module>s6    $
 
 
 û