diff --git a/CHANGES.rst b/CHANGES.rst index 38ac8e5..4b76893 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ 6.0.1 (unreleased) ================== -- Nothing changed yet. +- Fix test compatibility with zope.interface 5.4. 6.0.0 (2021-01-20) diff --git a/src/zope/publisher/configure.txt b/src/zope/publisher/configure.txt index ccfc9ef..1ccadfd 100644 --- a/src/zope/publisher/configure.txt +++ b/src/zope/publisher/configure.txt @@ -10,8 +10,19 @@ adapters and security: >>> XMLConfig('configure.zcml', zope.publisher)() - >>> len(list(zope.component.getGlobalSiteManager().registeredUtilities())) - 22 +The exact count of registered utilities will vary depending on which +packages are installed because of the use of +``zcml:condition="installed ..."`` clauses in the ZCML. + + >>> try: + ... import zope.annotation + ... except ImportError: + ... expected_count = 22 + ... else: + ... expected_count = 23 + + >>> len(list(zope.component.getGlobalSiteManager().registeredUtilities())) == expected_count + True >>> len(list(zope.component.getGlobalSiteManager().registeredAdapters())) 11 diff --git a/src/zope/publisher/skinnable.py b/src/zope/publisher/skinnable.py index 02d9a8b..8c4a459 100644 --- a/src/zope/publisher/skinnable.py +++ b/src/zope/publisher/skinnable.py @@ -1,79 +1,79 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Foundation 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. -# -############################################################################## -"""Browser-specific skin implementations. - -""" -__docformat__ = 'restructuredtext' - -import zope.component -import zope.interface -import zope.interface.interfaces - -from zope.publisher import interfaces - - -@zope.interface.implementer(interfaces.ISkinChangedEvent) -class SkinChangedEvent(object): - """Skin changed event.""" - - def __init__(self, request): - self.request = request - - -def getDefaultSkin(request): - """Returns the IDefaultSkin layer for IBrowserRequest.""" - return interfaces.browser.IDefaultBrowserLayer - - -def setDefaultSkin(request): - """Sets the default skin for a given request.""" - adapters = zope.component.getSiteManager().adapters - skin = adapters.lookup((zope.interface.providedBy(request),), - interfaces.IDefaultSkin, '') - if skin is None: - # Find a named ``default`` adapter providing IDefaultSkin as fallback. - skin = adapters.lookup((zope.interface.providedBy(request),), - interfaces.IDefaultSkin, 'default') - if skin is None: - # Let's be nice and continue to work for IBrowserRequest's - # without relying on adapter registrations. - if interfaces.browser.IBrowserRequest.providedBy(request): - skin = getDefaultSkin - if skin is not None: - if not zope.interface.interfaces.IInterface.providedBy(skin): - # The default fallback skin is registered as a named adapter. - skin = skin(request) - else: - # The defaultSkin directive registers skins as interfaces and not - # as adapters. We will not try to adapt the request to an - # interface to produce an interface. - pass - if interfaces.ISkinType.providedBy(skin): - # silently ignore skins which do not provide ISkinType - zope.interface.directlyProvides(request, skin) - else: - raise TypeError("Skin interface %s doesn't provide ISkinType" % - skin) - - -def applySkin(request, skin): - """Change the presentation skin for this request.""" - # Remove all existing skin type declarations (commonly the default skin) - # based on the given skin type. - ifaces = [iface for iface in zope.interface.directlyProvidedBy(request) - if not interfaces.ISkinType.providedBy(iface)] - # Add the new skin. - ifaces.append(skin) - zope.interface.directlyProvides(request, *ifaces) - zope.event.notify(SkinChangedEvent(request)) +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Foundation 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. +# +############################################################################## +"""Browser-specific skin implementations. + +""" +__docformat__ = 'restructuredtext' + +import zope.component +import zope.interface +import zope.interface.interfaces + +from zope.publisher import interfaces + + +@zope.interface.implementer(interfaces.ISkinChangedEvent) +class SkinChangedEvent(object): + """Skin changed event.""" + + def __init__(self, request): + self.request = request + + +def getDefaultSkin(request): + """Returns the IDefaultSkin layer for IBrowserRequest.""" + return interfaces.browser.IDefaultBrowserLayer + + +def setDefaultSkin(request): + """Sets the default skin for a given request.""" + adapters = zope.component.getSiteManager().adapters + skin = adapters.lookup((zope.interface.providedBy(request),), + interfaces.IDefaultSkin, '') + if skin is None: + # Find a named ``default`` adapter providing IDefaultSkin as fallback. + skin = adapters.lookup((zope.interface.providedBy(request),), + interfaces.IDefaultSkin, 'default') + if skin is None: + # Let's be nice and continue to work for IBrowserRequest's + # without relying on adapter registrations. + if interfaces.browser.IBrowserRequest.providedBy(request): + skin = getDefaultSkin + if skin is not None: + if not zope.interface.interfaces.IInterface.providedBy(skin): + # The default fallback skin is registered as a named adapter. + skin = skin(request) + else: + # The defaultSkin directive registers skins as interfaces and not + # as adapters. We will not try to adapt the request to an + # interface to produce an interface. + pass + if interfaces.ISkinType.providedBy(skin): + # silently ignore skins which do not provide ISkinType + zope.interface.directlyProvides(request, skin) + else: + raise TypeError("Skin interface %r doesn't provide ISkinType" % + skin) + + +def applySkin(request, skin): + """Change the presentation skin for this request.""" + # Remove all existing skin type declarations (commonly the default skin) + # based on the given skin type. + ifaces = [iface for iface in zope.interface.directlyProvidedBy(request) + if not interfaces.ISkinType.providedBy(iface)] + # Add the new skin. + ifaces.append(skin) + zope.interface.directlyProvides(request, *ifaces) + zope.event.notify(SkinChangedEvent(request))