summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-04-26 15:30:45 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-04-26 15:30:45 +0200
commit9f29a72b98712f191237cb2ee3dc1f3db730d361 (patch)
tree82926022fba697a14a1474b501470735d13b3650
parente52c0b996a9d51a5aec5eaef0baee4000c59969f (diff)
downloadruamel.yaml-9f29a72b98712f191237cb2ee3dc1f3db730d361.tar.gz
fix problem in cdav/ooo.py safe-dumping with cyaml0.14.10
-rw-r--r--CHANGES3
-rw-r--r--README.rst3
-rw-r--r--__init__.py4
-rw-r--r--_test/test_cyaml.py8
-rw-r--r--cyaml.py3
-rw-r--r--main.py18
-rw-r--r--representer.py5
7 files changed, 38 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index 65afded..120a513 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+[0, 14, 10]: 2017-04-26
+ - fix problem with emitting using cyaml
+
[0, 14, 9]: 2017-04-22
- remove dependency on ``typing`` while still supporting ``mypy``
(http://stackoverflow.com/a/43516781/1307905)
diff --git a/README.rst b/README.rst
index a81e99d..47f0618 100644
--- a/README.rst
+++ b/README.rst
@@ -18,6 +18,9 @@ ChangeLog
.. should insert NEXT: at the beginning of line for next key
+0.14.10 (2017-04-26):
+ - fix problem with emitting using cyaml
+
0.14.9 (2017-04-22):
- remove dependency on ``typing`` while still supporting ``mypy``
(http://stackoverflow.com/a/43516781/1307905)
diff --git a/__init__.py b/__init__.py
index 42b7378..9073226 100644
--- a/__init__.py
+++ b/__init__.py
@@ -11,8 +11,8 @@ if False: # MYPY
_package_data = dict(
full_package_name='ruamel.yaml',
- version_info=(0, 14, 9),
- __version__='0.14.9',
+ version_info=(0, 14, 10),
+ __version__='0.14.10',
author='Anthon van der Neut',
author_email='a.van.der.neut@ruamel.eu',
description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA
diff --git a/_test/test_cyaml.py b/_test/test_cyaml.py
index 81dc4a5..4c5c5db 100644
--- a/_test/test_cyaml.py
+++ b/_test/test_cyaml.py
@@ -11,3 +11,11 @@ def test_load_cyaml():
assert ruamel.yaml.__with_libyaml__
from ruamel.yaml.cyaml import CLoader
ruamel.yaml.load("abc: 1", Loader=CLoader)
+
+
+def test_dump_cyaml():
+ import ruamel.yaml
+ data = {'a': 1, 'b': 2}
+ res = ruamel.yaml.dump(data, Dumper=ruamel.yaml.cyaml.CSafeDumper,
+ default_flow_style=False, allow_unicode=True)
+ assert res == "a: 1\nb: 2\n"
diff --git a/cyaml.py b/cyaml.py
index b39303c..02ed6aa 100644
--- a/cyaml.py
+++ b/cyaml.py
@@ -71,6 +71,7 @@ class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver): # type: ignore
explicit_start=explicit_start,
explicit_end=explicit_end,
version=version, tags=tags)
+ self._emitter = self._serializer = self._representer = self
BaseRepresenter.__init__(self, default_style=default_style,
default_flow_style=default_flow_style, dumper=self)
BaseResolver.__init__(self, loadumper=self)
@@ -85,6 +86,7 @@ class CSafeDumper(CEmitter, SafeRepresenter, Resolver): # type: ignore
version=None, tags=None, block_seq_indent=None,
top_level_colon_align=None, prefix_colon=None):
# type: (StreamType, Any, Any, Any, bool, Union[None, int], Union[None, int], bool, Any, Any, Union[None, bool], Union[None, bool], Any, Any, Any, Any, Any) -> None # NOQA
+ self._emitter = self._serializer = self._representer = self
CEmitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width, encoding=encoding,
allow_unicode=allow_unicode, line_break=line_break,
@@ -111,6 +113,7 @@ class CDumper(CEmitter, Serializer, Representer, Resolver): # type: ignore
explicit_start=explicit_start,
explicit_end=explicit_end,
version=version, tags=tags)
+ self._emitter = self._serializer = self._representer = self
Representer.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
diff --git a/main.py b/main.py
index 93482ca..dc6ed92 100644
--- a/main.py
+++ b/main.py
@@ -172,7 +172,11 @@ def emit(events, stream=None, Dumper=Dumper,
for event in events:
dumper.emit(event)
finally:
- dumper._emitter.dispose()
+ try:
+ dumper._emitter.dispose()
+ except AttributeError:
+ raise
+ dumper.dispose() # cyaml
if getvalue is not None:
return getvalue()
@@ -206,7 +210,11 @@ def serialize_all(nodes, stream=None, Dumper=Dumper,
dumper.serialize(node)
dumper._serializer.close()
finally:
- dumper._emitter.dispose()
+ try:
+ dumper._emitter.dispose()
+ except AttributeError:
+ raise
+ dumper.dispose() # cyaml
if getvalue is not None:
return getvalue()
@@ -260,7 +268,11 @@ def dump_all(documents, stream=None, Dumper=Dumper,
raise
dumper._serializer.close()
finally:
- dumper._emitter.dispose()
+ try:
+ dumper._emitter.dispose()
+ except AttributeError:
+ raise
+ dumper.dispose() # cyaml
if getvalue is not None:
return getvalue()
return None
diff --git a/representer.py b/representer.py
index 8d20617..a9e229c 100644
--- a/representer.py
+++ b/representer.py
@@ -59,7 +59,10 @@ class BaseRepresenter(object):
@property
def serializer(self):
# type: () -> Any
- return self.dumper._serializer
+ try:
+ return self.dumper._serializer
+ except AttributeError:
+ return self # cyaml
def represent(self, data):
# type: (Any) -> None