Commit 7cc89c6e authored by Emmy Vouriot's avatar Emmy Vouriot Committed by Jérome Perrin

WIP: Python 2 to 3 fixes - add py2 compatibility

parent dde1b189
...@@ -34,6 +34,7 @@ from OFS.Image import Image as OFSImage ...@@ -34,6 +34,7 @@ from OFS.Image import Image as OFSImage
from lxml.etree import Element from lxml.etree import Element
from lxml import etree from lxml import etree
import re import re
import six
DRAW_URI = 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' DRAW_URI = 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'
TEXT_URI = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0' TEXT_URI = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'
...@@ -145,6 +146,8 @@ class ImageFieldWidget(Widget.TextWidget): ...@@ -145,6 +146,8 @@ class ImageFieldWidget(Widget.TextWidget):
if value in ('', None): if value in ('', None):
return None return None
path = '/'.join(REQUEST.physicalPathFromURL(value)) path = '/'.join(REQUEST.physicalPathFromURL(value))
if six.PY2:
path = path.encode()
image_object = field.getPortalObject().restrictedTraverse(path) image_object = field.getPortalObject().restrictedTraverse(path)
display = field.get_value('image_display') display = field.get_value('image_display')
format = field.get_value('image_format') format = field.get_value('image_format')
......
...@@ -1107,6 +1107,10 @@ class ODGStrategy(ODFStrategy): ...@@ -1107,6 +1107,10 @@ class ODGStrategy(ODFStrategy):
text_xpath = '//draw:frame[@draw:name="%s"]' % field.id text_xpath = '//draw:frame[@draw:name="%s"]' % field.id
node_list = element_tree.xpath(text_xpath, namespaces=element_tree.nsmap) node_list = element_tree.xpath(text_xpath, namespaces=element_tree.nsmap)
value = field.get_value('default') value = field.get_value('default')
if six.PY2:
if isinstance(value, str):
value = value.decode('utf-8')
else:
if isinstance(value, bytes): if isinstance(value, bytes):
value = value.decode('utf-8') value = value.decode('utf-8')
for target_node in node_list: for target_node in node_list:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment