[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - IToIRegistry.py:1.1.4.7 ViewService.py:1.1.2.5 hooks.py:1.1.2.13 metaConfigure.py:1.1.2.13
Stephan Richter
srichter@cbu.edu
Fri, 25 Jan 2002 09:00:24 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv17954/ComponentArchitecture
Modified Files:
Tag: Zope-3x-branch
IToIRegistry.py ViewService.py hooks.py metaConfigure.py
Log Message:
- It is now allowed to specify a list of factories when specifying a view.
The factories are listed separated by one whitespace. I make this partial
checkin to show what files were modified. Let me know whether the
modification is done at the right spot and I will add more unit tests and
maybe abstract everything more to support more than one whitespace. I
would also like to know, whether there are other spots too where I should
be making modifications.
=== Zope3/lib/python/Zope/ComponentArchitecture/IToIRegistry.py 1.1.4.6 => 1.1.4.7 ===
self._registerAll(require, primary_provide, c, base)
- def register(self, require, provide, c):
+
+ def register(self, require, provide, maker):
'''
Registers a component.
'''
- if not callable(c):
+ if type(maker) not in (type([]), type(())):
+ maker = [maker]
+ if not maker == filter(callable, maker):
raise TypeError("The registered component callable is not "
"callable")
- self._registerAll(require, provide, c, provide)
+ self._registerAll(require, provide, maker, provide)
+
def _find(self, require, provide):
return self._reg.get((require, provide), None)
=== Zope3/lib/python/Zope/ComponentArchitecture/ViewService.py 1.1.2.4 => 1.1.2.5 ===
for layername in getSkin(object, skin, type):
layer = self.__layers.get(layername)
- if not layer: continue
+ if not layer:
+ continue
reg = layer.get(name, None)
- if reg is None: continue
- c = reg.getForObject(object, type)
- if c is None: continue
- return c(object)
+ if reg is None:
+ continue
+ makers = reg.getForObject(object, type)
+ if makers is None:
+ continue
+
+ result = object
+ for maker in makers:
+ result = maker(result)
+
+ return result
+
if default is _marker:
raise ComponentLookupError(object, name, type)
=== Zope3/lib/python/Zope/ComponentArchitecture/hooks.py 1.1.2.12 => 1.1.2.13 ===
def getAdapter_hook(object, interface, default=None):
if interface.isImplementedBy(object): return object
- c = _adapters.getForObject(object, interface)
- if c is None: return default
- return c(object)
+ makers = _adapters.getForObject(object, interface)
+ if makers is None: return default
+ result = object
+ for maker in makers:
+ result = maker(object)
+ return result
def provideUtility_hook(providedInterface, component):
_utilities.register(providedInterface, component)
=== Zope3/lib/python/Zope/ComponentArchitecture/metaConfigure.py 1.1.2.12 => 1.1.2.13 ===
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
-from hooks import provideAdapter, provideUtility
-from ViewService import provideView
-from ResourceService import provideResource
-from SkinService import defineSkin
-from Zope.Configuration.name import resolve
-from Zope.Configuration import namespace
-from Service import defineService, provideService
-
-def adapter(factory, provides, for_=None):
- if for_ is not None: for_ = resolve(for_)
- provides = resolve(provides)
- return [(
- ('adapter', for_, provides),
- provideAdapter, (for_, provides, resolve(factory))
- )]
-
-def utility(component, provides):
- provides = resolve(provides)
- component = resolve(component)
- return [(
- ('utility', provides),
- provideUtility,(provides, component)
- )]
-
-def view(factory, type, name, for_=None, layer=''):
- if for_ is not None: for_ = resolve(for_)
- type = resolve(type)
- factory = resolve(factory)
- return [(
- ('view', for_, name, type,layer),
- provideView, (for_, name, type, factory, layer)
- )]
-
-def defaultView(factory, type, name, for_=None):
- if for_ is not None: for_ = resolve(for_)
- type = resolve(type)
- factory = resolve(factory)
-
- return [
- (('view', for_, name, type),
- provideView, (for_, name, type, factory)),
- (('view', for_, '', type),
- provideView, (for_, '', type, factory)),
- ]
-
-def resource(component, type, name, layer=''):
- type = resolve(type)
- component = resolve(component)
- return [(
- ('resource', name, type,layer),
- provideResource, (name, type, component, layer)
- )]
-
-def serviceType(name, interface):
- return [(
- ('serviceType', name),
- defineService, (name, resolve(interface))
- )]
-
-def service(name, component):
- component = resolve(component)
- return [(
- ('service', name),
- provideService, (name, component)
- )]
-
-def skin(name, type, layers):
- type = resolve(type)
- layers = [layer.strip() for layer in layers.split(',')]
- return [(
- ('skin', name, type),
- defineSkin, (name, type, layers)
- )]
-
+# This software is subject to the provisions of the Zope Public License,
+# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+
+from hooks import provideAdapter, provideUtility
+from ViewService import provideView
+from ResourceService import provideResource
+from SkinService import defineSkin
+from Zope.Configuration.name import resolve
+from Zope.Configuration import namespace
+from Service import defineService, provideService
+
+def adapter(factory, provides, for_=None):
+ if for_ is not None: for_ = resolve(for_)
+ provides = resolve(provides)
+ return [(
+ ('adapter', for_, provides),
+ provideAdapter, (for_, provides, resolve(factory))
+ )]
+
+def utility(component, provides):
+ provides = resolve(provides)
+ component = resolve(component)
+ return [(
+ ('utility', provides),
+ provideUtility,(provides, component)
+ )]
+
+def view(factory, type, name, for_=None, layer=''):
+ if for_ is not None: for_ = resolve(for_)
+ type = resolve(type)
+ factory = resolve(factory)
+ return [(
+ ('view', for_, name, type,layer),
+ provideView, (for_, name, type, factory, layer)
+ )]
+
+def defaultView(factory, type, name, for_=None):
+ if for_ is not None: for_ = resolve(for_)
+ type = resolve(type)
+ factory = resolve(factory)
+ return [
+ (('view', for_, name, type),
+ provideView, (for_, name, type, factory)),
+ (('view', for_, '', type),
+ provideView, (for_, '', type, factory)),
+ ]
+
+def resource(component, type, name, layer=''):
+ type = resolve(type)
+ component = resolve(component)
+ return [(
+ ('resource', name, type,layer),
+ provideResource, (name, type, component, layer)
+ )]
+
+def serviceType(name, interface):
+ return [(
+ ('serviceType', name),
+ defineService, (name, resolve(interface))
+ )]
+
+def service(name, component):
+ component = resolve(component)
+ return [(
+ ('service', name),
+ provideService, (name, component)
+ )]
+
+def skin(name, type, layers):
+ type = resolve(type)
+ layers = [layer.strip() for layer in layers.split(',')]
+ return [(
+ ('skin', name, type),
+ defineSkin, (name, type, layers)
+ )]
+