7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-06-09 01:02:21 +00:00
tutor/tutor/serialize.py

27 lines
510 B
Python
Raw Normal View History

import yaml
from yaml.parser import ParserError
from yaml.scanner import ScannerError
def load(stream):
return yaml.load(stream, Loader=yaml.SafeLoader)
def dump(content, fileobj):
yaml.dump(content, stream=fileobj, default_flow_style=False)
def dumps(content):
return yaml.dump(content, stream=None, default_flow_style=False)
def parse(v):
"""
Parse a yaml-formatted string.
"""
try:
return load(v)
except (ParserError, ScannerError):
pass
return v