當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。