Skip to content

Commit

Permalink
Merge 388abb0 into ef45cac
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Oct 8, 2018
2 parents ef45cac + 388abb0 commit fac0ccd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Products/GenericSetup/PythonScripts/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _exportBody(self):
def _importBody(self, body):
"""Import the object from the file body.
"""
if six.PY3:
if six.PY3 and isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = body.replace('\r\n', '\n').replace('\r', '\n')
self.context.write(body)
Expand Down
6 changes: 6 additions & 0 deletions Products/GenericSetup/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class DOMComparator:

def _compareDOM(self, found_text, expected_text, debug=False):

if six.PY3:
if isinstance(found_text, bytes):
found_text = found_text.decode('utf8')
if isinstance(expected_text, bytes):
expected_text = expected_text.decode('utf8')

found_lines = [x.strip() for x in found_text.splitlines()]
found_text = '\n'.join([i for i in found_lines if i])

Expand Down
15 changes: 10 additions & 5 deletions Products/GenericSetup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ def _initProperties(self, node):
remove_elements = []
for sub in child.childNodes:
if sub.nodeName == 'element':
value = sub.getAttribute('value').encode(self._encoding)
value = sub.getAttribute('value')
if prop_map.get('type') not in (
'ulines', 'multiple selection'):
value = value.encode(self._encoding)
if self._convertToBoolean(sub.getAttribute('remove')
or 'False'):
remove_elements.append(value)
Expand All @@ -775,15 +778,17 @@ def _initProperties(self, node):
if value in remove_elements:
remove_elements.remove(value)

if prop_map.get('type') in ('lines', 'tokens',
if prop_map.get('type') in ('lines', 'tokens', 'ulines',
'multiple selection'):
prop_value = tuple(new_elements) or ()
elif prop_map.get('type') == 'boolean':
prop_value = self._convertToBoolean(self._getNodeText(child))
else:
# if we pass a *string* to _updateProperty, all other values
# are converted to the right type
prop_value = self._getNodeText(child).encode(self._encoding)
prop_value = self._getNodeText(child)
if six.PY2 and isinstance(prop_value, six.text_type):
prop_value = prop_value.encode(self._encoding)

if not self._convertToBoolean(child.getAttribute('purge')
or 'True'):
Expand All @@ -795,12 +800,12 @@ def _initProperties(self, node):
p not in remove_elements]) +
tuple(prop_value))

if isinstance(prop_value, (six.binary_type, str)):
if isinstance(prop_value, (six.binary_type, six.text_type)):
prop_type = obj.getPropertyType(prop_id) or 'string'
if prop_type in type_converters:
# The type_converters use the ZPublisher default_encoding
# for decoding bytes!
if self._encoding != default_encoding:
if self._encoding.lower() != default_encoding:
u_prop_value = prop_value.decode(self._encoding)
prop_value = u_prop_value.encode(default_encoding)
prop_value = type_converters[prop_type](prop_value)
Expand Down

0 comments on commit fac0ccd

Please sign in to comment.