[snowy] Fix UnicodeEncodeErrors with some Tomboy notes
- From: Brad Taylor <btaylor src gnome org>
- To: svn-commits-list gnome org
- Subject: [snowy] Fix UnicodeEncodeErrors with some Tomboy notes
- Date: Wed, 13 May 2009 10:02:11 -0400 (EDT)
commit 566d227790651221e958dfe6aa1708b6aa5f772e
Author: Brad Taylor <brad getcoded net>
Date: Wed May 13 10:01:06 2009 -0400
Fix UnicodeEncodeErrors with some Tomboy notes
Some Tomboy notes contained Unicode characters which need to be munged manually
to deal with a libxml2 stubbornness.
---
notes/views.py | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/notes/views.py b/notes/views.py
index a13ef88..4d4f241 100644
--- a/notes/views.py
+++ b/notes/views.py
@@ -34,10 +34,13 @@ def note_detail(request, note_id,
styledoc = libxml2.parseFile('data/note2xhtml.xsl')
style = libxslt.parseStylesheetDoc(styledoc)
- doc = libxml2.parseDoc(note.body)
+ # libxml2 doesn't munge encodings, so forcibly encode to UTF-8
+ # http://mail.gnome.org/archives/xml/2004-February/msg00363.html
+ doc = libxml2.parseDoc(note.body.encode('UTF-8'))
result = style.applyStylesheet(doc, None)
- body = style.saveResultToString(result)
+ # libxml2 doesn't munge encodings, so forcibly decode from UTF-8
+ body = unicode(style.saveResultToString(result), 'UTF-8')
finally:
if style != None: style.freeStylesheet()
if doc != None: doc.freeDoc()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]