Python six.moves.configparser.ParsingError() Examples

The following are 5 code examples of six.moves.configparser.ParsingError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module six.moves.configparser , or try the search function .
Example #1
Source File: config.py    From hdfs with MIT License 6 votes vote down vote up
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.') 
Example #2
Source File: theme.py    From ttrv with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: kernel.py    From ansible-jupyter-kernel with Apache License 2.0 5 votes vote down vote up
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': {}} 
Example #4
Source File: config.py    From heat-translator with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: theme.py    From rtv with MIT License 5 votes vote down vote up
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)