Skip to content

Commit

Permalink
- Replace all filter(None...) expressions which break under Pytho…
Browse files Browse the repository at this point in the history
…n 3 (fixes #63)
  • Loading branch information
dataflake committed Feb 2, 2020
1 parent 3eb34c0 commit 9b390d7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Change Log
2.3 (unreleased)
----------------

- Nothing changed yet.
- Replace all ``filter(None...)`` expressions which break under Python 3
(`#63 <https://github.com/zopefoundation/Products.PluggableAuthService/issues/63>`_)


2.2.1 (2020-01-13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def manage_updateProtocolMapping(self, mapping, REQUEST=None):
""" Update mapping of Request Type to Protocols
"""
for key, value in mapping.items():
value = filter(None, value)
value = [_f for _f in value if _f]
if not value:
if key in self._map:
del self._map[key]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def manage_updateGroup(self, group_id, predicate, title=None,
def manage_removeGroups(self, group_ids, RESPONSE=None, REQUEST=None):
""" Remove one or more groups via the ZMI.
"""
group_ids = filter(None, group_ids)
group_ids = [_f for _f in group_ids if _f]

if not group_ids:
message = 'no+groups+selected'
Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/ZODBGroupManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def manage_updateGroup(self, group_id, title, description, RESPONSE=None):
def manage_removeGroups(self, group_ids, RESPONSE=None, REQUEST=None):
""" Remove one or more groups via the ZMI.
"""
group_ids = filter(None, group_ids)
group_ids = [_f for _f in group_ids if _f]

if not group_ids:
message = 'no+groups+selected'
Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/ZODBRoleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def manage_removeRoles(self, role_ids, RESPONSE=None, REQUEST=None):
remove it from the roles in the root of the site (at the
bottom of the Security tab at manage_access).
"""
role_ids = filter(None, role_ids)
role_ids = [_f for _f in role_ids if _f]

if not role_ids:
message = 'no+roles+selected'
Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/ZODBUserManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def manage_updateUser(self, user_id, login_name, RESPONSE=None,
def manage_removeUsers(self, user_ids, RESPONSE=None, REQUEST=None):
""" Remove one or more users via the ZMI.
"""
user_ids = filter(None, user_ids)
user_ids = [_f for _f in user_ids if _f]

if not user_ids:
message = 'no+users+selected'
Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _updateFromDOM(self, root):
for mapping in root.getElementsByTagName('mapping'):
label = self._getNodeAttr(mapping, 'label', None)
protocols = self._getNodeAttr(mapping, 'protocols', '').split(',')
self.context._map[label] = tuple(filter(None, protocols))
self.context._map[label] = tuple([_f for _f in protocols if _f])

def _getExportInfo(self):
from Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ def assertStatus(self, response, status):
self.assertEqual(status, response.getOutput().split(b'\r\n')[0])


class ChallengeProtocolChooserFunctionalTests(
Testing.ZopeTestCase.Functional,
Testing.ZopeTestCase.ZopeTestCase,
ChallengeProtocolChooserTestHelper):
""" Test basic functionality """

def setUp(self):
super(ChallengeProtocolChooserFunctionalTests, self).setUp()
self.setup_user_folder()
self.setup_cookie_auth()
self.setup_http_auth()
self.setup_sniffer()

def test_manage_updateProtocolMapping(self):
# Make sure the mapped request types contain
# valid data under Python 2 and Python 3
pas = self.app.test_folder_1_.acl_users
plugin = pas.chooser

for key, value in plugin._map.items():
self.assertTrue(isinstance(value, (list, tuple, set)))


class ChallengeProtocolChooserBasicAuthTests(
Testing.ZopeTestCase.Functional,
Testing.ZopeTestCase.ZopeTestCase,
Expand Down
4 changes: 2 additions & 2 deletions Products/PluggableAuthService/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_empty(self):
filename, text, content_type = context._wrote[1]
self.assertEqual(filename, 'PAS/.properties')
self.assertEqual(content_type, 'text/plain')
lines = filter(None, [x.strip() for x in text.splitlines()])
lines = [_f for _f in [x.strip() for x in text.splitlines()] if _f]
lines = sorted(lines)
self.assertEqual(len(lines), 3)
self.assertEqual(lines[0], '[DEFAULT]')
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_with_contents(self):
filename, text, content_type = context._wrote[1]
self.assertEqual(filename, 'PAS/.properties')
self.assertEqual(content_type, 'text/plain')
lines = filter(None, [x.strip() for x in text.splitlines()])
lines = [_f for _f in [x.strip() for x in text.splitlines()] if _f]
lines = sorted(lines)
self.assertEqual(len(lines), 3)
self.assertEqual(lines[0], '[DEFAULT]')
Expand Down

0 comments on commit 9b390d7

Please sign in to comment.