Exemple #1
0
 def _construct_parser(self, fname):
     # type: (str) -> RawConfigParser
     parser = configparser.RawConfigParser()
     # If there is no such file, don't bother reading it but create the
     # parser anyway, to hold the data.
     # Doing this is useful when modifying and saving files, where we don't
     # need to construct a parser.
     if os.path.exists(fname):
         try:
             parser.read(fname)
         except UnicodeDecodeError:
             raise ConfigurationError((
                 "ERROR: "
                 "Configuration file contains invalid %s characters.\n"
                 "Please fix your configuration, located at %s\n"
             ) % (locale.getpreferredencoding(False), fname))
     return parser
Exemple #2
0
 def switch(self, dest, url, rev_options):
     # type: (str, HiddenText, RevOptions) -> None
     repo_config = os.path.join(dest, self.dirname, 'hgrc')
     config = configparser.RawConfigParser()
     try:
         config.read(repo_config)
         config.set('paths', 'default', url.secret)
         with open(repo_config, 'w') as config_file:
             config.write(config_file)
     except (OSError, configparser.NoSectionError) as exc:
         logger.warning(
             'Could not switch Mercurial repository to %s: %s',
             url,
             exc,
         )
     else:
         cmd_args = make_command('update', '-q', rev_options.to_args())
         self.run_command(cmd_args, cwd=dest)
Exemple #3
0
 def _construct_parser(self, fname):
     # type: (str) -> RawConfigParser
     parser = configparser.RawConfigParser()
     # If there is no such file, don't bother reading it but create the
     # parser anyway, to hold the data.
     # Doing this is useful when modifying and saving files, where we don't
     # need to construct a parser.
     if os.path.exists(fname):
         try:
             parser.read(fname)
         except UnicodeDecodeError:
             # See https://github.com/pypa/pip/issues/4963
             raise ConfigurationFileCouldNotBeLoaded(
                 reason="contains invalid {} characters".format(
                     locale.getpreferredencoding(False)),
                 fname=fname,
             )
         except configparser.Error as error:
             # See https://github.com/pypa/pip/issues/4893
             raise ConfigurationFileCouldNotBeLoaded(error=error)
     return parser