[FIX] xmlrpclib being an asshole

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
This commit is contained in:
Xavier Morel 2011-06-30 16:25:28 +02:00
parent 6102406eea
commit 1b236bd882
1 changed files with 14 additions and 2 deletions

View 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']: