[Zope3-checkins] SVN: Zope3/trunk/src/zope/component/ The presentation service is gone.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:24:14 EDT 2004


Log message for revision 27607:
  The presentation service is gone.
  


Changed:
  D   Zope3/trunk/src/zope/component/presentation.py
  U   Zope3/trunk/src/zope/component/tests/placelesssetup.py
  D   Zope3/trunk/src/zope/component/tests/test_presentation.py


-=-
Deleted: Zope3/trunk/src/zope/component/presentation.py
===================================================================
--- Zope3/trunk/src/zope/component/presentation.py	2004-09-17 16:16:56 UTC (rev 27606)
+++ Zope3/trunk/src/zope/component/presentation.py	2004-09-17 16:24:14 UTC (rev 27607)
@@ -1,539 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.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.
-#
-##############################################################################
-"""Global Presentation Service
-
-This module contains an adapter-registry-based global presentation
-service. Additionally it contains all registration classes that can occur:
-
-  - SkinRegistration
-
-  - LayerRegistration
-
-  - DefaultSkinRegistration
-
-  - PresentationRegistration
-
-$Id$
-"""
-from types import ClassType
-from zope.component.interfaces import IPresentationService, IRegistry
-from zope.component.service import GlobalService
-from zope.component.servicenames import Presentation
-from zope.interface import providedBy
-from zope.interface.interfaces import IInterface
-import zope.interface
-import zope.interface.adapter
-
-class IGlobalPresentationService(zope.interface.Interface):
-    """Provide ability to update the global presentation service
-    """
-
-    def defineSkin(name, layers):
-        """Define a skin
-
-        A skin is defined for a request type.  It consists of a
-        sequence of layer names.  Layers must be defined before they
-        are used in a skin definition.
-
-        Note that there is one predefined layer, "default".
-        """
-
-    def setDefaultSkin(name):
-        """Set the default skin for a request type
-
-        If not set, it defaults to the "default" skin.
-        """
-
-    def defineLayer(name):
-        """Define a layer
-        """
-
-    def provideAdapter(request_type, factory, name='', contexts=(),
-                       providing=zope.interface.Interface, layer='default'):
-        """Provide a presentation adapter
-        """
-
-class IDefaultViewName(zope.interface.Interface):
-    """A string that contains the default view name
-
-    A default view name is used to select a view when a user hasn't
-    specified one.
-    """
-
-class GlobalPresentationService(GlobalService):
-    r"""Global presentation service
-
-       The global presentation service provides management of views, and
-       resources arranged in skins, where skins are ordered collections
-       of layers.
-
-       Views are modeled as adapters of objects and requests.
-       Resources are just request adapters.
-
-       The adapters are arranged in layers.
-
-       Let's look at some examples. First, we'll create a service:
-
-       >>> s = GlobalPresentationService()
-
-       And define a custom layer and skin:
-
-       >>> s.defineLayer('custom')
-       >>> s.defineSkin('custom', ['custom', 'default'])
-
-       We'll define a request type and a fake request:
-
-       >>> class IRequest(zope.interface.Interface):
-       ...     "Demonstration request type"
-
-       >>> class Request(object):
-       ...     zope.interface.implements(IRequest)
-       ...     def getPresentationSkin(self):
-       ...         return getattr(self, 'skin', None)
-
-
-       >>> request = Request()
-
-       With this in place, we can start registering resources. A resource
-       is just a request adapter.
-
-       >>> class MyResource(object):
-       ...    def __init__(self, request):
-       ...        self.request = request
-
-       To register a resource, we register it as an adapter. Most
-       resources are going to interface with a user, and, so, don't
-       really provide a programatic interface. For this reason, we
-       register them to provide the empty interface, Interface, which is
-       the default provided interface:
-
-       >>> s.provideAdapter(IRequest, MyResource, name='foo', layer='custom')
-
-       Now we can try to look this up:
-
-       >>> s.queryResource('foo', request)
-
-       But we won't get anything, because our request doesn't specify a
-       skin and, the default skin gets used.  Our resource was registered
-       in the custom layer, which isn't used by the default skin. If we
-       set out request skin to 'custom':
-
-       >>> request.skin = 'custom'
-
-       Then the lookup will suceed:
-
-       >>> r = s.queryResource('foo', request)
-       >>> r.__class__.__name__
-       'MyResource'
-       >>> r.request is request
-       True
-
-       Views are registered as "multi" adapters.  Multi-adapters adapt
-       multiple objects simultaneously.
-
-       >>> class IContact(zope.interface.Interface):
-       ...     "Demonstration content type"
-
-       >>> class MyView(object):
-       ...     def __init__(self, context, request):
-       ...         self.context, self.request = context, request
-
-       >>> s.provideAdapter(IRequest, MyView, contexts=[IContact], 
-       ...                  name='foo', layer='custom')
-
-       When defining views, we provide one or more (typically 1) context
-       interfaces, corresponding to the contexts of the view.
-
-       >>> class Contact(object):
-       ...     zope.interface.implements(IContact)
-
-       >>> c = Contact()
-
-       We look up views with queryView:
-
-       >>> v = s.queryView(c, 'foo', request)
-       >>> v.__class__.__name__
-       'MyView'
-       >>> v.request is request
-       True
-       >>> v.context is c
-       True
-
-       Most views and resources are unnamed and provide no interface. We
-       can also have views that provide interfaces.  For example, we
-       might need a view to help out with finding objects:
-
-       >>> class ITraverse(zope.interface.Interface):
-       ...     "Sample traversal interface (imagine interesting methods :)"
-
-       >>> class Traverser(object):
-       ...     zope.interface.implements(ITraverse)
-       ...     def __init__(self, context, request):
-       ...         self.context, self.request = context, request
-
-       which we register using the provided interface, rather than a name. 
-
-       >>> s.provideAdapter(IRequest, Traverser, contexts=[IContact],
-       ...                  providing=ITraverse, layer='custom')
-
-       (We could use a name too, if we wanted to.)
-
-       Then we look up the view using the interface:
-
-       >>> v = s.queryView(c, '', request, providing=ITraverse)
-       >>> v.__class__.__name__
-       'Traverser'
-       >>> v.request is request
-       True
-       >>> v.context is c
-       True
-       """
-
-    zope.interface.implements(IPresentationService,
-                              IGlobalPresentationService,
-                              IRegistry,
-                              )
-
-    def __init__(self):
-        self._layers = {'default': GlobalLayer(self, 'default')}
-        self._skins = {'default': [self._layers['default']]}
-        self.skins = {'default': ('default', )}
-        self.defaultSkin = 'default'
-        self._registrations = {}
-
-    def registrations(self):
-        return self._registrations.itervalues()
-
-    def defineSkin(self, name, layers, info=''):
-        """Define a skin
-
-        A skin is defined for a request type.  It consists of a
-        sequence of layer names.  Layers must be defined before they
-        are used in a skin definition.
-
-        Note that there is one predefined layer, "default".
-
-        >>> s = GlobalPresentationService()
-        >>> s.defineSkin('default', ['default'])
-        Traceback (most recent call last):
-        ...
-        ValueError: ("Can\'t redefine skin", 'default')
-
-
-        The layers used in a skin definition must be defined before
-        they are used:
-
-        >>> s.defineSkin('custom', ['custom', 'default'])
-        Traceback (most recent call last):
-        ...
-        ValueError: ('Undefined layers', ['custom'])
-
-
-        >>> s.defineLayer('custom')
-        >>> s.defineSkin('custom', ['custom', 'default'], 'custom doc')
-
-        >>> skins = s.skins.items()
-        >>> skins.sort()
-        >>> skins
-        [('custom', ('custom', 'default')), ('default', ('default',))]
-
-        A skin registration is also recorded for each registered skin.
-
-        >>> registrations = map(str, s.registrations())
-        >>> registrations.sort()
-        >>> for r in registrations:
-        ...     print r
-        zope.component.presentation.LayerRegistration('custom', '')
-        zope.component.presentation.SkinRegistration('custom', """ \
-                              """['custom', 'default'], 'custom doc')
-        """
-
-        if name in self._skins:
-            raise ValueError("Can't redefine skin", name)
-
-        bad = [layer for layer in layers if layer not in self._layers]
-        if bad:
-            raise ValueError, ("Undefined layers", bad)
-
-        self._skins[name] = [self._layers[layer] for layer in layers]
-        self.skins[name] = tuple(layers)
-        self._registrations[('skin', name)
-                            ] = SkinRegistration(name, layers, info)
-
-    def querySkin(self, name):
-        return self.skins.get(name)
-
-    def queryLayer(self, name):
-        return self._layers.get(name)
-
-    def setDefaultSkin(self, name, info=''):
-        """Set the default skin for a request type
-
-        If not set, it defaults to the "default" skin.
-
-        >>> s = GlobalPresentationService()
-        >>> s.defaultSkin
-        'default'
-
-        >>> s.setDefaultSkin('custom')
-        Traceback (most recent call last):
-        ...
-        ValueError: ('Undefined skin', 'custom')
-
-        >>> s.defineLayer('custom')
-        >>> s.defineSkin('custom', ['custom', 'default'])
-        >>> s.setDefaultSkin('custom', 'yawn')
-        >>> s.defaultSkin
-        'custom'
-
-        A default skin registration is also recorded for each
-        registered default skin.
-
-        >>> registrations = map(str, s.registrations())
-        >>> registrations.sort()
-        >>> for r in registrations:
-        ...     print r
-        zope.component.presentation.DefaultSkinRegistration('custom', 'yawn')
-        zope.component.presentation.LayerRegistration('custom', '')
-        zope.component.presentation.SkinRegistration('custom', """ \
-                       """['custom', 'default'], '')
-        """
-
-        # Make sure we are refering to a defined skin
-        if name not in self._skins:
-            raise ValueError, ("Undefined skin", name)
-
-        self.defaultSkin = name
-        self._registrations['defaultSkin'
-                            ] = DefaultSkinRegistration(name, info)
-
-    def defineLayer(self, name, info=''):
-        """Define a layer
-
-        >>> s = GlobalPresentationService()
-        >>> s.defineLayer('custom', 'blah')
-
-        You can't define a layer that's already defined:
-
-        >>> s.defineLayer('custom')
-        Traceback (most recent call last):
-        ...
-        ValueError: ("Can\'t redefine layer", 'custom')
-
-        A layer registration is also recorded for each registered layer.
-
-        >>> list(s.registrations())
-        [zope.component.presentation.LayerRegistration('custom', 'blah')]
-        """
-
-        if name in self._layers:
-            raise ValueError("Can\'t redefine layer", name)
-
-        self._layers[name] = GlobalLayer(self, name)
-        self._registrations[('layer', name)] = LayerRegistration(name, info)
-
-    def provideAdapter(self, request_type, factory, name=u'', contexts=(), 
-                       providing=zope.interface.Interface, layer='default',
-                       info=''):
-        """Provide a presentation adapter
-
-        This is a fairly low-level interface that supports both
-        resources and views.
-
-        """
-
-        ifaces = []
-        for context in contexts:
-            if not IInterface.providedBy(context) and context is not None:
-                if not isinstance(context, (type, ClassType)):
-                    raise TypeError(context, IInterface)
-                context = zope.interface.implementedBy(context)
-
-            ifaces.append(context)
-
-        ifaces.append(request_type)
-        ifaces = tuple(ifaces)
-
-        reg = self._layers[layer]
-
-        reg.register(ifaces, providing, name, factory)
-
-        self._registrations[
-            (layer, ifaces, providing, name)
-            ] = PresentationRegistration(layer, ifaces, providing, name,
-                                         factory, info)
-
-    def queryResource(self, name, request, default=None,
-                      providing=zope.interface.Interface):
-        """Look up a named resource for a given request
-
-        The request must implement IPresentationRequest.
-
-        The default will be returned if the component can't be found.
-        """
-        skin = request.getPresentationSkin() or self.defaultSkin
-        for layer in self._skins[skin]:
-            r = layer.queryAdapter(request, providing, name)
-            if r is not None:
-                return r
-        return default
-
-    def queryView(self, object, name, request,
-                  providing=zope.interface.Interface, default=None):
-        """Look for a named view for a given object and request
-
-        The request must implement IPresentationRequest.
-
-        The default will be returned if the component can't be found.
-        """
-        skin = request.getPresentationSkin() or self.defaultSkin
-        objects = object, request
-        for layer in self._skins.get(skin, ()):
-            r = layer.queryMultiAdapter(objects, providing, name)
-            if r is not None:
-                return r
-        return default
-
-    def queryMultiView(self, objects, request,
-                       providing=zope.interface.Interface, name='',
-                       default=None):
-        """Adapt the given objects and request
-
-        The first argument is a sequence of objects to be adapted with the
-        request.
-        """
-        skin = request.getPresentationSkin() or self.defaultSkin
-        objects = objects + (request, )
-        for layer in self._skins[skin]:
-            r = layer.queryMultiAdapter(objects, providing, name)
-            if r is not None:
-                return r
-        return default
-
-
-    ############################################################
-    #
-    # The following methods are provided for convenience and for
-    # backward compatability with old code:
-
-    def provideView(self, for_, name, type, maker, layer='default',
-                    providing=zope.interface.Interface):
-        # Helper function for simple view defs
-        return self.provideAdapter(type, maker, name,
-                                   contexts=[for_], layer=layer,
-                                   providing=providing)
-
-
-    def setDefaultViewName(self, for_, request_type, name, layer="default"):
-        """Default view names
-
-        A default view name is a name that an application should use
-        if a user hasn't selected one.  This should not be confused
-        with unnamed views.
-
-        The presentation service can store this by storing the name as
-        an "adapter".
-        """
-        return self.provideAdapter(request_type, name,
-                                   providing=IDefaultViewName,
-                                   contexts=[for_], layer=layer)
-
-    def queryDefaultViewName(self, object, request, default=None):
-        skin = request.getPresentationSkin() or 'default'
-        objects = object, request
-        for layer in self._skins[skin]:
-            r = layer.lookup(map(providedBy, objects), IDefaultViewName)
-            if r is not None:
-                return r
-        return default
-
-    def provideResource(self, name, request_type, factory, layer='default',
-                        providing=zope.interface.Interface):
-        # Helper function for simple view defs
-        return self.provideAdapter(request_type, factory, name, layer=layer,
-                                   providing=providing)
-
-
-def GL(presentation_service, layer_name):
-    return presentation_service.queryLayer(layer_name)
-
-
-class GlobalLayer(zope.interface.adapter.AdapterRegistry):
-
-    def __init__(self, parent, name):
-        super(GlobalLayer, self).__init__()
-        self.__parent__ = parent
-        self.__name__ = name
-
-    def __reduce__(self):
-        return GL, (self.__parent__, self.__name__)
-
-
-class SkinRegistration(object):
-    """Registration for a global skin."""
-
-    def __init__(self, skin, layers, info):
-        self.skin, self.layers, self.doc = skin, layers, info
-
-    def __repr__(self):
-        """Representation of the object in a doctest-friendly format."""
-        return '%s.%s(%r, %r, %r)' % (
-            self.__class__.__module__, self.__class__.__name__,
-            self.skin, self.layers, self.doc)
-
-
-class LayerRegistration(object):
-    """Registration for a global layer."""
-
-    def __init__(self, layer, info):
-        self.layer, self.doc = layer, info
-
-    def __repr__(self):
-        """Representation of the object in a doctest-friendly format."""
-        return '%s.%s(%r, %r)' % (
-            self.__class__.__module__, self.__class__.__name__,
-            self.layer, self.doc)
-
-
-class DefaultSkinRegistration(object):
-    """Registration for the global default skin."""
-
-    def __init__(self, skin, info):
-        self.skin, self.doc = skin, info
-
-    def __repr__(self):
-        """Representation of the object in a doctest-friendly format."""
-        return '%s.%s(%r, %r)' % (
-            self.__class__.__module__, self.__class__.__name__,
-            self.skin, self.doc)
-
-
-class PresentationRegistration(object):
-    """Registration for a single presentation component."""
-
-    def __init__(self, layer, required, provided, name, factory, info):
-        (self.layer, self.required, self.provided, self.name,
-         self.factory, self.doc
-         ) = layer, required, provided, name, factory, info
-
-    def __repr__(self):
-        """Representation of the object in a doctest-friendly format."""
-        return '%s.%s(%s, %r, %r, %r, %r, %r)' % (
-            self.__class__.__module__, self.__class__.__name__,
-            self.layer,
-            tuple([getattr(s, '__name__', None) for s in self.required]),
-            self.provided.__name__,
-            self.name, getattr(self.factory, '__name__', self.factory),
-            self.doc)
-

