Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to davisagli-py-3 branch #60

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Products/GenericSetup/PluginIndexes/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
_DATE_XML = b"""\
<index name="foo_date" meta_type="DateIndex">
<property name="index_naive_time_as_local">True</property>
<property name="precision">1</property>
</index>
"""

Expand Down Expand Up @@ -228,7 +229,7 @@ def _no_clear(*a):
raise AssertionError("Don't clear me!")
index = FieldIndex('foo_field')
index.indexed_attrs = ['bar']
index.clear = _no_clear
index.clear = _no_clear
adapted = PluggableIndexNodeAdapter(index, environ)
adapted.node = parseString(_FIELD_XML).documentElement # no raise

Expand All @@ -244,7 +245,7 @@ def _no_clear(*a):
raise AssertionError("Don't clear me!")
index = KeywordIndex('foo_keyword')
index.indexed_attrs = ['bar']
index.clear = _no_clear
index.clear = _no_clear
adapted = PluggableIndexNodeAdapter(index, environ)
adapted.node = parseString(_KEYWORD_XML).documentElement # no raise

Expand Down Expand Up @@ -274,7 +275,7 @@ def _no_clear(*a):
raise AssertionError("Don't clear me!")
index = DateIndex('foo_date')
index._setPropValue('index_naive_time_as_local', True)
index.clear = _no_clear
index.clear = _no_clear
adapted = DateIndexNodeAdapter(index, environ)
adapted.node = parseString(_DATE_XML).documentElement # no raise

Expand All @@ -291,7 +292,7 @@ def _no_clear(*a):
index = DateRangeIndex('foo_daterange')
index._since_field = 'bar'
index._until_field = 'baz'
index.clear = _no_clear
index.clear = _no_clear
adapted = DateRangeIndexNodeAdapter(index, environ)
adapted.node = parseString(_DATERANGE_XML).documentElement # no raise

Expand All @@ -306,7 +307,7 @@ def test_FilteredSet(self):
def _no_clear(*a):
raise AssertionError("Don't clear me!")
index = PythonFilteredSet('bar', 'True')
index.clear = _no_clear
index.clear = _no_clear
adapted = FilteredSetNodeAdapter(index, environ)
adapted.node = parseString(_SET_XML).documentElement # no raise

Expand All @@ -324,7 +325,7 @@ def _no_clear(*a):
index.addFilteredSet('baz', 'PythonFilteredSet', 'False')
bar = index.filteredSets['bar']
baz = index.filteredSets['baz']
bar.clear = baz.clear = _no_clear
bar.clear = baz.clear = _no_clear
adapted = TopicIndexNodeAdapter(index, environ)
adapted.node = parseString(_SET_XML).documentElement # no raise

Expand Down
1 change: 1 addition & 0 deletions Products/GenericSetup/ZCatalog/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class _extra:
</object>
%s <index name="foo_date" meta_type="DateIndex">
<property name="index_naive_time_as_local">True</property>
<property name="precision">1</property>
</index>
<index name="foo_daterange" meta_type="DateRangeIndex" since_field="bar"
until_field="baz"/>
Expand Down
4 changes: 2 additions & 2 deletions Products/GenericSetup/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def generateXML(self, encoding='utf-8'):
"""
xml = self._exportTemplate()
if six.PY2:
xml = xml.encode('utf-8')
xml = xml.encode(encoding)
return xml

security.declarePrivate('getStep')
Expand Down Expand Up @@ -615,7 +615,7 @@ def generateXML(self, encoding='utf-8'):
"""
xml = self._toolsetConfig()
if six.PY2:
xml = xml.encode('utf-8')
xml = xml.encode(encoding)
return xml

security.declareProtected(ManagePortal, 'parseXML')
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
25 changes: 18 additions & 7 deletions Products/GenericSetup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class NodeAdapterBase(object):

"""Node im- and exporter base.
"""

_encoding = 'utf-8'
_LOGGER_ID = ''

def __init__(self, context, environ):
Expand Down Expand Up @@ -502,7 +502,8 @@ def _exportBody(self):
"""Export the object as a file body.
"""
self._doc.appendChild(self._exportNode())
xml = self._doc.toprettyxml(' ', encoding='utf-8')
# Specifying the encoding parameter forces xml to be bytes
xml = self._doc.toprettyxml(' ', encoding=self._encoding)
self._doc.unlink()
return xml

Expand All @@ -515,6 +516,8 @@ def _importBody(self, body):
filename = (self.filename or
'/'.join(self.context.getPhysicalPath()))
raise ExpatError('%s: %s' % (filename, e))
# Replace the encoding with the one from the XML
self._encoding = dom.encoding or 'utf-8'
self._importNode(dom.documentElement)

body = property(_exportBody, _importBody)
Expand Down Expand Up @@ -758,7 +761,9 @@ 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 six.PY2 and isinstance(value, six.text_type):
value = value.encode(self._encoding)
if self._convertToBoolean(sub.getAttribute('remove')
or 'False'):
remove_elements.append(value)
Expand All @@ -769,15 +774,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 @@ -788,8 +795,12 @@ def _initProperties(self, node):
if p not in prop_value and
p not in remove_elements]) +
tuple(prop_value))

if isinstance(prop_value, (six.binary_type, str)):
if not six.PY2:
if isinstance(prop_value, six.binary_type):
prop_type = obj.getPropertyType(prop_id) or 'string'
if prop_type == 'string':
prop_value = prop_value.decode(self._encoding)
if isinstance(prop_value, six.text_type):
prop_type = obj.getPropertyType(prop_id) or 'string'
if prop_type in type_converters:
prop_value = type_converters[prop_type](prop_value)
Expand Down
4 changes: 2 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ github = git://github.com/zopefoundation
github_push = [email protected]:zopefoundation

[sources]
AccessControl = git ${remotes:github}/AccessControl.git pushurl=${remotes:github_push}/AccessControl.git branch=TaintedBytes
AccessControl = git ${remotes:github}/AccessControl.git pushurl=${remotes:github_push}/AccessControl.git branch=master
Products.MailHost = git ${remotes:github}/Products.MailHost pushurl=${remotes:github_push}/Products.MailHost
Zope = git ${remotes:github}/Zope pushurl=${remotes:github_push}/Zope branch=lines-property
Zope = git ${remotes:github}/Zope pushurl=${remotes:github_push}/Zope branch=master

[test]
recipe = zc.recipe.testrunner
Expand Down