U .e7@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZerdd lmZmZmZmZmZmZmZejZed eZee Z!d d Z"d dZ#eddddddZ$e rdndZ%ddZ&Gddde'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_direnum)MYPY_CHECK_RUNNING)AnyDictIterableListNewTypeOptionalTupleKindcCs*|dd}|dr&|dd}|S)zFMake a name consistent regardless of source (environment or file) _-z--N)lowerreplace startswith)namer?/usr/lib/python3.8/site-packages/pip/_internal/configuration.py_normalize_name.s  rcCs&d|krd|}t||ddS)N.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?)formatrsplit)rZ error_messagerrr_disassemble_key8sr!userglobalZsiteenvzenv-var)USERGLOBALSITEENVENV_VARzpip.inizpip.confcCspddtdD}tjtjt}tjtdt r8dndt}tjt dt}t j |t j |gt j||giS)NcSsg|]}tj|tqSr)ospathjoinCONFIG_BASENAME).0r+rrr Qsz+get_configuration_files..Zpip~z.pip)rZsite_config_dirsr*r+r,sysprefixr-rrZuser_config_dirkindsr&r'r%)Zglobal_config_filesZsite_config_fileZlegacy_config_fileZnew_config_filerrrget_configuration_filesPs( r4cseZdZdZd)fdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(ZZS)* ConfigurationaHandles 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 stt|tjtjtjdg}||krJtdd t t |dd||_ ||_ tjtjtjtjtjg|_ddg|_dd|jD|_dd|jD|_g|_dS) Nz5Got invalid value for load_only - should be one of {}z, versionhelpcSsi|] }|gqSrrr.variantrrr sz*Configuration.__init__..cSsi|] }|iqSrrr9rrrr;s)superr5__init__r3r%r&r'rrr,mapreprisolated 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_varsrGrrrloadszConfiguration.loadcCs<|jdk stdz|dWStk r6YdSXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rAAssertionError_get_parser_to_modify IndexErrorrLrrrget_file_to_edits zConfiguration.get_file_to_editcCs |jS)z`Returns key-value pairs like dict.items() representing the loaded configuration ) _dictionaryitemsrLrrrrSszConfiguration.itemscCs4z |j|WStk r.td|YnXdS)z,Get a value from the configuration. No such key - {}N)rRKeyErrorrr)rGkeyrrr get_values zConfiguration.get_valuecCsj||\}}|dk rJt|\}}||s<||||||||j|j|<|||dS)z-Modify a value in the configuration. N) _ensure_have_load_onlyrOr! has_sectionZ add_sectionsetrErA_mark_as_modified)rGrVvaluefnameparsersectionrrrr set_values    zConfiguration.set_valuec Cs|||j|jkr&td||\}}|dk rt|\}}d}||r`|||}|rt | |}z t |}Wnt k rd}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_optioniterrSnext StopIterationZremove_sectionr[) rGrVr]r^r_rZmodified_somethingZ section_itervalrrr unset_values,       zConfiguration.unset_valuec CsX||jD]D\}}td|ttj|t|d}| |W5QRXqdS)z*Save the current in-memory state. z Writing to %swN) rXrFloggerinforr*r+dirnameopenwrite)rGr]r^frrrsaves   zConfiguration.savecCs$|jdkrtdtd|jdS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rArrgdebugrLrrrrXs z$Configuration._ensure_have_load_onlycCs$i}|jD]}||j|q |S)zs6   $