[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - IResourceService.py:1.1.2.1 ISkinService.py:1.1.2.1 ResourceService.py:1.1.2.1 SkinService.py:1.1.2.1 IToIRegistry.py:1.1.4.6 IViewService.py:1.1.2.3 ViewService.py:1.1.2.4 __init__.py:1.1.6.11 metaConfigure.py:1.1.2.12
Jim Fulton
jim@zope.com
Mon, 14 Jan 2002 08:43:22 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv29617/ComponentArchitecture
Modified Files:
Tag: Zope-3x-branch
IToIRegistry.py IViewService.py ViewService.py __init__.py
metaConfigure.py
Added Files:
Tag: Zope-3x-branch
IResourceService.py ISkinService.py ResourceService.py
SkinService.py
Log Message:
Factored skin service from view service.
Made skins type-dependent. IOW, skins for Browsers are different from
skins for FTP.
Added resource components, which are to views as utilities are to
adapters. They provide interface-specific components that do not
extend or depend on some specific other component. Like views, they
are named and are specific to a particulat presentation type.
We nee resources to deal with things like images and style sheets.
Added tests for browser directives.
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/IResourceService.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Revision information: $Id: IResourceService.py,v 1.1.2.1 2002/01/14 13:42:50 jim Exp $
"""
from Interface import Interface
class IResourceService(Interface):
def provideResource(name, type, component, layer=''):
"""Provide a resource
A resource is an inependent component that provides a view
type. It is like a view except that it acts by itself,
typically to support views. Common resources include images,
style sheets, ets.
Arguments:
name -- The resource name
type -- The resource type, expressed as an interface
component -- the resource component.
layer -- Optional skin layer. Layers are used to define skins.
"""
def getResource(object, name, type, default=None, skin=''):
"""Look up a named resource of a given type
The type is expressed as an interface.
The object provides a place to look for placeful resources.
A Zope.ComponentArchitecture.ComponentLookupError will be
raised if the component can't be found.
"""
def getRequestResource(object, name, request, default=None):
"""Look up a named resource for a given request
The request must implement IViewRequest.
The object provides a place to look for placeful resources.
A Zope.ComponentArchitecture.ComponentLookupError will be
raised if the component can't be found.
"""
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/ISkinService.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Revision information: $Id: ISkinService.py,v 1.1.2.1 2002/01/14 13:42:50 jim Exp $
"""
from Interface import Interface
class ISkinService(Interface):
def defineSkin(skin, type, layers):
"""Define a skin for a given view type as a sequence of layers
There is a predefined skin, '', with a single layer, ''.
"""
def getSkin(object, skin, type):
"""Return the sequence of layers (names) making up the skin.
The object provides a place to look for placeful skin definitions.
If the skin was not defined, an empty sequence will be returned.
"""
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/ResourceService.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Revision information: $Id: ResourceService.py,v 1.1.2.1 2002/01/14 13:42:50 jim Exp $
"""
from IToIRegistry import IRegistry
from Exceptions import ComponentLookupError
from SkinService import getSkin
from IResourceService import IResourceService
_marker = object()
class ResourceService:
def __init__(self):
self.__layers = {}
__implements__ = IResourceService
# Implementation methods for interface
# Zope.ComponentArchitecture.IResourceService.
def getResource(self, object, name, type, default=_marker, skin=''):
'''See interface IResourceService'''
for layername in getSkin(object, skin, type):
layer = self.__layers.get(layername)
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
if default is _marker:
raise ComponentLookupError(object, name, type)
return default
def getRequestResource(self, object, name, request, default=_marker):
'''See interface IResourceService'''
type = request.getViewType()
skin = request.getViewSkin()
return self.getResource(object, name, type, default, skin)
def provideResource(self, name, type, component, layer=''):
'''See interface IResourceService'''
resources = self.__layers.get(layer)
if resources is None:
resources = self.__layers[layer] = {}
reg = resources.get(name, None)
if reg is None:
reg = resources[name] = IRegistry()
reg.register(type, component)
def _clear(self):
self.__init__()
resourceService = ResourceService()
getResource = resourceService.getResource
provideResource = resourceService.provideResource
getRequestResource = resourceService.getRequestResource
_clear = resourceService._clear
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/SkinService.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Revision information: $Id: SkinService.py,v 1.1.2.1 2002/01/14 13:42:50 jim Exp $
"""
from IToIRegistry import IToIRegistry
from Exceptions import ComponentLookupError
from ISkinService import ISkinService
from IToIRegistry import DataRegistry
_default = ('',)
class SkinService:
def __init__(self):
self.__skins = {}
__implements__ = ISkinService
# Implementation methods for interface
# Zope.ComponentArchitecture.ISkinService.
def defineSkin(self, skin, type, layers):
'''See interface ISkinService'''
reg = self.__skins.get(skin, None)
if reg is None:
reg = self.__skins[skin] = DataRegistry()
reg.register(type, layers)
def getSkin(self, object, skin, type):
'''See interface ISkinService'''
reg = self.__skins.get(skin, None)
if reg is not None:
layers = reg.getForObject(object, type)
if layers is not None:
return layers
if not skin:
return _default
return ()
def _clear(self):
self.__init__()
skinService = SkinService()
defineSkin = skinService.defineSkin
getSkin = skinService.getSkin
_clear = skinService._clear
=== Zope3/lib/python/Zope/ComponentArchitecture/IToIRegistry.py 1.1.4.5 => 1.1.4.6 ===
class IRegistry(IToIRegistry):
-
def register(self, provide, c):
'''
@@ -94,23 +93,10 @@
self._registerAll(None, provide, c, provide)
+class DataRegistry(IToIRegistry):
-class IToIRegistryWithLabels (IToIRegistry):
- """
- Supports the use of label interfaces for inputs.
- """
- def register(self, require, provide, c):
+ def register(self, provide, c):
'''
- Registers a component.
+ Registers data for an interface.
'''
- if isinstance(require, LabelInterface):
- # register the name instead of the interface.
- require = require.getName()
- self._registerAll(require, provide, c, provide)
-
- def _find(self, require, provide):
- if isinstance(require, LabelInterface):
- # Look up the name instead of the interface.
- return self._reg.get((require.getName(), provide), None)
- else:
- return self._reg.get((require, provide), None)
+ self._registerAll(None, provide, c, provide)
=== Zope3/lib/python/Zope/ComponentArchitecture/IViewService.py 1.1.2.2 => 1.1.2.3 ===
class IViewService(Interface):
- def defineSkin(skin, layers):
- """Define a skin as a sequence of layers
-
- There is a predefined skin, '', with a single layer, ''.
- """
-
def provideView(forInterface, name, type, maker, layer=''):
"""Provide a view
=== Zope3/lib/python/Zope/ComponentArchitecture/ViewService.py 1.1.2.3 => 1.1.2.4 ===
from IToIRegistry import IToIRegistry
from Exceptions import ComponentLookupError
+from SkinService import getSkin
+from IViewService import IViewService
_marker = object()
class ViewService:
def __init__(self):
- self.__skins = {'': ('',)}
self.__layers = {}
+
+ __implements__ = IViewService
# Implementation methods for interface
# Zope.ComponentArchitecture.IViewService.
-
def getView(self, object, name, type, default=_marker, skin=''):
'''See interface IViewService'''
- for layername in self.__skins.get(skin, ()):
+ for layername in getSkin(object, skin, type):
layer = self.__layers.get(layername)
if not layer: continue
reg = layer.get(name, None)
@@ -68,18 +70,11 @@
reg.register(forInterface, type, maker)
-
-
- def defineSkin(self, skin, layers):
- '''See interface IViewService'''
- self.__skins[skin] = layers
-
def _clear(self):
self.__init__()
viewService = ViewService()
-getView = viewService.getView
-provideView = viewService.provideView
+getView = viewService.getView
+provideView = viewService.provideView
getRequestView = viewService.getRequestView
-defineSkin = viewService.defineSkin
-_clear = viewService._clear
+_clear = viewService._clear
=== Zope3/lib/python/Zope/ComponentArchitecture/__init__.py 1.1.6.10 => 1.1.6.11 ===
from hooks import provideFactory, createObject
from Service import defineService, provideService, getService
-from ViewService import getView, provideView, defineSkin, getRequestView
+from SkinService import getSkin, defineSkin
+from ViewService import getView, provideView, getRequestView
+from ResourceService import getResource, provideResource, getRequestResource
def _clear():
from hooks import _clear; _clear()
from Service import _clear; _clear()
from ViewService import _clear; _clear()
+ from ResourceService import _clear; _clear()
+ from SkinService import _clear; _clear()
__implements__ = IComponentArchitecture
=== Zope3/lib/python/Zope/ComponentArchitecture/metaConfigure.py 1.1.2.11 => 1.1.2.12 ===
from hooks import provideAdapter, provideUtility
-from ViewService import provideView, defineSkin
+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
@@ -48,6 +50,14 @@
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),
@@ -61,10 +71,11 @@
provideService, (name, component)
)]
-def skin(name, layers):
+def skin(name, type, layers):
+ type = resolve(type)
layers = [layer.strip() for layer in layers.split(',')]
return [(
- ('skin', name),
- defineSkin, (name, layers)
+ ('skin', name, type),
+ defineSkin, (name, type, layers)
)]