当前位置: 首页>>代码示例>>Python>>正文


Python configparser.ParsingError方法代码示例

本文整理汇总了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.') 
开发者ID:mtth,项目名称:hdfs,代码行数:22,代码来源:config.py

示例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) 
开发者ID:tildeclub,项目名称:ttrv,代码行数:38,代码来源:theme.py

示例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': {}} 
开发者ID:ansible,项目名称:ansible-jupyter-kernel,代码行数:14,代码来源:kernel.py

示例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) 
开发者ID:openstack,项目名称:heat-translator,代码行数:12,代码来源:config.py


注:本文中的six.moves.configparser.ParsingError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。