Ticket #52 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

importing gtk breaks unicode loading

Reported by: anonymous Assigned to: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

The following summarizes it pretty well, I guess:

>>> import yaml
>>> u = u"\N{skull and crossbones}"
>>> yaml.load(yaml.dump(u))
u'\u2620'
>>> import gtk
>>> yaml.load(yaml.dump(u))
'\xe2\x98\xa0'

Attachments

Change History

05/01/07 09:07:40 changed by anonymous

Ok, I looked a little closer and the problem seems to be that pygtk changes the default encoding and yaml relies on this:

>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> import gtk
>>> sys.getdefaultencoding()
'utf-8' 

I think GTK shouldn't do that but I'll try to prepare a patch for PyYAML anyways.

05/01/07 09:16:01 changed by anonymous

Make conversion explicit and not reliant on default encoding. Ensure behaviour as documented in PyYAMLDocumentation#Stringconversion

diff --git a/yaml/constructor.py b/yaml/constructor.py
index d1d4f6a..cf4b051 100644
--- a/yaml/constructor.py
+++ b/yaml/constructor.py
@@ -383,7 +383,7 @@ class SafeConstructor(BaseConstructor):
     def construct_yaml_str(self, node):
         value = self.construct_scalar(node)
         try:
-            return str(value)
+            return value.encode("ascii")
         except UnicodeEncodeError:
             return value

05/05/07 15:04:41 changed by xi

  • status changed from new to closed.
  • resolution set to fixed.

Thanks for the patch, fixed [251].


Add/Change #52 (importing gtk breaks unicode loading)




Change Properties
Action