[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - metaConfigure.py:1.1.2.16

Barry Warsaw barry@wooz.org
Thu, 13 Dec 2001 16:57:47 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv13702/lib/python/Zope/App/Security

Modified Files:
      Tag: Zope-3x-branch
	metaConfigure.py 
Log Message:
definePermission(), defineRole(): Remove these in favor of a generic
function that returns a wrapper that throws away the return value.

throw_away_return_value(): This is the generic function wrapper
function ;).

metaConfigure(): Define definePermission and defineRole in terms of
throw_away_return_value()


=== Zope3/lib/python/Zope/App/Security/metaConfigure.py 1.1.2.15 => 1.1.2.16 ===
     setSecurityPolicy( policy )
 
-
-def definePermission(**kw):
-    perm_reg.definePermission(**kw)
-
-def defineRole(**kw):
-    role_reg.defineRole(**kw)
+# We need a wrapper to throw away the return value, otherwise the machinery
+# requres that the returned things is a callable.
+def throw_away_return_value(func):
+    def callfunc(func=func, **kw):
+        func(**kw)
+    return callfunc
 
 def metaConfigure():
-    register(namespace('security'), 'definePermission', definePermission)
-    register(namespace('security'), 'defineRole', defineRole)
+    register(namespace('security'),
+             'definePermission',
+             throw_away_return_value(perm_reg.definePermission))
+    register(namespace('security'),
+             'defineRole',
+             throw_away_return_value(role_reg.defineRole))
     register(namespace('security'), 'protectClass', protectClass)
     register(namespace('security'), 'publicClass', publicClass)
     register(namespace('security'), 'defaultPolicy',
@@ -46,4 +50,3 @@
 
     register(namespace('security'), 'principal',
              globalRegistry.definePrincipal)
-