summaryrefslogtreecommitdiff
path: root/odoo/tools/convert.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-09-25 17:00:43 +0200
committerXavier Morel <xmo@odoo.com>2017-09-25 17:00:43 +0200
commit059710b2b07e30effa5443fb56e05eae66d97d13 (patch)
treef12bb426da32e9095dfdf98daf5df72b1ea76693 /odoo/tools/convert.py
parente6f2ce245b42b4588f2c0f753773f3d71dd9543f (diff)
[FIX] reading of HTML and XML view fields in P3
Reading them as bytes would not crash but could fill the corresponding field with pretty much garbage. Turns out Html fields inherit from Text and XML content generally goes into text fields, so handling these items as text makes much more sense than as binary data.
Diffstat (limited to 'odoo/tools/convert.py')
-rw-r--r--odoo/tools/convert.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py
index 60f9bfa83ad..59e87d6ee32 100644
--- a/odoo/tools/convert.py
+++ b/odoo/tools/convert.py
@@ -116,29 +116,29 @@ def _eval_xml(self, node, env):
'Could not eval(%s) for %s in %s', a_eval, node.get('name'), env.context)
raise
def _process(s):
- matches = re.finditer(br'[^%]%\((.*?)\)[ds]', s)
+ matches = re.finditer(br'[^%]%\((.*?)\)[ds]'.decode('utf-8'), s)
done = set()
for m in matches:
found = m.group()[1:]
if found in done:
continue
done.add(found)
- id = m.groups()[0].decode('utf-8')
+ id = m.groups()[0]
if not id in self.idref:
self.idref[id] = self.id_get(id)
# So funny story: in Python 3, bytes(n: int) returns a
# bytestring of n nuls. In Python 2 it obviously returns the
# stringified number, which is what we're expecting here
- s = s.replace(found, pycompat.text_type(self.idref[id]).encode('utf-8'))
- s = s.replace(b'%%', b'%') # Quite wierd but it's for (somewhat) backward compatibility sake
+ s = s.replace(found, pycompat.text_type(self.idref[id]))
+ s = s.replace('%%', '%') # Quite wierd but it's for (somewhat) backward compatibility sake
return s
if t == 'xml':
_fix_multiple_roots(node)
- return b'<?xml version="1.0"?>\n'\
- +_process(b"".join(etree.tostring(n, encoding='utf-8') for n in node))
+ return '<?xml version="1.0"?>\n'\
+ +_process("".join(etree.tostring(n, encoding='unicode') for n in node))
if t == 'html':
- return _process(b"".join(etree.tostring(n, encoding='utf-8') for n in node))
+ return _process("".join(etree.tostring(n, encoding='unicode') for n in node))
data = node.text
if node.get('file'):