本文整理汇总了Python中six.moves.configparser.ParsingError方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.ParsingError方法的具体用法?Python configparser.ParsingError怎么用?Python configparser.ParsingError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser
的用法示例。
在下文中一共展示了configparser.ParsingError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import ParsingError [as 别名]
def __init__(self, path=None, stream_log_level=None):
RawConfigParser.__init__(self)
self._clients = {}
self.path = path or os.getenv('HDFSCLI_CONFIG', self.default_path)
if stream_log_level:
stream_handler = lg.StreamHandler()
stream_handler.setLevel(stream_log_level)
fmt = '%(levelname)s\t%(message)s'
stream_handler.setFormatter(lg.Formatter(fmt))
lg.getLogger().addHandler(stream_handler)
if osp.exists(self.path):
try:
self.read(self.path)
except ParsingError:
raise HdfsError('Invalid configuration file %r.', self.path)
else:
self._autoload()
_logger.info('Instantiated configuration from %r.', self.path)
else:
_logger.info('Instantiated empty configuration.')
示例2: from_file
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import ParsingError [as 别名]
def from_file(cls, filename, source):
"""
Load a theme from the specified configuration file.
Parameters:
filename: The name of the filename to load.
source: A description of where the theme was loaded from.
"""
_logger.info('Loading theme %s', filename)
try:
config = configparser.ConfigParser()
config.optionxform = six.text_type # Preserve case
with codecs.open(filename, encoding='utf-8') as fp:
config.readfp(fp)
except configparser.ParsingError as e:
raise ConfigError(e.message)
if not config.has_section('theme'):
raise ConfigError(
'Error loading {0}:\n'
' missing [theme] section'.format(filename))
theme_name = os.path.basename(filename)
theme_name, _ = os.path.splitext(theme_name)
elements = {}
for element, line in config.items('theme'):
if element not in cls.DEFAULT_ELEMENTS:
# Could happen if using a new config with an older version
# of the software
_logger.info('Skipping element %s', element)
continue
elements[element] = cls._parse_line(element, line, filename)
return cls(name=theme_name, source=source, elements=elements)
示例3: do_ansible_cfg
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import ParsingError [as 别名]
def do_ansible_cfg(self, code):
self.ansible_cfg = str(code)
# Test that the code for ansible.cfg is parsable. Do not write the file yet.
try:
config = configparser.SafeConfigParser()
if self.ansible_cfg is not None:
config.readfp(six.StringIO(self.ansible_cfg))
except configparser.ParsingError as e:
return self.send_error(e, 0)
logger.info("ansible.cfg set to %s", code)
return {'status': 'ok', 'execution_count': self.execution_count,
'payload': [], 'user_expressions': {}}
示例4: _load_config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import ParsingError [as 别名]
def _load_config(cls, conf_file):
'''Private method only to be called once from the __init__ module'''
cls._translator_config = configparser.ConfigParser()
try:
cls._translator_config.read(conf_file)
except configparser.ParsingError:
msg = _('Unable to parse translator.conf file.'
'Check to see that it exists in the conf directory.')
raise exception.ConfFileParseError(message=msg)