Modified: Zope3/trunk/src/zope/component/tests/placelesssetup.py
===================================================================
--- Zope3/trunk/src/zope/component/tests/placelesssetup.py	2004-09-17 16:16:56 UTC (rev 27606)
+++ Zope3/trunk/src/zope/component/tests/placelesssetup.py	2004-09-17 16:24:14 UTC (rev 27607)
@@ -17,7 +17,7 @@
 """
 from zope.testing.cleanup import CleanUp
 from zope.component import getGlobalServices
-from zope.component.servicenames import Adapters, Utilities, Presentation
+from zope.component.servicenames import Adapters, Utilities
 
 # A mix-in class inheriting from CleanUp that also connects the CA services
 class PlacelessSetup(CleanUp):
@@ -40,11 +40,5 @@
         from zope.component.adapter import GlobalAdapterService
         provideService(Adapters, GlobalAdapterService())
 
-        # presentation service
-        from zope.component.interfaces import IPresentationService
-        defineService(Presentation, IPresentationService)
-        from zope.component.presentation import GlobalPresentationService
-        provideService(Presentation, GlobalPresentationService())
-
     def tearDown(self):
         CleanUp.tearDown(self)

Deleted: Zope3/trunk/src/zope/component/tests/test_presentation.py
===================================================================
--- Zope3/trunk/src/zope/component/tests/test_presentation.py	2004-09-17 16:16:56 UTC (rev 27606)
+++ Zope3/trunk/src/zope/component/tests/test_presentation.py	2004-09-17 16:24:14 UTC (rev 27607)
@@ -1,284 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.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.
-#
-##############################################################################
-"""Presentation Serivce tests
-
-$Id$
-"""
-import unittest
-from doctest import DocTestSuite
-from zope.component.presentation import GlobalPresentationService
-import zope.interface
-
-class IRequest(zope.interface.Interface):
-    "Demonstration request type"
-
-class Request(object):
-    zope.interface.implements(IRequest)
-    def getPresentationSkin(self):
-        return getattr(self, 'skin', None)
-
-class IContact(zope.interface.Interface):
-    "Demonstration content type"
-
-class Contact(object):
-    zope.interface.implements(IContact)
-
-class MyView(object):
-    def __init__(self, context, request):
-        self.context, self.request = context, request
-
-
-def test_view_lookup_fails_w_wrong_skin():
-    """
-    >>> s = GlobalPresentationService()
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-
-    >>> request = Request()
-
-    >>> s.provideAdapter(IRequest, MyView, contexts=[IContact], name='foo',
-    ...                  layer='custom')
-
-    >>> c = Contact()
-
-    >>> s.queryView(c, 'foo', request)
-
-    We don't get anothing because we registered in the custom layer,
-    but looked up in the default skin which has only the default layer.
-    """
-
-class ICompany(zope.interface.Interface):
-    "Demonstration content type"
-
-class Company(object):
-    zope.interface.implements(ICompany)
-
-class ContactInCompanyView:
-    def __init__(self, contact, company, request):
-        self.contact, self.company, self.request = contact, company, request
-
-class IFamily(zope.interface.Interface):
-    "Demonstration content type"
-
-class Family(object):
-    zope.interface.implements(IFamily)
-
-class ContactInFamilyView(object):
-    def __init__(self, contact, family, request):
-        self.contact, self.family, self.request = contact, family, request
-
-def test_multi_views():
-    """A multi-view is a view on multiple objects
-
-    >>> s = GlobalPresentationService()
-    >>> request = Request()
-
-    >>> s.provideAdapter(IRequest, ContactInCompanyView,
-    ...                  contexts=[IContact, ICompany], name='foo',
-    ...                  info='test 1')
-
-    >>> bob = Contact()
-    >>> acme = Company()
-
-    >>> v = s.queryMultiView((bob, acme), request, name='foo')
-    >>> v.__class__.__name__
-    'ContactInCompanyView'
-    >>> v.contact is bob
-    True
-    >>> v.company is acme
-    True
-    >>> v.request is request
-    True
-
-    >>> s.provideAdapter(IRequest, ContactInFamilyView,
-    ...                  contexts=[IContact, IFamily], name='foo',
-    ...                  info='test 2')
-
-    >>> smith = Family()
-    >>> v = s.queryMultiView((bob, smith), request, name='foo')
-    >>> v.__class__.__name__
-    'ContactInFamilyView'
-    >>> v.contact is bob
-    True
-    >>> v.family is smith
-    True
-    >>> v.request is request
-    True
-
-    Provided adapters (views and resources) are recorded as registrations:
-
-    >>> registrations = map(str, s.registrations())
-    >>> registrations.sort()
-    >>> for r in registrations:
-    ...     print r
-    zope.component.presentation.PresentationRegistration(""" \
-       """default, ('IContact', 'ICompany', 'IRequest'), """ \
-       """'Interface', 'foo', 'ContactInCompanyView', 'test 1')
-    zope.component.presentation.PresentationRegistration(""" \
-       """default, ('IContact', 'IFamily', 'IRequest'), """ \
-       """'Interface', 'foo', 'ContactInFamilyView', 'test 2')
-
-    """
-
-def test_provideView():
-    """
-
-    The provideView is a simpler and backward-compatible interface to
-    provideAdapter.
-
-    >>> s = GlobalPresentationService()
-    >>> request = Request()
-    >>> s.provideView(IContact, 'foo', IRequest, MyView)
-
-
-    >>> c = Contact()
-    >>> v = s.queryView(c, 'foo', request)
-    >>> v.__class__.__name__
-    'MyView'
-    >>> v.request is request
-    True
-    >>> v.context is c
-    True
-
-    We can specify a layer and we can provide a view factory directly:
-
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-    >>> s.provideView(IContact, 'index.html', IRequest, MyView, layer='custom')
-
-    >>> c = Contact()
-    >>> request.skin = 'custom'
-
-    >>> v = s.queryView(c, 'foo', request)
-
-    >>> v.__class__.__name__
-    'MyView'
-    >>> v.request is request
-    True
-    >>> v.context is c
-    True
-    """
-
-
-def test_default_view_names():
-    """
-    >>> s = GlobalPresentationService()
-    >>> request = Request()
-    >>> c = Contact()
-
-    We haven't set a default view name:
-
-    >>> s.queryDefaultViewName(c, request)
-
-    Let's set a "default default":
-
-    >>> s.setDefaultViewName(None, IRequest, 'index.html')
-
-    And then we'll get it is we look something up:
-
-    >>> s.queryDefaultViewName(c, request)
-    'index.html'
-
-    Now we'll set a name for a specific interface. We'll also specify
-    a specifioc layer:
-
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-    >>> s.setDefaultViewName(IContact, IRequest, 'hello.html', layer='custom')
-
-    If we don't specify the custum skin, we'll still get the default:
-
-    >>> s.queryDefaultViewName(c, request)
-    'index.html'
-
-    But if we specify a custom skin, we'll get the custom value for a contact:
-
-    >>> request.skin = 'custom'
-    >>> s.queryDefaultViewName(c, request)
-    'hello.html'
-
-    But not for something else:
-
-    >>> s.queryDefaultViewName(42, request)
-    'index.html'
-
-    """
-
-def test_default_skin_affects_lookup():
-    """
-    >>> s = GlobalPresentationService()
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-
-    >>> request = Request()
-
-    >>> class MyResource(object):
-    ...    def __init__(self, request):
-    ...        self.request = request
-    >>> s.provideAdapter(IRequest, MyResource, name='foo', layer='custom')
-    >>> s.queryResource('foo', request)
-
-    >>> s.provideAdapter(IRequest, MyView, contexts=[IContact], name='foo',
-    ...                  layer='custom')
-
-    >>> c = Contact()
-    >>> v = s.queryView(c, 'foo', request)
-
-
-    >>> s.setDefaultSkin('custom')
-
-
-    >>> r = s.queryResource('foo', request)
-    >>> r.__class__.__name__
-    'MyResource'
-    >>> r.request is request
-    True
-
-    >>> v = s.queryView(c, 'foo', request)
-    >>> v.__class__.__name__
-    'MyView'
-    >>> v.request is request
-    True
-    >>> v.context is c
-    True
-    """
-
-def test_pickling():
-    """
-    >>> from zope.component.tests.test_service import testServiceManager
-    >>> from zope.component.interfaces import IPresentationService
-    >>> testServiceManager.defineService('Presentation', IPresentationService)
-    >>> presentation = GlobalPresentationService()
-    >>> testServiceManager.provideService('Presentation', presentation)
-    >>> import pickle
-
-    >>> s = pickle.loads(pickle.dumps(presentation))
-    >>> s is presentation
-    True
-
-    >>> layer = pickle.loads(pickle.dumps(presentation.queryLayer('default')))
-    >>> (layer is presentation.queryLayer('default')) and (layer is not None)
-    True
-
-    >>> testServiceManager._clear()
-    """
-
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite('zope.component.presentation'),
-        DocTestSuite(),
-        ))
-
-if __name__ == '__main__': unittest.main()



More information about the Zope3-Checkins mailing list