ó ÿ¾v]c @szdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZddlmZerýdd lmZmZmZmZmZmZmZejZed eƒZneje ƒZ!d „Z"d „Z#ed dddddddddƒZ$e rQdndZ%d„Z&de'fd„ƒYZ(dS(s 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 iÿÿÿÿN(t configparser(tConfigurationErrort!ConfigurationFileCouldNotBeLoaded(tappdirs(tWINDOWSt expanduser(t ensure_dirtenum(tMYPY_CHECK_RUNNING(tAnytDicttIterabletListtNewTypetOptionaltTupletKindcCs8|jƒjddƒ}|jdƒr4|d}n|S(sFMake a name consistent regardless of source (environment or file) t_t-s--i(tlowertreplacet startswith(tname((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyt_normalize_name)s cCs:d|kr*dj|ƒ}t|ƒ‚n|jddƒS(Nt.sbKey does not contain dot separated section and key. Perhaps you wanted to use 'global.{}' instead?i(tformatRtsplit(Rt error_message((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyt_disassemble_key3s   tUSERtusertGLOBALtglobaltSITEtsitetENVtenvtENV_VARsenv-varspip.inispip.confcCs¼gtjdƒD]}tjj|tƒ^q}tjjtjtƒ}tjjtdƒt rgdndtƒ}tjjtj dƒtƒ}i|t j 6|gt j 6||gt j6S(Ntpipt~s.pip(Rtsite_config_dirstostpathtjointCONFIG_BASENAMEtsystprefixRRtuser_config_dirtkindsRR!R(R*tglobal_config_filestsite_config_filetlegacy_config_filetnew_config_file((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pytget_configuration_filesKs.      t ConfigurationcBsÂeZdZdd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z e d „ƒZd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„ZRS(sâ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. cCsétt|ƒjƒtjtjtjdg}||krhtdj dj t t |d ƒƒƒƒ‚n||_ ||_tjtjtjtjtjg|_ddg|_d„|jDƒ|_d„|jDƒ|_g|_dS(Ns5Got invalid value for load_only - should be one of {}s, iÿÿÿÿtversionthelpcSsi|]}g|“qS(((t.0tvariant((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pys †s cSsi|]}i|“qS(((R9R:((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pys ‰s (tsuperR6t__init__R0RRR!tNoneRRR+tmaptreprtisolatedt load_onlyR#R%t_override_ordert_ignore_env_namest_parserst_configt_modified_parsers(tselfR@RAt_valid_load_only((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyR<os %  'cCs$|jƒ|js |jƒndS(sELoads configuration from configuration files and environment N(t_load_config_filesR@t_load_environment_vars(RG((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pytloads  cCsF|jdk stdƒ‚y|jƒdSWntk rAdSXdS(s@Returns the file with highest priority in configuration s)Need to be specified a file to be editingiN(RAR=tAssertionErrort_get_parser_to_modifyt IndexError(RG((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pytget_file_to_edit•s   cCs |jjƒS(s`Returns key-value pairs like dict.items() representing the loaded configuration (t _dictionarytitems(RG((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRQ¡scCs<y|j|SWn&tk r7tdj|ƒƒ‚nXdS(s,Get a value from the configuration. sNo such key - {}N(RPtKeyErrorRR(RGtkey((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyt get_value¨s cCs—|jƒ|jƒ\}}|dk rot|ƒ\}}|j|ƒsY|j|ƒn|j|||ƒn||j|j|<|j ||ƒdS(s-Modify a value in the configuration. N( t_ensure_have_load_onlyRMR=Rt has_sectiont add_sectiontsetRERAt_mark_as_modified(RGRStvaluetfnametparsertsectionR((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyt set_value±s  c Cs*|jƒ||j|jkr8tdj|ƒƒ‚n|jƒ\}}|dk rt|ƒ\}}t}|j |ƒr’|j ||ƒ}n|rt |j |ƒƒ}yt |ƒ}Wntk rÖd}nX|dkró|j|ƒn|j||ƒqtdƒ‚n|j|j|=dS(s,Unset a value in the configuration. sNo such key - {}s4Fatal Internal error [id=1]. Please report as a bug.N(RURERARRRMR=RtFalseRVt remove_optiontiterRQtnextt StopIterationtremove_sectionRY( RGRSR[R\R]Rtmodified_somethingt section_itertval((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyt unset_valueÄs*      cCss|jƒxb|jD]W\}}tjd|ƒttjj|ƒƒt|dƒ}|j |ƒWdQXqWdS(s*Save the current in-memory state. s Writing to %stwN( RURFtloggertinfoRR)R*tdirnametopentwrite(RGR[R\tf((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pytsaveës  cCs5|jdkrtdƒ‚ntjd|jƒdS(Ns'Needed a specific file to be modifying.s$Will be working with %s variant only(RAR=RRjtdebug(RG((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRUþscCs2i}x%|jD]}|j|j|ƒqW|S(s<A dictionary representing the loaded configuration. (RBtupdateRE(RGtretvalR:((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRPscCsØt|jƒƒ}|tjdd!tjgkrCtjdƒdSxŽ|jƒD]€\}}xq|D]i}|j dk r ||j kr tjd||ƒqcn|j ||ƒ}|j |j ||fƒqcWqPWdS(s5Loads configuration from configuration files iisZSkipping loading configuration files due to environment's PIP_CONFIG_FILE being os.devnullNs Skipping file '%s' (variant: %s)(tdictt_iter_config_filesR0R#R)tdevnullRjRqRQRAR=t _load_fileRDtappend(RGt config_filesR:tfilesR[R\((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRIs   cCsltjd||ƒ|j|ƒ}xC|jƒD]5}|j|ƒ}|j|j|j||ƒƒq/W|S(Ns'For variant '%s', will try loading '%s'(RjRqt_construct_parsertsectionsRQRERrt_normalized_keys(RGR:R[R\R]RQ((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRw-s $cCs•tjƒ}tjj|ƒr‘y|j|ƒWq‘tk ritddjt j t ƒƒd|ƒ‚q‘tj k r}td|ƒ‚q‘Xn|S(Ntreasonscontains invalid {} charactersR[terror( RtRawConfigParserR)R*texiststreadtUnicodeDecodeErrorRRtlocaletgetpreferredencodingR_tError(RGR[R\R((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyR{8s   cCs-|jtjj|jd|jƒƒƒdS(s7Loads configuration from environment variables s:env:N(RER0R%RrR}t_get_environ_vars(RG((s:/tmp/pip-install-vZZv26/pip/pip/_internal/configuration.pyRJOscCs?i}x2|D]*\}}|dt|ƒ}||| s4    4