本文整理汇总了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)
示例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)
示例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
示例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',
])
示例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)
示例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()
示例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
示例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
示例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
示例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