Commits

Kirill Simonov committed f351f10

Fix allow_unicode (ticket:3).

Comments (0)

Files changed (3)

lib/yaml/__init__.py

 
 def dump_all(natives, writer=None, Emitter=Emitter,
         Serializer=Serializer, Representer=Representer,
-        encoding=None, line_break=None, canonical=None,
+        encoding='utf-8', line_break=None, canonical=None,
         indent=None, width=None, allow_unicode=None):
     if writer is None:
         try:
 
 def safe_dump_all(natives, writer=None, Emitter=Emitter,
         Serializer=Serializer, Representer=SafeRepresenter,
-        encoding=None, line_break=None, canonical=None,
+        encoding='utf-8', line_break=None, canonical=None,
         indent=None, width=None, allow_unicode=None):
     return dump_all(natives, writer, Emitter, Serializer, Representer,
             encoding, line_break, canonical, indent, width, allow_unicode)

lib/yaml/representer.py

                 u'null')
 
     def represent_str(self, native):
+        encoding = None
         try:
-            native.encode('ascii')
-            ascii = True
-        except (UnicodeDecodeError, UnicodeEncodeError):
-            ascii = False
-        if ascii:
+            unicode(native, 'ascii')
+            encoding = 'ascii'
+        except UnicodeDecodeError:
+            try:
+                unicode(native, 'utf-8')
+                encoding = 'utf-8'
+            except UnicodeDecodeError:
+                pass
+        if encoding:
             return self.represent_scalar(u'tag:yaml.org,2002:str',
-                    unicode(native, 'ascii'))
+                    unicode(native, encoding))
         else:
             return self.represent_scalar(u'tag:yaml.org,2002:binary',
                     unicode(native.encode('base64')), style='|')

lib/yaml/serializer.py

         self.anchors = {}
         self.last_anchor_id = 0
         self.closed = None
-        self.open(encoding, line_break, canonical, indent, width)
+        self.open(encoding, line_break, canonical, indent, width, allow_unicode)
 
     def open(self, encoding=None, line_break=None, canonical=None,
             indent=None, width=None, allow_unicode=None):
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.