Modify ↓
Ticket #52 (closed defect: fixed)
importing gtk breaks unicode loading
| Reported by: | anonymous | Owned by: | 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
comment:2 Changed 6 years ago by anonymous
Make conversion explicit and not reliant on default encoding. Ensure behaviour as documented in PyYAMLDocumentation
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
Note: See
TracTickets for help on using
tickets.

Ok, I looked a little closer and the problem seems to be that pygtk changes the default encoding and yaml relies on this:
I think GTK shouldn't do that but I'll try to prepare a patch for PyYAML anyways.