aboutsummaryrefslogtreecommitdiffstats
path: root/yamlish.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2012-02-27 18:54:37 +0100
committerMatěj Cepl <mcepl@redhat.com>2012-02-27 18:54:37 +0100
commitd9f2aa1f9d1066a168700c4e356db4f26772468a (patch)
treeafe42448063640b6b822e95c032fd649a6be353d /yamlish.py
parenta9adb2cae3d62d95a1fdc57d7137dca5e5b9ada9 (diff)
downloadyamlish-d9f2aa1f9d1066a168700c4e356db4f26772468a.tar.gz
Temporary commit to make files available
Diffstat (limited to 'yamlish.py')
-rw-r--r--yamlish.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/yamlish.py b/yamlish.py
index d7be098..098e03d 100644
--- a/yamlish.py
+++ b/yamlish.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, print_function, unicode_literals
"""
Easy YAML serialisation compatible with TAP (http://testanything.org/) format.
Copyright (C) 2012 Red Hat, Inc.
@@ -150,15 +151,15 @@ def load(source):
many others).
"""
out = None
- logging.debug("instr:\n%s", source)
+ logging.debug("inobj:\n%s", source)
if isinstance(source, (str, unicode)):
out = yaml.load(source, Loader=_YamlishLoader)
logging.debug("out (string) = %s", out)
elif hasattr(source, "__iter__"):
- instr = ""
+ inobj = ""
for line in source:
- instr += line + '\n'
- out = load(instr)
+ inobj += line + '\n'
+ out = load(inobj)
logging.debug("out (iter) = %s", out)
return out
@@ -172,13 +173,15 @@ def dump(source, destination):
with open(destination, "w") as outf:
dump(source, outf)
elif isinstance(destination, file):
- yaml.dump(source, destination, canonical=False,
- allow_unicode=False,
- default_flow_style=False, default_style=False)
+ yaml.dump(source, destination, encoding="utf-8",
+ default_flow_style=False, canonical=False,
+ Dumper=yaml.SafeDumper)
def dumps(source):
"""
Return YAMLish string from given source.
"""
- return yaml.dump(source, canonical=False, allow_unicode=False,
- default_flow_style=False, default_style=False)
+ return yaml.dump(source, encoding="utf-8",
+ explicit_start=True, explicit_end=True,
+ default_flow_style=False, default_style=False,
+ canonical=False, Dumper=yaml.SafeDumper)