U ÀÒ.eŠ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ú?/usr/lib/python3.8/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)rZ error_messagerrrÚ_disassemble_key8sÿýr!ÚuserÚglobalZsiteÚ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Ú Qsÿz+get_configuration_files..Zpipú~z.pip)rZsite_config_dirsr*r+r,ÚsysÚprefixr-rrZuser_config_dirÚkindsr&r'r%)Zglobal_config_filesZsite_config_fileZlegacy_config_fileZnew_config_filerrrÚget_configuration_filesPs(þ ýÿýr4cs¶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(„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©r.ÚvariantrrrÚ Šsz*Configuration.__init__..cSsi|] }|i“qSrrr9rrrr;�s)Úsuperr5Ú__init__r3r%r&r'rrr,ÚmapÚreprÚisolatedÚ load_onlyr(r)Ú_override_orderÚ_ignore_env_namesÚ_parsersÚ_configÚ_modified_parsers)Úselfr@rAZ_valid_load_only©Ú __class__rrr=ts0ÿÿÿ ÿÿzConfiguration.__init__cCs| ¡|js| ¡dS)zELoads configuration from configuration files and environment N)Ú_load_config_filesr@Ú_load_environment_vars©rGrrrÚ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)rAÚAssertionErrorÚ_get_parser_to_modifyÚ IndexErrorrLrrrÚ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ÚitemsrLrrrrS¦szConfiguration.itemscCs4z |j|WStk r.td |¡ƒ‚YnXdS)z,Get a value from the configuration. úNo such key - {}N)rRÚKeyErrorrr)rGÚkeyrrrÚ get_value­s zConfiguration.get_valuecCsj| ¡| ¡\}}|dk rJt|ƒ\}}| |¡s<| |¡| |||¡||j|j|<| ||¡dS)z-Modify a value in the configuration. N) Ú_ensure_have_load_onlyrOr!Ú has_sectionZ add_sectionÚsetrErAÚ_mark_as_modified)rGrVÚvalueÚfnameÚparserÚsectionrrrrÚ set_value¶s    zConfiguration.set_valuec CsÒ| ¡||j|jkr&td |¡ƒ‚| ¡\}}|dk rÀt|ƒ\}}d}| |¡r`| ||¡}|r¸t |  |¡ƒ}z t |ƒ}Wnt k r–d}YnX|dkrª|  |¡| ||¡ntdƒ‚|j|j|=dS)z,Unset a value in the configuration. rTNFz4Fatal Internal error [id=1]. Please report as a bug.)rXrErArrrOr!rYZ remove_optionÚiterrSÚnextÚ StopIterationZremove_sectionr[) rGrVr]r^r_rZmodified_somethingZ section_iterÚvalrrrÚ 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) rXrFÚloggerÚinforr*r+ÚdirnameÚopenÚwrite)rGr]r^Ú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)rArrgÚdebugrLrrrrXs z$Configuration._ensure_have_load_onlycCs$i}|jD]}| |j|¡q |S)zs6   $    û