diff options
author | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2006-04-18 19:33:16 +0000 |
---|---|---|
committer | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2006-04-18 19:33:16 +0000 |
commit | 00a1a3f4c7e9e54c5c3d30a2fa3990b99ea9cad3 (patch) | |
tree | fae69afbd5743cf5f94a95f799e2818444bccf74 | |
parent | 0e133bded6f6b7206bfb6d772290a82d3201b22a (diff) | |
download | pyyaml-00a1a3f4c7e9e54c5c3d30a2fa3990b99ea9cad3.tar.gz |
Fix bugs in emitter and representer.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@143 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r-- | lib/yaml/emitter.py | 7 | ||||
-rw-r--r-- | lib/yaml/representer.py | 10 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/yaml/emitter.py b/lib/yaml/emitter.py index 3b8b1f3..d06fde1 100644 --- a/lib/yaml/emitter.py +++ b/lib/yaml/emitter.py @@ -959,10 +959,9 @@ class Emitter: ch = None if end < len(text): ch = text[end] - if ch is None or ch in u'"\\' \ + if ch is None or ch in u'"\\\x85\u2028\u2029\uFEFF' \ or not (u'\x20' <= ch <= u'\x7E' - or (self.allow_unicode and ch > u'\x7F' - and ch not in u'\x85\u2028\u2029')): + or (self.allow_unicode and ch > u'\x7F')): if start < end: data = text[start:end] self.column += len(data) @@ -996,7 +995,7 @@ class Emitter: self.write_indent() self.whitespace = False self.indention = False - if ch == u' ': + if text[start] == u' ': data = u'\\' self.column += len(data) if self.encoding: diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index 797d865..749182d 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -63,7 +63,7 @@ class BaseRepresenter: self.represented_objects[alias_key] = None data_types = type(data).__mro__ if type(data) is self.instance_type: - data_types = self.get_classobj_bases(data.__class__)+data_types + data_types = self.get_classobj_bases(data.__class__)+list(data_types) for data_type in data_types: if data_type in self.yaml_representers: node = self.yaml_representers[data_type](self, data) @@ -291,10 +291,14 @@ class Representer(SafeRepresenter): return self.represent_scalar(tag, unicode(data)) def represent_complex(self, data): - if data.real != 0.0: + if data.imag == 0.0: + data = u'%r' % data.real + elif data.real == 0.0: + data = u'%rj' % data.imag + elif data.imag > 0: data = u'%r+%rj' % (data.real, data.imag) else: - data = u'%rj' % data.imag + data = u'%r%rj' % (data.real, data.imag) return self.represent_scalar(u'tag:yaml.org,2002:python/complex', data) def represent_tuple(self, data): |