Support YAML as an output format.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
d21b309ca8
commit
9f030febbf
1 changed files with 13 additions and 0 deletions
|
|
@ -421,6 +421,17 @@ class JSONFile(FileFormat):
|
|||
"(unknown dict)")
|
||||
return o
|
||||
|
||||
class YAMLFile(JSONFile):
|
||||
"""A serializer for YAML.
|
||||
|
||||
Since by default the JSON output by JSONEncoder is valid YAML, this
|
||||
serializer works by outputting JSON. However, loading YAML is not
|
||||
supported, since that would require a full YAML parser (and has security
|
||||
implications).
|
||||
"""
|
||||
def load(self):
|
||||
raise NotImplementedError("Loading arbitrary YAML is not supported.")
|
||||
|
||||
class FileStorage:
|
||||
"""A file (or file-like object) in a certain format."""
|
||||
def __init__(self, fmt, filename, txnformat=None, options=None):
|
||||
|
|
@ -433,6 +444,8 @@ class FileStorage:
|
|||
self._backend = PickleFile(filename, self._txn, options)
|
||||
elif fmt == "json":
|
||||
self._backend = JSONFile(filename, self._txn, options)
|
||||
elif fmt == "yaml":
|
||||
self._backend = YAMLFile(filename, self._txn, options)
|
||||
else:
|
||||
raise ValueError("{0}: not a supported backend".format(fmt))
|
||||
@staticmethod
|
||||
|
|
|
|||
Loading…
Reference in a new issue