[Zope3-checkins] CVS: Zope3/src/zope/app/component -
metaconfigure.py:1.32
Jim Fulton
jim at zope.com
Thu Mar 18 07:19:23 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv2050/src/zope/app/component
Modified Files:
metaconfigure.py
Log Message:
Fixed bugs in handling of multiple factories in views;
views require different combined-factory generation logic.
Changed the multiple-factory check to disallow multiple
factories when there no required interfaces.
=== Zope3/src/zope/app/component/metaconfigure.py 1.31 => 1.32 ===
--- Zope3/src/zope/app/component/metaconfigure.py:1.31 Mon Mar 15 15:41:56 2004
+++ Zope3/src/zope/app/component/metaconfigure.py Thu Mar 18 07:19:22 2004
@@ -80,12 +80,22 @@
return ob
-def reduce_factories(factories, for_):
+def adapter(_context, factory, provides, for_, permission=None, name=''):
+ if permission is not None:
+ if permission == PublicPermission:
+ permission = CheckerPublic
+ checker = InterfaceChecker(provides, permission)
+ factory.append(lambda c: proxify(c, checker))
+
+ for_ = tuple(for_)
+
+ # Generate a single factory from multiple factories:
+ factories = factory
if len(factories) == 1:
factory = factories[0]
elif len(factories) < 1:
raise ValueError("No factory specified")
- elif len(factories) > 1 and len(for_) > 1:
+ elif len(factories) > 1 and len(for_) != 1:
raise ValueError("Can't use multiple factories and multiple for")
else:
def factory(ob):
@@ -93,22 +103,11 @@
ob = f(ob)
return ob
- return factory
-
-def adapter(_context, factory, provides, for_, permission=None, name=''):
- if permission is not None:
- if permission == PublicPermission:
- permission = CheckerPublic
- checker = InterfaceChecker(provides, permission)
- factory.append(lambda c: proxify(c, checker))
-
- for_ = tuple(for_)
-
_context.action(
discriminator = ('adapter', for_, provides, name),
callable = checkingHandler,
args = (permission, Adapters, 'register',
- for_, provides, name, reduce_factories(factory, for_)),
+ for_, provides, name, factory),
)
_context.action(
discriminator = None,
@@ -248,12 +247,25 @@
raise ValueError("No for interfaces specified");
for_ = tuple(for_)
+ # Generate a single factory from multiple factories:
+ factories = factory
+ if len(factories) == 1:
+ factory = factories[0]
+ elif len(factories) < 1:
+ raise ValueError("No factory specified")
+ elif len(factories) > 1 and len(for_) > 1:
+ raise ValueError("Can't use multiple factories and multiple for")
+ else:
+ def factory(ob, request):
+ for f in factories[:-1]:
+ ob = f(ob)
+ return factories[-1](ob, request)
+
_context.action(
discriminator = ('view', for_, name, type, layer, provides),
callable = checkingHandler,
args = (permission, Presentation, 'provideAdapter',
- type, reduce_factories(factory, for_), name, for_,
- provides, layer),
+ type, factory, name, for_, provides, layer),
)
_context.action(
discriminator = None,
More information about the Zope3-Checkins
mailing list