[FIX] xmlrpclib being an asshole
authorXavier Morel <xmo@openerp.com>
Thu, 30 Jun 2011 14:25:28 +0000 (16:25 +0200)
committerXavier Morel <xmo@openerp.com>
Thu, 30 Jun 2011 14:25:28 +0000 (16:25 +0200)
xmlrpclib.ServerProxy will convert XMLRPC strings to 'str'. Or to 'unicode' if it does not feel right today, or just wants to fuck with you. Competence is overrated!

Check precise type of view archiectures and re-encode to str if we're facing unicode strings, so it's possible to feed these little bastards to ElementTree

bzr revid: xmo@openerp.com-20110630142528-1xtj61gaou2klzme

addons/base/controllers/main.py

index 6116cfd..850069b 100644 (file)
@@ -536,11 +536,23 @@ class View(openerpweb.Controller):
         return fvg
     
     def process_view(self, session, fvg, context, transform):
+        # depending on how it feels, xmlrpclib.ServerProxy can translate
+        # XML-RPC strings to ``str`` or ``unicode``. ElementTree does not
+        # enjoy unicode strings which can not be trivially converted to
+        # strings, and it blows up during parsing.
+
+        # So ensure we fix this retardation by converting view xml back to
+        # bit strings.
+        if isinstance(fvg['arch'], unicode):
+            arch = fvg['arch'].encode('utf-8')
+        else:
+            arch = fvg['arch']
+
         if transform:
             evaluation_context = session.evaluation_context(context or {})
-            xml = self.transform_view(fvg['arch'], session, evaluation_context)
+            xml = self.transform_view(arch, session, evaluation_context)
         else:
-            xml = ElementTree.fromstring(fvg['arch'])
+            xml = ElementTree.fromstring(arch)
         fvg['arch'] = Xml2Json.convert_element(xml)
         for field in fvg['fields'].values():
             if field.has_key('views') and field['views']: