[Zope3-checkins] CVS: Zope3/src/zope/app/component -
metadirectives.py:1.14 metaconfigure.py:1.31
Jim Fulton
jim at zope.com
Mon Mar 15 15:41:57 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv3257/src/zope/app/component
Modified Files:
metadirectives.py metaconfigure.py
Log Message:
Changed to reflect that adapters and views are registered:
- Using a new api
- Multiple for
- single factory
If multiple factories are provided in zcml, we generate a single
factory that calls the multiple
Changes to allow multiple for interfaces. This still needs tests, so
not yet done.
=== Zope3/src/zope/app/component/metadirectives.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/component/metadirectives.py:1.13 Tue Mar 9 07:39:25 2004
+++ Zope3/src/zope/app/component/metadirectives.py Mon Mar 15 15:41:56 2004
@@ -41,14 +41,13 @@
"""
This is the basic information for all views.
"""
-
- for_ = GlobalObject(
- title=u"The interface this view applies to.",
- description=u"""
- The view will be for all objects that implement this
- interface. If this is not supplied, the view applies to all
- objects (XXX this ought to change).""",
- required=False
+
+ for_ = Tokens(
+ title=u"Specifications of the objects to be viewed",
+ description=u"""This should be a list of interfaces or classes
+ """,
+ required=True,
+ value_type=GlobalObject(missing_value=object())
)
permission = Id(
@@ -158,10 +157,12 @@
required=True
)
- for_ = GlobalObject(
- title=u"Interface the component is used for",
- description=u"""This is the interface from which is being adapted.""",
- required=True
+ for_ = Tokens(
+ title=u"Specifications to be adapted",
+ description=u"""This should be a list of interfaces or classes
+ """,
+ required=True,
+ value_type=GlobalObject(missing_value=object())
)
permission = Id(
=== Zope3/src/zope/app/component/metaconfigure.py 1.30 => 1.31 ===
--- Zope3/src/zope/app/component/metaconfigure.py:1.30 Sat Mar 13 18:54:58 2004
+++ Zope3/src/zope/app/component/metaconfigure.py Mon Mar 15 15:41:56 2004
@@ -80,6 +80,20 @@
return ob
+def reduce_factories(factories, for_):
+ 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):
+ for f in factories:
+ ob = f(ob)
+ return ob
+
+ return factory
def adapter(_context, factory, provides, for_, permission=None, name=''):
if permission is not None:
@@ -88,24 +102,27 @@
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, 'provideAdapter',
- for_, provides, factory, name),
+ args = (permission, Adapters, 'register',
+ for_, provides, name, reduce_factories(factory, for_)),
)
_context.action(
discriminator = None,
callable = provideInterface,
args = ('', provides)
)
- if for_ is not None:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = ('', for_)
- )
+ if for_:
+ for iface in for_:
+ if iface is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', iface)
+ )
def utility(_context, provides, component=None, factory=None,
permission=None, name=''):
@@ -140,7 +157,8 @@
if description is not None:
component.description = description
- utility(_context, IFactory, component, permission=PublicPermission, name=id)
+ utility(_context, IFactory, component,
+ permission=PublicPermission, name=id)
def _checker(_context, permission, allowed_interface, allowed_attributes):
@@ -205,9 +223,6 @@
permission=None, allowed_interface=None, allowed_attributes=None,
provides=Interface):
- if for_ == '*':
- for_ = None
-
if ((allowed_attributes or allowed_interface)
and (not permission)):
raise ConfigurationError(
@@ -228,11 +243,17 @@
factory[-1] = proxyView
+
+ if not for_:
+ raise ValueError("No for interfaces specified");
+ for_ = tuple(for_)
+
_context.action(
discriminator = ('view', for_, name, type, layer, provides),
callable = checkingHandler,
- args = (permission, Presentation, 'provideView', for_, name,
- type, factory, layer, provides),
+ args = (permission, Presentation, 'provideAdapter',
+ type, reduce_factories(factory, for_), name, for_,
+ provides, layer),
)
_context.action(
discriminator = None,
@@ -246,38 +267,41 @@
)
if for_ is not None:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = (for_.__module__+'.'+for_.getName(),
- for_)
- )
+ for iface in for_:
+ if iface is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', iface)
+ )
def defaultView(_context, type, name, for_, **__kw):
- if for_ == '*':
- for_ = None
-
if __kw:
view(_context, type=type, name=name, for_=for_, **__kw)
- _context.action(
- discriminator = ('defaultViewName', for_, type, name),
- callable = handler,
- args = (Presentation, 'setDefaultViewName', for_, type, name),
- )
+ if len(for_) == 1:
+ _context.action(
+ discriminator = ('defaultViewName', for_[0], type, name),
+ callable = handler,
+ args = (Presentation, 'setDefaultViewName', for_[0], type, name),
+ )
+ else:
+ raise TypeError("Can't use multiple for in defaultView")
+
_context.action(
discriminator = None,
callable = provideInterface,
- args = (type.__module__+'.'+type.getName(), type)
+ args = ('', type)
)
- if for_ is not None:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = (for_.__module__+'.'+for_.getName(), for_)
- )
+ for iface in for_:
+ if iface is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', iface)
+ )
def serviceType(_context, id, interface):
_context.action(
More information about the Zope3-Checkins
mailing list