[Checkins] SVN: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/ Let applyTransform handle sequences too.
Maurits van Rees
cvs-admin at zope.org
Thu Jan 3 13:23:32 UTC 2013
Log message for revision 128993:
Let applyTransform handle sequences too.
Changed:
U Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py
U Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/interfaces/plugins.py
U Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py
-=-
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py 2013-01-03 12:58:28 UTC (rev 128992)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py 2013-01-03 13:23:31 UTC (rev 128993)
@@ -307,7 +307,7 @@
if search_name:
if kw.get('id') is not None:
del kw['id'] # don't even bother searching by id
- # XXX name can be a list, I think.
+ # Note: name can be a sequence.
kw['login'] = self.applyTransform( kw['name'] )
plugins = self._getOb( 'plugins' )
@@ -1073,14 +1073,20 @@
value must be a string (or unicode).
- TODO: maybe allow lists/tuples/sets and iterate over them.
+ Note: the value may be a sequence (list, tuple) so we may
+ need to iterate over it. We return a list then.
"""
if not value:
return value
transform = self._get_login_transform_method()
if not transform:
return value
- return transform(value)
+ if isinstance(value, basestring):
+ return transform(value)
+ result = []
+ for v in value:
+ result.append(transform(v))
+ return result
security.declarePrivate( '_get_login_transform_method' )
def _get_login_transform_method( self ):
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/interfaces/plugins.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/interfaces/plugins.py 2013-01-03 12:58:28 UTC (rev 128992)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/interfaces/plugins.py 2013-01-03 13:23:31 UTC (rev 128993)
@@ -363,8 +363,8 @@
o Return mappings for groups matching the given criteria.
o 'id' in combination with 'exact_match' true, will
- return at most one mapping per supplied ID ('id' and 'login'
- may be sequences).
+ return at most one mapping per supplied ID ('id'
+ may be a sequence).
o If 'exact_match' is False, then 'id' may be treated by
the plugin as "contains" searches (more complicated searches
@@ -414,8 +414,8 @@
o Return mappings for roles matching the given criteria.
o 'id' in combination with 'exact_match' true, will
- return at most one mapping per supplied ID ('id' and 'login'
- may be sequences).
+ return at most one mapping per supplied ID ('id'
+ may be a sequence).
o If 'exact_match' is False, then 'id' may be treated by
the plugin as "contains" searches (more complicated searches
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py 2013-01-03 12:58:28 UTC (rev 128992)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py 2013-01-03 13:23:31 UTC (rev 128993)
@@ -2529,8 +2529,10 @@
self.assertEqual(zcuf.applyTransform(u' User '), u'user')
self.assertEqual(zcuf.applyTransform(''), '')
self.assertEqual(zcuf.applyTransform(None), None)
- self.assertRaises(AttributeError, zcuf.applyTransform, 123)
- self.assertRaises(AttributeError, zcuf.applyTransform, ['User'])
+ self.assertEqual(zcuf.applyTransform([' User ']), ['user'])
+ self.assertEqual(zcuf.applyTransform(('User', ' joe ', 'Diana')),
+ ['user', 'joe', 'diana'])
+ self.assertRaises(TypeError, zcuf.applyTransform, 123)
zcuf.login_transform = 'upper'
self.assertEqual(zcuf.applyTransform(' User '), 'USER')
# Let's not fail just because a user has accidentally left a
More information about the checkins
mailing list