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


Python parser.ParserError方法代码示例

本文整理汇总了Python中yaml.parser.ParserError方法的典型用法代码示例。如果您正苦于以下问题:Python parser.ParserError方法的具体用法?Python parser.ParserError怎么用?Python parser.ParserError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml.parser的用法示例。


在下文中一共展示了parser.ParserError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_environment_from_file

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def get_environment_from_file(env_name):
    cwd = os.getcwd()
    file_name = beanstalk_directory + env_name

    try:
        ProjectRoot.traverse()
        file_ext = '.env.yml'
        path = file_name + file_ext
        if os.path.exists(path):
            with codecs.open(path, 'r', encoding='utf8') as f:
                return safe_load(f)
    except (ScannerError, ParserError):
        raise InvalidSyntaxError('The environment file contains '
                                 'invalid syntax.')

    finally:
        os.chdir(cwd) 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:fileoperations.py

示例2: get_application_from_file

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def get_application_from_file(app_name):
    cwd = os.getcwd()
    file_name = beanstalk_directory + app_name

    try:
        ProjectRoot.traverse()
        file_ext = '.app.yml'
        path = file_name + file_ext
        if os.path.exists(path):
            with codecs.open(path, 'r', encoding='utf8') as f:
                return safe_load(f)
    except (ScannerError, ParserError):
        raise InvalidSyntaxError('The application file contains '
                                 'invalid syntax.')

    finally:
        os.chdir(cwd) 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:fileoperations.py

示例3: _yaml_configuration_path_option

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def _yaml_configuration_path_option(option_name, option_value):
    """
    Validate a command line option containing a FilePath to a YAML file.

    :param unicode option_name: The name of the option being validated.
    :param unicode option_value: The value being validated.
    """
    yaml_path = _existing_file_path_option(option_name, option_value)
    try:
        configuration = yaml.safe_load(yaml_path.open())
    except ParserError as e:
        raise UsageError(
            u"Problem with --{}. "
            u"Unable to parse YAML from {}. "
            u"Error message: {}.".format(
                option_name, yaml_path.path, unicode(e)
            )
        )
    return configuration 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:21,代码来源:cleanup.py

示例4: test_probe_yaml

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def test_probe_yaml(self):
        m = main.HandsOn()

        with self.assertRaises(SystemExit) as cm:
            m.run([
                'probe', 'yaml',
            ])
        self.assertEqual(cm.exception.code, 0)

        with self.assertRaises(ParserError):
            m.run([
                '-y', './bootstrap',
                'probe', 'yaml',
            ])

        with self.assertRaises(AssertionError):
            m.run([
                '-y', './data/bogus.yaml',
                'probe', 'yaml',
            ]) 
开发者ID:smithfarm,项目名称:ceph-auto-aws,代码行数:22,代码来源:test_main.py

示例5: parse_config

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def parse_config(self, path: str) -> dict:
        """Loads a YAML config file, returning its dictionary format.

        Args:
            path: Path to the config file to be loaded.

        Returns:
            dict: Dictionary representation of the config file.

        """
        try:
            with Path(path).open("r") as file:
                return yaml.safe_load(file)
        except (FileNotFoundError, ParserError) as error:
            raise argparse.ArgumentError(self, error) 
开发者ID:spectacles-ci,项目名称:spectacles,代码行数:17,代码来源:cli.py

示例6: __init__

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def __init__(self, problem_id, time_limit, memory_limit, meta):
        self.id = problem_id
        self.time_limit = time_limit
        self.memory_limit = memory_limit
        self.meta = ConfigNode(meta)
        self.generator_manager = GeneratorManager()

        # Cache root dir so that we don't need to scan all roots (potentially very slow on networked mount).
        self.root_dir = get_problem_root(problem_id)
        self.problem_data = ProblemDataManager(self)

        # Checkers modules must be stored in a dict, for the duration of execution,
        # lest globals be deleted with the module.
        self._checkers = {}

        try:
            doc = yaml.safe_load(self.problem_data['init.yml'])
            if not doc:
                raise InvalidInitException('I find your lack of content disturbing.')
            self.config = ConfigNode(
                doc,
                defaults={
                    'wall_time_factor': 3,
                    'output_prefix_length': 64,
                    'output_limit_length': 25165824,
                    'binary_data': False,
                    'short_circuit': True,
                    'points': 1,
                    'symlinks': {},
                    'meta': meta,
                },
            )
        except (IOError, KeyError, ParserError, ScannerError) as e:
            raise InvalidInitException(str(e))

        self.problem_data.archive = self._resolve_archive_files()
        self._resolve_test_cases() 
开发者ID:DMOJ,项目名称:judge-server,代码行数:39,代码来源:problem.py

示例7: _load

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def _load(self, parser_func, file_path):
        with open(file_path, 'r') as fd:
            try:
                return parser_func(fd)
            except ValueError:
                LOG.exception('Failed loading content from %s.', file_path)
                raise
            except ParserError:
                LOG.exception('Failed loading content from %s.', file_path)
                raise 
开发者ID:StackStorm,项目名称:st2,代码行数:12,代码来源:loader.py

示例8: parse_document_start

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def parse_document_start(self):

        # Parse any extra document end indicators.
        while self.check_token(DocumentEndToken):
            self.get_token()

        # Parse an explicit document.
        if not self.check_token(StreamEndToken):
            token = self.peek_token()
            start_mark = token.start_mark
            # UNITY: only process directives(version and tags) on the first document
            if self.check_prev_token(StreamStartToken):
                version, tags = self.process_directives()
            else:
                version, tags = self.yaml_version, self.tag_handles.copy() if self.tag_handles else None
            if not self.check_token(DocumentStartToken):
                raise ParserError(None, None,
                                  "expected '<document start>', but found %r"
                                  % self.peek_token().id,
                                  self.peek_token().start_mark)
            token = self.get_token()
            end_mark = token.end_mark
            event = DocumentStartEvent(start_mark, end_mark,
                                       explicit=True, version=version, tags=tags)
            self.states.append(self.parse_document_end)
            self.state = self.parse_document_content
        else:
            # Parse the end of the stream.
            token = self.get_token()
            event = StreamEndEvent(token.start_mark, token.end_mark)
            assert not self.states
            assert not self.marks
            self.state = None
        return event 
开发者ID:socialpoint-labs,项目名称:unity-yaml-parser,代码行数:36,代码来源:parser.py

示例9: load_config

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def load_config(config_file: Path) -> Dict:
    """Load the config yaml file into a dictionary."""
    try:
        with config_file.open("r") as f:
            config: Dict = yaml.load(f, Loader=yaml.FullLoader)
    except FileNotFoundError:
        raise ConfigLoadError(f"Config file does not exist: {config_file}")
    except (ScannerError, ParserError) as e:
        logging.error(str(e))
        raise ConfigLoadError(
            "Error encountered in config file. Check that your config file is formatted correctly."
        )
    else:
        dehyphen(config)
    return config 
开发者ID:fennerm,项目名称:flashfocus,代码行数:17,代码来源:config.py

示例10: parse

# 需要导入模块: from yaml import parser [as 别名]
# 或者: from yaml.parser import ParserError [as 别名]
def parse(v):
    """
    Parse a yaml-formatted string.
    """
    try:
        return load(v)
    except (ParserError, ScannerError):
        pass
    return v 
开发者ID:overhangio,项目名称:tutor,代码行数:11,代码来源:serialize.py


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