Re#7 @sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZerdd lmZmZmZmZmZmZmZejZed eZeje Z!d d Z"d dZ#eddddddddddZ$e rTdndZ%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;|jjdd}|jdr7|dd}|S)zFMake a name consistent regardless of source (environment or file) _-z--N)lowerreplace startswith)namer/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/configuration.py_normalize_name*srcCs7d|kr'dj|}t||jddS)N.zbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?)formatrsplit)r error_messagerrr_disassemble_key4s    r"USERuserGLOBALglobalSITEsiteENVenvENV_VARzenv-varzpip.inizpip.confcCsddtjdD}tjjtjt}tjjtdt rRdndt}tjjtj dt}t j |t j |gt j||giS)NcSs%g|]}tjj|tqSr)ospathjoinCONFIG_BASENAME).0r-rrr Os z+get_configuration_files..pip~z.pip)rsite_config_dirsr,r-r.sysprefixr/rruser_config_dirkindsr%r'r#)global_config_filessite_config_filelegacy_config_filenew_config_filerrrget_configuration_filesLs       r=cs!eZdZdZdfddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZS)- 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. Ncstt|jtjtjtjdg}||krktdjdj t t |dd ||_ ||_ tjtjtjtjtjg|_ddg|_dd|jD|_dd|jD|_g|_dS) Nz5Got invalid value for load_only - should be one of {}z, rversionhelpcSsi|]}g|qSrr)r0variantrrr s z*Configuration.__init__..cSsi|]}i|qSrr)r0rArrrrBs )superr>__init__r8r#r%r'rrr.mapreprisolated load_onlyr)r+_override_order_ignore_env_names_parsers_config_modified_parsers)selfrHrI_valid_load_only) __class__rrrEqs (  '  zConfiguration.__init__cCs!|j|js|jdS)zELoads configuration from configuration files and environment N)_load_config_filesrH_load_environment_vars)rOrrrloads  zConfiguration.loadc CsJ|jdk stdy|jdSWntk rEdSYnXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rIAssertionError_get_parser_to_modify IndexError)rOrrrget_file_to_edits   zConfiguration.get_file_to_editcCs |jjS)z`Returns key-value pairs like dict.items() representing the loaded configuration ) _dictionaryitems)rOrrrrZszConfiguration.itemsc Cs=y|j|SWn'tk r8tdj|YnXdS)z,Get a value from the configuration. zNo such key - {}N)rYKeyErrorrr)rOkeyrrr get_values zConfiguration.get_valuecCs|j|jst|j\}}|dk rxt|\}}|j|se|j||j|||||j|j|<|j ||dS)z-Modify a value in the configuration. N) _ensure_have_load_onlyrIrUrVr" has_section add_sectionsetrM_mark_as_modified)rOr\valuefnameparsersectionrrrr set_values   zConfiguration.set_valuecCs|j|jst||j|jkrDtdj||j\}}|dk rt|\}}|j|o|j ||std|j |s|j ||j |||j|j|=dS)z#Unset a value in the configuration.zNo such key - {}Nz4Fatal Internal error [id=1]. Please report as a bug.) r^rIrUrMrrrVr"r_ remove_optionrZremove_sectionrb)rOr\rdrerfrrrr unset_values    zConfiguration.unset_valuec Cst|jxc|jD]X\}}tjd|ttjj|t|d}|j |WdQRXqWdS)z*Save the current in-memory state. z Writing to %swN) r^rNloggerinforr,r-dirnameopenwrite)rOrdrefrrrsaves  zConfiguration.savecCs2|jdkrtdtjd|jdS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rIrrldebug)rOrrrr^s z$Configuration._ensure_have_load_onlycCs2i}x%|jD]}|j|j|qW|S)zcs,              r>))rrloggingr,r5pip._vendor.six.movesrpip._internal.exceptionsrrZpip._internal.utilsrpip._internal.utils.compatrrpip._internal.utils.miscrr pip._internal.utils.typingr typingr r r rrrrrstrr getLoggerrrlrr"r8r/r=objectr>rrrr s4    4