本文整理汇总了Python中configparser.InterpolationError方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.InterpolationError方法的具体用法?Python configparser.InterpolationError怎么用?Python configparser.InterpolationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser
的用法示例。
在下文中一共展示了configparser.InterpolationError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deserialize
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationError [as 别名]
def deserialize(self, serialized: str) -> None:
"""Extract data from string and store it in the Configuration parser."""
updated_preferences = self.__updateSerialized(serialized)
self._parser = configparser.ConfigParser(interpolation = None)
try:
self._parser.read_string(updated_preferences)
except (configparser.MissingSectionHeaderError, configparser.DuplicateOptionError, configparser.DuplicateSectionError, configparser.ParsingError, configparser.InterpolationError) as e:
Logger.log("w", "Could not deserialize preferences file: {error}".format(error = str(e)))
self._parser = None
return
has_version = "general" in self._parser and "version" in self._parser["general"]
if has_version:
if self._parser["general"]["version"] != str(Preferences.Version):
Logger.log("w", "Could not deserialize preferences from loaded project")
self._parser = None
return
else:
return
self.__initializeSettings()
示例2: test_interpolationerror
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationError [as 别名]
def test_interpolationerror(self):
import pickle
e1 = configparser.InterpolationError('option', 'section', 'msg')
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(e1, proto)
e2 = pickle.loads(pickled)
self.assertEqual(e1.message, e2.message)
self.assertEqual(e1.args, e2.args)
self.assertEqual(e1.section, e2.section)
self.assertEqual(e1.option, e2.option)
self.assertEqual(repr(e1), repr(e2))
示例3: get_aliases
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationError [as 别名]
def get_aliases(config):
"""Add aliases from the configfile to the ALIASES section of settings.
Args:
config: configparser.ConfigParser of the configfile.
Return:
aliases: Dictionary of aliases.
message: Error message filled with aliases that cannot be parsed.
"""
message = ""
aliases = {}
try:
alias_section = config["ALIASES"]
except KeyError:
# Default to no aliases if the section does not exist in the configfile
alias_section = dict()
for alias in alias_section:
try:
aliases[alias] = alias_section[alias]
except configparser.InterpolationError as e:
message += "Parsing alias '%s' failed.\n" % alias \
+ "If you meant to use % for current file, use %%.\n" \
+ e.message + "\n"
return aliases, message