Kirill Simonov avatar Kirill Simonov committed 2faecec

Fix bugs in emitter and representer.

Comments (0)

Files changed (2)

lib/yaml/emitter.py

             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)
                 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:

lib/yaml/representer.py

             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)
         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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.