changeset 271:232002e132db 0.1.1

pgsql_backend unicode fix: parseXml was expecting str and getting unicode
author Goffi <goffi@goffi.org>
date Wed, 13 Aug 2014 17:30:37 +0200
parents f17034e4cf4a
children 558a43366c9f
files sat_pubsub/pgsql_storage.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Wed Aug 13 17:01:29 2014 +0200
+++ b/sat_pubsub/pgsql_storage.py	Wed Aug 13 17:30:37 2014 +0200
@@ -59,15 +59,19 @@
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
 
-from wokkel.generic import parseXml, stripNamespace
+from wokkel import generic
 from wokkel.pubsub import Subscription
 
 from sat_pubsub import error, iidavoll, const
 import psycopg2
 import psycopg2.extensions
+# we wants psycopg2 to return us unicode, not str
 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
 psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
 
+# parseXml manage str, but we get unicode
+parseXml = lambda unicode_data: generic.parseXml(unicode_data.encode('utf-8'))
+
 class Storage:
 
     implements(iidavoll.IStorage)
@@ -643,7 +647,7 @@
         if unrestricted:
             ret = []
             for data in result:
-                item = stripNamespace(parseXml(data[0]))
+                item = generic.stripNamespace(parseXml(data[0]))
                 access_model = data[1]
                 item_id = data[2]
                 if access_model == 'roster': #TODO: jid access_model
@@ -654,7 +658,7 @@
 
                 ret.append((item, access_model, access_list))
             return ret
-        items = [stripNamespace(parseXml(r[0])) for r in result]
+        items = [generic.stripNamespace(parseXml(r[0])) for r in result]
         return items
 
 
@@ -681,7 +685,7 @@
                 result = cursor.fetchone()
                 if result:
                     for data in result:
-                        item = stripNamespace(parseXml(data[0]))
+                        item = generic.stripNamespace(parseXml(data[0]))
                         access_model = data[1]
                         item_id = data[2]
                         if access_model == 'roster': #TODO: jid access_model