[Zope3-checkins] CVS: Zope3/src/zope/component - __init__.py:1.14
interfaces.py:1.15
Jim Fulton
cvs-admin at zope.org
Fri Nov 21 12:09:24 EST 2003
Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv29474/src/zope/component
Modified Files:
__init__.py interfaces.py
Log Message:
Changed to reflect merging view, resource and skin services into the
presentation service.
Simplified the service apis for the adapter and presentation services.
The services no-loner provide get methods. Also, the adapter
service no-longer checks whether an object already implements the
desired interface, since that's done by the outer-level api.
=== Zope3/src/zope/component/__init__.py 1.13 => 1.14 ===
--- Zope3/src/zope/component/__init__.py:1.13 Sun Sep 21 13:34:06 2003
+++ Zope3/src/zope/component/__init__.py Fri Nov 21 12:09:23 2003
@@ -22,7 +22,7 @@
from zope.component.interfaces import IComponentArchitecture
from zope.component.exceptions import ComponentLookupError
from zope.component.service import serviceManager
-from zope.component.servicenames import Adapters, Skins, Resources
+from zope.component.servicenames import Adapters, Presentation
from zope.component.servicenames import Factories
# Try to be hookable. Do so in a try/except to avoid a hard dependence
@@ -132,48 +132,46 @@
def getFactoryInterfaces(context, name):
return getService(context, Factories).getInterfaces(name)
-# Skin service
-def getSkin(wrapped_object, name, view_type):
- return getService(wrapped_object,
- Skins).getSkin(wrapped_object, name, view_type)
-
-# View service
+# Presentation service
def getView(object, name, request, context=None):
v = queryView(object, name, request, context=context)
if v is not None:
return v
-
- raise ComponentLookupError("Couldn't find view", context, name)
+
+ raise ComponentLookupError("Couldn't find view",
+ name, object, context, request)
def queryView(object, name, request, default=None, context=None):
if context is None:
context = object
- return getService(context,
- 'Views').queryView(object, name, request, default)
+ s = getService(context, Presentation)
+ return s.queryView(object, name, request, default=default)
queryView = hookable(queryView)
def getDefaultViewName(object, request, context=None):
- if context is None:
- context = object
- return getService(context, 'Views').getDefaultViewName(object, request)
+ v = queryDefaultViewName(object, request, context=context)
+ if v is not None:
+ return v
+
+ raise ComponentLookupError("Couldn't find default view name",
+ context, request)
def queryDefaultViewName(object, request, default=None, context=None):
if context is None:
context = object
- return getService(context,
- 'Views').queryDefaultViewName(object, request, default)
-
-# Resource service
+ s = getService(context, Presentation)
+ return s.queryDefaultViewName(object, request, default)
def getResource(wrapped_object, name, request):
- return getService(wrapped_object,
- Resources).getResource(
- wrapped_object, name, request)
-
-def queryResource(wrapped_object, name, request, default=None):
- return getService(wrapped_object,
- Resources).queryResource(
- wrapped_object, name, request, default)
+ v = queryResource(wrapped_object, name, request)
+ if v is not None:
+ return v
+
+ raise ComponentLookupError("Couldn't find resource", name, request)
+
+def queryResource(context, name, request, default=None):
+ s = getService(context, Presentation)
+ return s.queryResource(name, request, default)
=== Zope3/src/zope/component/interfaces.py 1.14 => 1.15 ===
--- Zope3/src/zope/component/interfaces.py:1.14 Sun Sep 21 13:34:08 2003
+++ Zope3/src/zope/component/interfaces.py Fri Nov 21 12:09:23 2003
@@ -166,20 +166,7 @@
context, and returns the interface or interface tuple that
object instances created by the named factory will implement."""
- # Skin service
-
- def getSkin(wrapped_object, name, view_type):
- """Get a skin definition as a sequence of layers
-
- Returns the nearest skin (sequence of layer names) to the
- object, as specified by the name and the view type (browser,
- xml-rpc, etc.) as expressed by an interface. If a matching
- skin is not found, raises ComponentLookupError
-
- There is a predefined skin in the global skin service, '', with
- a single layer, ''."""
-
- # View service
+ # Presentation service
def getView(object, name, request, context=None):
"""Get a named view for a given object.
@@ -232,8 +219,6 @@
"""
- # Resource service
-
def getResource(wrapped_object, name, request):
"""Get a named resource for a given request
@@ -380,25 +365,17 @@
class IAdapterService(Interface):
- def getAdapter(object, interface):
- """Get an adapter to an interface for an object
-
- If the object has a __conform__ method, this method will be
- called with the requested interface. If the method returns a
- non-None value, that value will be returned. Otherwise, if the
- object already implements the interface, the object will be
- returned.
+ def queryAdapter(object, interface, default=None):
+ """Look for an adapter to an interface for an object
- If a matching adapter cannot be found, raises
- ComponentLookupError.
+ If a matching adapter cannot be found, returns the default.
"""
- def getNamedAdapter(object, interface, name):
- """Get a named adapter to an interface for an object
+ def queryNamedAdapter(object, interface, name, default=None):
+ """Look for a named adapter to an interface for an object
- If a matching adapter cannot be found, raises
- ComponentLookupError.
+ If a matching adapter cannot be found, returns the default.
The name consisting of an empty string is reserved for unnamed
adapters. The unnamed adapter methods will often call the
@@ -406,20 +383,7 @@
"""
- def queryAdapter(object, interface, default=None):
- """Look for an adapter to an interface for an object
-
- If the object has a __conform__ method, this method will be
- called with the requested interface. If the method returns a
- non-None value, that value will be returned. Otherwise, if the
- object already implements the interface, the object will be
- returned.
-
- If a matching adapter cannot be found, returns the default.
-
- """
-
- def queryNamedAdapter(object, interface, name, default=None):
+ def queryMultiAdapter(objects, interface, name, default=None):
"""Look for a named adapter to an interface for an object
If a matching adapter cannot be found, returns the default.
@@ -431,7 +395,7 @@
"""
# XXX need to add name support
- def getRegisteredMatching(for_interfaces=None, provided_interfaces=None):
+ def getRegisteredMatching(required=None, provided=None):
"""Return information about registered data
Zero or more for and provided interfaces may be
@@ -451,39 +415,6 @@
"""
-class IGlobalAdapterService(IAdapterService):
-
- def provideAdapter(forInterface, providedInterface, maker, name=''):
- """Provide an adapter
-
- An adapter provides an interface for objects that have another
- interface.
-
- Arguments:
-
- forInterface -- The interface the adapter provides an interface for.
-
- providedInterface -- The provided interface
-
- maker -- a sequence of factories that are used to create the adapter.
- The first factory is called with the object to be adapted, subsequent
- factories are called with the results of the previous factory.
- """
- def getRegisteredMatching(for_interface=None, provide_interface=None,
- name=None):
- """Return information about registered data
-
- A four-tuple is returned containing:
-
- - registered name,
-
- - registered for interface
-
- - registered provided interface, and
-
- - registered data
- """
-
class IPresentation(Interface):
"""Presentation components provide interfaces to external actors
@@ -505,13 +436,6 @@
"""An IPresentationRequest provides methods for getting view meta data.
"""
- def getPresentationType():
- """Get a view type
-
- The view type is expressed as an interface, as would be passed
- to IViewService.getView.
- """
-
def getPresentationSkin():
"""Get the skin to be used for a request.
@@ -532,30 +456,6 @@
"""
-class IResourceService(Interface):
-
- def getResource(object, name, request):
- """Look up a named resource for a given request
-
- The request must implement IPresentationRequest.
-
- The object provides a place to look for placeful resources.
-
- A ComponentLookupError will be
- raised if the component can't be found.
- """
-
- def queryResource(object, name, request, default=None):
- """Look up a named resource for a given request
-
- The request must implement IPresentationRequest.
-
- The object provides a place to look for placeful resources.
-
- The default will be returned if the component can't be found.
- """
-
-
class IView(IPresentation, IContextDependent):
"""Views provide a connection between an external actor and an object
"""
@@ -572,85 +472,32 @@
"stands in" for the user.
"""
+class IPresentationService(Interface):
-
-class IViewService(Interface):
-
- def getView(object, name, request):
- """Get a named view for a given object and request
-
+ def queryResource(name, request, providing=Interface, default=None):
+ """Look up a named resource for a given request
+
The request must implement IPresentationRequest.
-
- The object also provides a place to look for placeful views.
-
- A ComponentLookupError will be
- raised if the component can't be found.
+
+ The default will be returned if the component can't be found.
"""
- def queryView(object, name, request, default=None):
+ def queryView(object, name, request, providing=Interface, default=None):
"""Look for a named view for a given object and request
The request must implement IPresentationRequest.
- The object also provides a place to look for placeful views.
-
- The default will be returned
- if the component can't be found.
- """
-
- def getDefaultViewName(object, request):
- """Get the name of the default view for the object and request
-
- The request must implement IPresentationRequest.
-
- A NotFoundError will be raised if the suitable
- default view name for the object cannot be found.
- """
-
- def queryDefaultViewName(object, request, default=None):
- """Look for the name of the default view for the object and request
-
- The request must implement IPresentationRequest.
-
- The default will be returned if a suitable
- default view name for the object cannot be found.
- """
-
-class IGlobalViewService(IViewService):
-
- def setDefaultViewName(i_required, i_provided, name):
- """Add name to registry of default view names for interfaces given."""
-
- def provideView(forInterface, name, type, factory, layer='default'):
- """Register a view factory
-
- The factory is a sequence. The last object in the sequence
- must be an IViewFactory. The other objects in the sequence
- must be adapter factories.
-
- XXX I'm not sure if there are right.
- The name is the view name.
- The type is the presentation type.
- """
-
- def getRegisteredMatching(required_interfaces=None, presentation_type=None,
- viewName=None, layer=None):
- """Return registration info matching keyword arg criteria.
-
- Return is an iterable 5-tuples containing:
- - required interface
- - provided interface
- - chain of factories
- - layer
- - view name
+ The default will be returned if the component can't be found.
"""
-class ISkinService(Interface):
-
- def getSkin(object, name, view_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.
- """
+ def queryMultiView(objects, name, request, providing=Interface,
+ default=None):
+ """Adapt the given objects and request
+
+ The first argument is a tuple of objects to be adapted with the
+ request.
+ """
+
+
+
+
More information about the Zope3-Checkins
mailing list