本文整理匯總了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