3 ”Re#7ã@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZer°dd lmZmZmZmZmZmZmZejZed eƒZeje ƒ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*|jƒjddƒ}|jdƒr&|dd…}|S)zFMake a name consistent regardless of source (environment or file) Ú_ú-z--éN)ÚlowerÚreplaceÚ startswith)Úname©rúŠ/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/configuration.pyÚ_normalize_name*s  rcCs&d|krdj|ƒ}t|ƒ‚|jddƒ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„tjdƒDƒ}tjjtjtƒ}tjjtdƒt r8dndtƒ}tjjtj dƒtƒ}t j |t j |gt j||giS)NcSsg|]}tjj|tƒ‘qSr)ÚosÚpathÚjoinÚCONFIG_BASENAME)Ú.0r-rrrú Osz+get_configuration_files..Ú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. Ncs¨tt|ƒjƒtjtjtjdg}||krJtdjdj t t |dd …ƒƒƒƒ‚||_ ||_ tjtjtjtjtjg|_ddg|_dd„|jDƒ|_dd„|jDƒ|_g|_dS) Nz5Got invalid value for load_only - should be one of {}z, rÚversionÚhelpcSsi|] }g|“qSrr)r0Úvariantrrrú ‡sz*Configuration.__init__..cSsi|] }i|“qSrr)r0rArrrrBŠséÿÿÿÿ)Úsuperr>Ú__init__r8r'r(r)rrr.ÚmapÚreprÚisolatedÚ load_onlyr*r+Ú_override_orderÚ_ignore_env_namesÚ_parsersÚ_configÚ_modified_parsers)ÚselfrHrIÚ_valid_load_only)Ú __class__rrrEqs   zConfiguration.__init__cCs|jƒ|js|jƒdS)zELoads configuration from configuration files and environment N)Ú_load_config_filesrHÚ_load_environment_vars)rOrrrÚload�szConfiguration.loadc Cs8|jdk stdƒ‚y |jƒdStk r2dSXdS)z@Returns the file with highest priority in configuration Nz)Need to be specified a file to be editingr)rIÚAssertionErrorÚ_get_parser_to_modifyÚ IndexError)rOrrrÚget_file_to_edit—s   zConfiguration.get_file_to_editcCs |jjƒS)z`Returns key-value pairs like dict.items() representing the loaded configuration )Ú _dictionaryÚitems)rOrrrrZ£szConfiguration.itemsc Cs2y |j|Stk r,tdj|ƒƒ‚YnXdS)z,Get a value from the configuration. zNo such key - {}N)rYÚKeyErrorrr)rOÚkeyrrrÚ get_valueªs zConfiguration.get_valuecCst|jƒ|jst‚|jƒ\}}|dk rTt|ƒ\}}|j|ƒsF|j|ƒ|j|||ƒ||j|j|<|j ||ƒdS)z-Modify a value in the configuration. N) Ú_ensure_have_load_onlyrIrUrVr"Ú has_sectionÚ add_sectionÚsetrMÚ_mark_as_modified)rOr\ÚvalueÚfnameÚparserÚsectionrrrrÚ set_value³s     zConfiguration.set_valuecCs |jƒ|jst‚||j|jkr0tdj|ƒƒ‚|jƒ\}}|dk rŽt|ƒ\}}|j|ƒod|j ||ƒsntdƒ‚|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_optionrZÚremove_sectionrb)rOr\rdrerfrrrrÚ unset_valueÇs        zConfiguration.unset_valuec Cs\|jƒxN|jD]D\}}tjd|ƒttjj|ƒƒt|dƒ�}|j |ƒWdQRXqWdS)z*Save the current in-memory state. z Writing to %sÚwN) r^rNÚloggerÚinforr,r-ÚdirnameÚopenÚwrite)rOrdreÚfrrrÚsaveâs   zConfiguration.savecCs$|jdkrtdƒ‚tjd|jƒdS)Nz'Needed a specific file to be modifying.z$Will be working with %s variant only)rIrrlÚdebug)rOrrrr^õs z$Configuration._ensure_have_load_onlycCs(i}x|jD]}|j|j|ƒq W|S)zWdS)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,ÚdevnullrlrsrZrIÚ _load_filerLÚappend)rOÚ config_filesrAÚfilesrdrerrrrR s    z Configuration._load_config_filescCsPtjd||ƒ|j|ƒ}x2|jƒD]&}|j|ƒ}|j|j|j||ƒƒq"W|S)Nz'For variant '%s', will try loading '%s')rlrsÚ_construct_parserÚsectionsrZrMrtÚ_normalized_keys)rOrArdrerfrZrrrry$s   zConfiguration._load_filecCs€tjƒ}tjj|ƒr|y|j|ƒWnXtk rNtdjt j dƒƒ|d�‚Yn.tj k rz}zt|d�‚WYdd}~XnX|S)Nzcontains invalid {} charactersF)Úreasonrd)Úerror) rÚRawConfigParserr,r-ÚexistsÚreadÚUnicodeDecodeErrorrrÚlocaleÚgetpreferredencodingÚError)rOrdrer�rrrr}/s   zConfiguration._construct_parsercCs"|jtjj|jd|jƒƒƒdS)z7Loads configuration from environment variables z:env:N)rMr8r+rtrÚget_environ_vars)rOrrrrSFs z$Configuration._load_environment_varscCs2i}x(|D] \}}|dt|ƒ}|||<q W|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)rOrfrZÚ normalizedrÚvalr\rrrrNs  zConfiguration._normalized_keysccsVxPtjjƒD]B\}}|jdƒo2|dd…jƒ|jk}|r |dd…jƒ|fVq WdS)z@Returns a generator with all environmental vars with prefix PIP_ÚPIP_éN)r,ÚenvironrZrrrK)rOr\r‹Úshould_be_yieldedrrrr‰[s  zConfiguration.get_environ_varsccs�tjjddƒ}|dk r&tj|gfVn tjgfVtƒ}tj|tjfV|j ob|o`tjj |ƒ }|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(rHr-rƒr'r))rOÚ config_filer{Úshould_load_user_configrrrrwgs  zConfiguration.iter_config_filescCs |j|S)z#Get values present in a config file)rM)rOrArrrÚ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.rrC)rIrUrLr)rOÚparsersrrrrV‹s   z#Configuration._get_parser_to_modifycCs"||f}||jkr|jj|ƒdS)N)rNrz)rOrdreÚfile_parser_tuplerrrrbšs zConfiguration._mark_as_modifiedcCsdj|jj|jƒS)Nz{}({!r}))rrQÚ__name__rY)rOrrrÚ__repr__ szConfiguration.__repr__)N)r—Ú __module__Ú __qualname__Ú__doc__rErTrXrZr]rgrjrrr^ÚpropertyrYrRryr}rSrr‰rwr”rVrbr˜Ú __classcell__rr)rQrr>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—rlrr"r8r/r=Úobjectr>rrrrÚ s4   $