Commit 7214980c authored by Hanno Schlichting's avatar Hanno Schlichting

Use `@implementer` and `@adapter` class decorators.

parent 32e810f1
......@@ -19,6 +19,7 @@ Features Added
Restructuring
+++++++++++++
- Use `@implementer` and `@adapter` class decorators.
4.0a2 (2016-09-09)
------------------
......
......@@ -16,7 +16,7 @@
from cgi import escape
import urllib
from zope.interface import implements
from zope.interface import implementer
from AccessControl import Unauthorized
from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass
......@@ -132,11 +132,10 @@ class Tabs(Base):
InitializeClass(Tabs)
@implementer(INavigation)
class Navigation(Base):
"""Basic navigation UI support"""
implements(INavigation)
security = ClassSecurityInfo()
security.declareProtected(view_management_screens, 'manage')
......
......@@ -35,7 +35,7 @@ from zExceptions import (
Forbidden,
Redirect as RedirectException,
)
from zope.interface import implements
from zope.interface import implementer
import Folder
import misc_
......@@ -52,11 +52,10 @@ LOG = getLogger('Application')
APP_MANAGER = None
@implementer(IApplication)
class Application(ApplicationDefaultPermissions, Folder.Folder):
"""Top-level system object"""
implements(IApplication)
security = ClassSecurityInfo()
title = 'Zope'
......
......@@ -36,7 +36,7 @@ from Acquisition import aq_parent
from ExtensionClass import Base
from zExceptions import Unauthorized, BadRequest, ResourceLockedError
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer
from zope.event import notify
from zope.lifecycleevent import ObjectCopiedEvent
from zope.lifecycleevent import ObjectMovedEvent
......@@ -59,12 +59,11 @@ copy_re = re.compile('^copy([0-9]*)_of_(.*)')
_marker = []
@implementer(ICopyContainer)
class CopyContainer(Base):
"""Interface for containerish objects which allow cut/copy/paste"""
implements(ICopyContainer)
security = ClassSecurityInfo()
# The following three methods should be overridden to store sub-objects
......@@ -448,12 +447,11 @@ class CopyContainer(Base):
InitializeClass(CopyContainer)
@implementer(ICopySource)
class CopySource(Base):
"""Interface for objects which allow themselves to be copied."""
implements(ICopySource)
# declare a dummy permission for Copy or Move here that we check
# in cb_isCopyable.
security = ClassSecurityInfo()
......
......@@ -15,7 +15,7 @@ import time
from Acquisition import aq_acquire
from zExceptions import HTTPPreconditionFailed
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
......@@ -56,6 +56,7 @@ class EtagBaseInterface(Interface):
"""
@implementer(EtagBaseInterface)
class EtagSupport(object):
"""
This class is the basis for supporting Etags in Zope. It's main
......@@ -68,7 +69,6 @@ class EtagSupport(object):
can be rejected according to the type of header (If-Match,
If-None-Match).
"""
implements(EtagBaseInterface)
def http__etag(self, readonly=0):
try:
......
......@@ -26,16 +26,15 @@ from DocumentTemplate.DT_Util import InstanceDict
from DocumentTemplate.DT_Util import TemplateDict
from DocumentTemplate.security import RestrictedDTML
from ExtensionClass import Base
from zope.interface import implements
from zope.interface import implementer
from OFS.interfaces import IFindSupport
@implementer(IFindSupport)
class FindSupport(Base):
"""Find support for Zope Folders"""
implements(IFindSupport)
security = ClassSecurityInfo()
security.declareProtected(view_management_screens, 'ZopeFind')
......
......@@ -17,7 +17,7 @@ Folders are the basic container objects and are analogous to directories.
from AccessControl.class_init import InitializeClass
from App.special_dtml import DTMLFile
from zope.interface import implements
from zope.interface import implementer
from OFS import bbb
from OFS.interfaces import IFolder
......@@ -50,6 +50,7 @@ def manage_addFolder(self, id, title='',
return self.manage_main(self, REQUEST)
@implementer(IFolder)
class Folder(
ObjectManager,
PropertyManager,
......@@ -62,8 +63,6 @@ class Folder(
interface for object management. Folder objects also implement
a management interface and can have arbitrary properties.
"""
implements(IFolder)
meta_type = 'Folder'
_properties = (
......
......@@ -31,8 +31,7 @@ from Persistence import Persistent
from zExceptions import Redirect, ResourceLockedError
from zope.contenttype import guess_content_type
from zope.event import notify
from zope.interface import implementedBy
from zope.interface import implements
from zope.interface import implementer
from zope.lifecycleevent import ObjectCreatedEvent
from zope.lifecycleevent import ObjectModifiedEvent
......@@ -87,18 +86,12 @@ def manage_addFile(self, id, file='', title='', precondition='',
raise Redirect(self.absolute_url() + '/manage_main')
@implementer(IWriteLock,
HTTPRangeSupport.HTTPRangeInterface)
class File(Persistent, Implicit, PropertyManager,
RoleManager, Item_w__name__, Cacheable):
"""A File object is a content object for arbitrary files."""
implements(implementedBy(Persistent),
implementedBy(Implicit),
implementedBy(PropertyManager),
implementedBy(RoleManager),
implementedBy(Item_w__name__),
IWriteLock,
HTTPRangeSupport.HTTPRangeInterface)
meta_type = 'File'
security = ClassSecurityInfo()
......
......@@ -18,7 +18,7 @@ from AccessControl.class_init import InitializeClass
from AccessControl.owner import ownerInfo
from AccessControl.SecurityInfo import ClassSecurityInfo
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer
from OFS.interfaces import ILockItem
......@@ -50,10 +50,9 @@ def validateTimeout(timeout):
return timeout, errors
@implementer(ILockItem)
class LockItem(Persistent):
implements(ILockItem)
security = ClassSecurityInfo()
security.declarePublic('getOwner', 'getLockToken', 'getDepth',
'getTimeout', 'getTimeoutString',
......
......@@ -15,16 +15,16 @@ from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_base
from Persistence import PersistentMapping
from zope.interface import implements
from zope.interface import implementer
from OFS.EtagSupport import EtagSupport
from OFS.interfaces import ILockItem, IWriteLock
@implementer(IWriteLock)
class LockableItem(EtagSupport):
"""Implements the WriteLock interface.
"""
implements(IWriteLock)
# Protect methods using declarative security
security = ClassSecurityInfo()
......
......@@ -46,7 +46,7 @@ from Persistence import Persistent
from zExceptions import BadRequest, ResourceLockedError
from zope.container.contained import notifyContainerModified
from zope.event import notify
from zope.interface import implements
from zope.interface import implementer
from zope.interface.interfaces import ComponentLookupError
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent
......@@ -142,6 +142,7 @@ class BreakoutException(Exception):
_marker = []
@implementer(IObjectManager)
class ObjectManager(CopyContainer,
Navigation,
Tabs,
......@@ -156,8 +157,6 @@ class ObjectManager(CopyContainer,
This class provides core behavior for collections of heterogeneous objects.
"""
implements(IObjectManager)
security = ClassSecurityInfo()
security.declareObjectProtected(access_contents_information)
security.setPermissionDefault(access_contents_information,
......
......@@ -21,7 +21,7 @@ from AccessControl.Permissions import manage_properties
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_base
from DocumentTemplate.sequence import sort
from zope.interface import implements
from zope.interface import implementer
from zope.container.contained import notifyContainerModified
from OFS.interfaces import IOrderedContainer as IOrderedContainer
......@@ -31,6 +31,7 @@ if sys.version_info >= (3, ):
basestring = str
@implementer(IOrderedContainer)
class OrderSupport(object):
""" Ordered container mixin class.
......@@ -40,8 +41,6 @@ class OrderSupport(object):
particular helpful, if the order does not depend on object attributes, but
is totally user-specific.
"""
implements(IOrderedContainer)
security = ClassSecurityInfo()
has_order_support = 1
......
......@@ -14,7 +14,7 @@
"""
from App.special_dtml import DTMLFile
from zope.interface import implements
from zope.interface import implementer
from OFS.Folder import Folder
from OFS.interfaces import IOrderedFolder
......@@ -35,11 +35,11 @@ def manage_addOrderedFolder(self, id, title='', createPublic=0, createUserF=0,
return self.manage_main(self, REQUEST)
@implementer(IOrderedFolder)
class OrderedFolder(OrderSupport, Folder):
""" Extends the default Folder by order support.
"""
implements(IOrderedFolder)
meta_type = 'Folder (Ordered)'
manage_options = (
......
......@@ -22,7 +22,7 @@ from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_base
from ExtensionClass import Base
from zExceptions import BadRequest
from zope.interface import implements
from zope.interface import implementer
from ZPublisher.Converters import type_converters
from OFS.interfaces import IPropertyManager
......@@ -30,6 +30,7 @@ from OFS.PropertySheets import DefaultPropertySheets
from OFS.PropertySheets import vps
@implementer(IPropertyManager)
class PropertyManager(Base):
"""
The PropertyManager mixin class provides an object with
......@@ -77,8 +78,6 @@ class PropertyManager(Base):
are assumed to have the mode 'wd' (writeable and deleteable).
"""
implements(IPropertyManager)
security = ClassSecurityInfo()
security.declareObjectProtected(access_contents_information)
security.setPermissionDefault(access_contents_information,
......
......@@ -50,7 +50,7 @@ from ExtensionClass import Base
from Persistence import Persistent
from zExceptions import Redirect
from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements
from zope.interface import implementer
from OFS import bbb
from OFS.interfaces import IItem
......@@ -70,6 +70,7 @@ else:
logger = logging.getLogger()
@implementer(IItem)
class Item(Base,
Resource,
LockableItem,
......@@ -79,8 +80,6 @@ class Item(Base,
Owned):
"""A common base class for simple, non-container objects."""
implements(IItem)
security = ClassSecurityInfo()
isPrincipiaFolderish = 0
......@@ -386,11 +385,10 @@ class Item(Base,
InitializeClass(Item)
@implementer(IItemWithName)
class Item_w__name__(Item):
"""Mixin class to support common name/id functions"""
implements(IItemWithName)
def getId(self):
"""Return the id of the object as a string.
"""
......@@ -433,6 +431,7 @@ def pretty_tb(t, v, tb, as_html=1):
return tb
@implementer(ISimpleItem)
class SimpleItem(Item,
Persistent,
Implicit,
......@@ -441,8 +440,6 @@ class SimpleItem(Item,
"""Mix-in class combining the most common set of basic mix-ins
"""
implements(ISimpleItem)
security = ClassSecurityInfo()
security.setPermissionDefault(View, ('Manager',))
......
......@@ -32,7 +32,7 @@ from zExceptions import NotFound
from ZPublisher.interfaces import UseTraversalDefault
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
from zope.component import queryMultiAdapter
from zope.location.interfaces import LocationError
......@@ -42,8 +42,8 @@ from zope.traversing.namespace import nsParse
_marker = object()
@implementer(ITraversable)
class Traversable:
implements(ITraversable)
security = ClassSecurityInfo()
......
......@@ -17,12 +17,13 @@ from Acquisition import aq_parent
from OFS.interfaces import ITraversable
from zope.component import getMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.traversing.browser.absoluteurl import _insufficientContext, _safe
from zope.publisher.browser import BrowserView
@implementer(IAbsoluteURL)
class AbsoluteURL(BrowserView):
"""An absolute_url adapter for generic objects in Zope 2 that
aren't OFS.Traversable (e.g. views, resources, etc.).
......@@ -31,7 +32,6 @@ class AbsoluteURL(BrowserView):
zope.traversing.browser, but the Zope 2 request doesn't support
all the methods that it uses yet.
"""
implements(IAbsoluteURL)
def __unicode__(self):
return urllib.unquote(self.__str__()).decode('utf-8')
......@@ -87,10 +87,10 @@ class AbsoluteURL(BrowserView):
return base
@implementer(IAbsoluteURL)
class OFSTraversableAbsoluteURL(BrowserView):
"""An absolute_url adapter for OFS.Traversable subclasses
"""
implements(IAbsoluteURL)
def __unicode__(self):
return urllib.unquote(self.__str__()).decode('utf-8')
......
......@@ -15,15 +15,15 @@
OFS event definitions.
"""
from zope.interface import implements
from zope.interface import implementer
from zope.interface.interfaces import ObjectEvent
import OFS.interfaces
@implementer(OFS.interfaces.IObjectWillBeMovedEvent)
class ObjectWillBeMovedEvent(ObjectEvent):
"""An object will be moved."""
implements(OFS.interfaces.IObjectWillBeMovedEvent)
def __init__(self, object, oldParent, oldName, newParent, newName):
ObjectEvent.__init__(self, object)
......@@ -33,27 +33,27 @@ class ObjectWillBeMovedEvent(ObjectEvent):
self.newName = newName
@implementer(OFS.interfaces.IObjectWillBeAddedEvent)
class ObjectWillBeAddedEvent(ObjectWillBeMovedEvent):
"""An object will be added to a container."""
implements(OFS.interfaces.IObjectWillBeAddedEvent)
def __init__(self, object, newParent=None, newName=None):
ObjectWillBeMovedEvent.__init__(self, object, None, None,
newParent, newName)
@implementer(OFS.interfaces.IObjectWillBeRemovedEvent)
class ObjectWillBeRemovedEvent(ObjectWillBeMovedEvent):
"""An object will be removed from a container."""
implements(OFS.interfaces.IObjectWillBeRemovedEvent)
def __init__(self, object, oldParent=None, oldName=None):
ObjectWillBeMovedEvent.__init__(self, object, oldParent, oldName,
None, None)
@implementer(OFS.interfaces.IObjectClonedEvent)
class ObjectClonedEvent(ObjectEvent):
"""An object has been cloned into a container."""
implements(OFS.interfaces.IObjectClonedEvent)
......@@ -117,10 +117,10 @@ product's ``interfaces.py``::
Then the class CoolDocument is marked with this interface::
from zope.interface import implements
from zope.interface import implementer
from Products.CoolProduct.interfaces import ICoolDocument
@implementer(ICoolDocument)
class CoolDocument(...):
implements(ICoolDocument)
...
Finally we must link the event and the interface to the subscriber using
......
......@@ -69,11 +69,11 @@ def maybeWarnDeprecated(ob, method_name):
(class_.__module__, class_.__name__, method_name))
@zope.interface.implementer(zope.location.interfaces.ISublocations)
@zope.component.adapter(OFS.interfaces.IObjectManager)
class ObjectManagerSublocations(object):
"""Get the sublocations for an ObjectManager.
"""
zope.component.adapts(OFS.interfaces.IObjectManager)
zope.interface.implements(zope.location.interfaces.ISublocations)
def __init__(self, container):
self.container = container
......
......@@ -38,8 +38,8 @@ class ITestItem(interface.Interface):
pass
@interface.implementer(ITestItem)
class TestItem(SimpleItem):
interface.implements(ITestItem)
def __init__(self, id):
self.id = id
......@@ -49,8 +49,8 @@ class ITestFolder(interface.Interface):
pass
@interface.implementer(ITestFolder)
class TestFolder(Folder):
interface.implements(ITestFolder)
def __init__(self, id):
self.id = id
......
import unittest
from zope.interface import implements
from zope.interface import implementer
from OFS.interfaces import IWriteLock
@implementer(IWriteLock)
class LockableResource(object):
implements(IWriteLock)
def __init__(self, locked):
self.locked = locked
......
......@@ -11,7 +11,7 @@ from App.config import getConfiguration
from logging import getLogger
from zExceptions import BadRequest
from zope.component.testing import PlacelessSetup
from zope.interface import implements
from zope.interface import implementer
from Zope2.App import zcml
from OFS.interfaces import IItem
......@@ -68,9 +68,9 @@ class ItemForDeletion(SimpleItem):
pass
@implementer(IItem)
class ObjectManagerWithIItem(ObjectManager):
"""The event subscribers work on IItem."""
implements(IItem)
class ObjectManagerTests(PlacelessSetup, unittest.TestCase):
......
......@@ -45,19 +45,20 @@ class TestRegisterClass(unittest.TestCase):
class Dummy(object):
pass
else:
from zope.interface import implements
from zope.interface import implementer
@implementer(ifaces)
class Dummy(object):
implements(ifaces)
pass
return Dummy
def _registerPermission(self, name, title=None):
from zope.component import provideUtility
from zope.interface import implements
from zope.interface import implementer
from zope.security.interfaces import IPermission
@implementer(IPermission)
class Perm:
implements(IPermission)
def __init__(self, title):
self. title = title
......
......@@ -18,7 +18,7 @@ from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
......@@ -26,8 +26,8 @@ class ISimpleContent(Interface):
pass
@implementer(ISimpleContent)
class SimpleContent(SimpleItem):
implements(ISimpleContent)
meta_type = 'SimpleContent'
security = ClassSecurityInfo()
......
......@@ -37,7 +37,7 @@ from zope.container.interfaces import IContainerNamesContainer
from zope.container.interfaces import INameChooser
from zope.event import notify
from zope.exceptions.interfaces import UserError
from zope.interface import implements
from zope.interface import implementer
from zope.lifecycleevent import ObjectCreatedEvent
from zope.publisher.interfaces import IPublishTraverse
from zope.traversing.browser.absoluteurl import absoluteURL
......@@ -47,8 +47,8 @@ from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@implementer(IAdding, IPublishTraverse)
class Adding(BrowserView):
implements(IAdding, IPublishTraverse)
def add(self, content):
"""See zope.browser.interfaces.IAdding
......@@ -199,12 +199,11 @@ class ContentAdding(Adding, SimpleItem):
menu_id = "add_content"
@implementer(INameChooser)
class ObjectManagerNameChooser:
"""A name chooser for a Zope object manager.
"""
implements(INameChooser)
def __init__(self, context):
self.context = context
......
......@@ -20,7 +20,7 @@ import urllib
import zope.browserresource.directory
import zope.browserresource.file
from zope.browserresource.file import File
from zope.interface import implements
from zope.interface import implementer
from zope.traversing.browser import absoluteURL
from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IBrowserPublisher
......@@ -54,8 +54,8 @@ class Resource(object):
return "%s/%s" % (url, name)
@implementer(IBrowserPublisher)
class PageTemplateResource(Resource, BrowserView):
implements(IBrowserPublisher)
def browserDefault(self, request):
return self.render, ()
......
......@@ -14,7 +14,7 @@
"""Test fixtures
"""
from zope.interface import Interface, implements
from zope.interface import Interface, implementer
from Products.Five import BrowserView
......@@ -23,9 +23,9 @@ class IOne(Interface):
"""
@implementer(IOne)
class One(object):
'A class'
implements(IOne)
class ViewOne(BrowserView):
......
......@@ -28,11 +28,13 @@ So let's create a simple content provider:
>>> import zope.component
>>> from zope.publisher.interfaces import browser
>>> class MessageBox(object):
... zope.interface.implements(interfaces.IContentProvider)
... zope.component.adapts(zope.interface.Interface,
... browser.IDefaultBrowserLayer,
... zope.interface.Interface)
>>> @zope.interface.implementer(interfaces.IContentProvider)
... @zope.component.adapter(
... zope.interface.Interface,
... browser.IDefaultBrowserLayer,
... zope.interface.Interface
... )
... class MessageBox(object):
... message = u'My Message'
...
... def __init__(self, context, request, view):
......@@ -121,8 +123,9 @@ provider implement an interface that specifies the attributes and provides
Now the message box can receive its text from the TAL environment:
>>> class DynamicMessageBox(MessageBox):
... zope.interface.implements(IMessageText)
>>> @zope.interface.implementer(IMessageText)
... class DynamicMessageBox(MessageBox):
... pass
>>> zope.component.provideAdapter(
... DynamicMessageBox, provides=interfaces.IContentProvider,
......@@ -159,8 +162,8 @@ Finally, a content provider can also implement several ``ITALNamespaceData``:
We'll change our message box content provider implementation a bit, so the new
information is used:
>>> class BetterDynamicMessageBox(DynamicMessageBox):
... zope.interface.implements(IMessageType)
>>> @zope.interface.implementer(IMessageType)
... class BetterDynamicMessageBox(DynamicMessageBox):
... type = None
...
... def render(self):
......@@ -196,10 +199,11 @@ Now we test a provider using a PageTemplateFile to render itself:
>>> open(dynTemplate, 'w').write(
... 'A simple template: <tal:simple replace="python:view.my_property" />')
>>> from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
>>> class TemplateProvider(object):
... zope.component.adapts(zope.interface.Interface,
... browser.IDefaultBrowserLayer,
... zope.interface.Interface)
>>> @zope.component.adapter(
... zope.interface.Interface,
... browser.IDefaultBrowserLayer,
... zope.interface.Interface)
... class TemplateProvider(object):
...
... def __init__(self, context, request, view):
... self.__parent__ = view
......
......@@ -27,10 +27,11 @@ def test_view_with_unwrapped_context():
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> from Products.Five.tests.testing import simplecontent as sc
>>> from zope.interface import Interface
>>> from zope.interface import implements
>>> from zope.interface import implementer
>>> from zope.component import queryMultiAdapter
>>> class Unwrapped:
... implements(sc.ISimpleContent)
>>> @implementer(sc.ISimpleContent)
... class Unwrapped:
... pass
>>> unwrapped = Unwrapped()
Simple views should work fine without having their contexts wrapped:
......
......@@ -22,7 +22,7 @@ def test_recursion():
This test makes sure that recursion is avoided for view lookup.
First, we need to set up a stub interface...
>>> from zope.interface import Interface, implements
>>> from zope.interface import Interface, implementer
>>> class IRecurse(Interface):
... pass
...
......@@ -30,8 +30,8 @@ def test_recursion():
and a class that is callable and has a view method:
>>> from OFS.Traversable import Traversable
>>> class Recurse(Traversable):
... implements(IRecurse)
>>> @implementer(IRecurse)
... class Recurse(Traversable):
... def view(self):
... return self()
... def __call__(self):
......
......@@ -44,9 +44,8 @@ a class, but contains no implementation::
A concrete class somewhere can now claim that it implements the
interface (i.e. its instance will provide the interface)::
@implementer(IElephant)
class PinkElephant:
# this says all instances of this class provide IElephant
implements(IElephant)
def getAngerLevel(self):
return 0 # this elephant is peaceful
......@@ -100,13 +99,13 @@ to subclass it from ``zope.interface.Interface``. Here is an example::
"""
Now to make some class declare that it implements this interface, you
need to use the ``implements()`` function in the class::
need to use the ``implementer()`` decorator on the class::
from zope.interface import implements
from zope.interface import implementer
from interfaces import IMyInterface
class MyClass:
implements(IMyInterface)
@implementer(IMyInterface)
class MyClass(object):
def someMethod(self):
return "I am alive! Alive!"
......@@ -126,11 +125,11 @@ requirement to make a class that is an adapter is very simple; you
only need to take a context object as the constructor. The context
object is the object being adapted. An example::
from zope.interface import implements
from zope.interface import implementer
from interfaces import INewInterface
@implementer(INewInterface)
class MyAdapter:
implements(INewInterface)
def __init__(self, context):
self.context = context
......@@ -162,7 +161,7 @@ can now be adapted to ``INewInterface``, like this::
object = MyClass()
adapted = INewInterface(object)
print adapted.anotherMethod()
print(adapted.anotherMethod())
Views
-----
......@@ -177,11 +176,12 @@ Zope objects, as long as two things are the case:
* The object (typically its class) is made traversable. This allows Zope
views, resources and other things to be attached to a Zope object.
Typically you give your classes an interface using the ``implements``
directive in the class body::
Typically you give your classes an interface using the ``implementer``
decorator on the class::
class MyClass:
implements(ISomeInterface)
@implementer(ISomeInterface)
class MyClass(object):
pass
For existing objects that you cannot modify this is not
possible. Instead, we provide a ZCML directive to accomplish this. As
......
......@@ -19,8 +19,8 @@ import zope.component
from Products.Five.browser import BrowserView
@zope.interface.implementer(zope.interface.common.mapping.IItemMapping)
class Macros(object):
zope.interface.implements(zope.interface.common.mapping.IItemMapping)
macro_pages = ()
aliases = {
......
......@@ -14,8 +14,8 @@
"""Adapter test fixtures
"""
from zope.interface import implements, Interface
from zope.component import adapts
from zope.component import adapter
from zope.interface import implementer, Interface
class IAdaptable(Interface):
......@@ -46,16 +46,16 @@ class IDestination(Interface):
"""Do something"""
@implementer(IAdaptable)
class Adaptable(object):
implements(IAdaptable)
def method(self):
return "The method"
@implementer(IAdapted)
@adapter(IAdaptable)
class Adapter(object):
implements(IAdapted)
adapts(IAdaptable)
def __init__(self, context):
self.context = context
......@@ -64,12 +64,13 @@ class Adapter(object):
return "Adapted: %s" % self.context.method()
@implementer(IOrigin)
class Origin(object):
implements(IOrigin)
pass
@implementer(IDestination)
class OriginalAdapter(object):
implements(IDestination)
def __init__(self, context):
self.context = context
......@@ -78,8 +79,8 @@ class OriginalAdapter(object):
return "Original"
@implementer(IDestination)
class OverrideAdapter(object):
implements(IDestination)
def __init__(self, context):
self.context = context
......
......@@ -14,13 +14,13 @@
"""Size adapters for testing
"""
from zope.interface import implements
from zope.interface import implementer
from zope.size.interfaces import ISized
@implementer(ISized)
class SimpleContentSize(object):
"""Size for ``SimpleContent`` objects."""
implements(ISized)
def __init__(self, context):
self.context = context
......@@ -32,9 +32,9 @@ class SimpleContentSize(object):
return "What is the meaning of life?"
@implementer(ISized)
class FancyContentSize(object):
"""Size for ``SimpleContent`` objects."""
implements(ISized)
def __init__(self, context):
self.context = context
......
......@@ -19,7 +19,7 @@ from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import Explicit
from OFS.SimpleItem import SimpleItem
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
......@@ -43,13 +43,13 @@ class FancyAttribute(Explicit):
InitializeClass(FancyAttribute)
@implementer(IFancyContent)
class FancyContent(SimpleItem):
"""A class that already comes with its own __bobo_traverse__ handler.
Quite fancy indeed.
It also comes with its own get_size method.
"""
implements(IFancyContent)
meta_type = "Fancy Content"
security = ClassSecurityInfo()
......@@ -69,14 +69,13 @@ class FancyContent(SimpleItem):
InitializeClass(FancyContent)
@implementer(IFancyContent)
class NonTraversableFancyContent(SimpleItem):
"""A class that already comes with its own __bobo_traverse__ handler.
Quite fancy indeed.
It also comes with its own get_size method.
"""
# A copy of the above class used to demonstrate some baseline behavior.
implements(IFancyContent)
meta_type = "Fancy Content"
security = ClassSecurityInfo()
......
......@@ -16,7 +16,7 @@
from OFS.Folder import Folder
from OFS.interfaces import IFolder
from zope.interface import implements
from zope.interface import implementer
class NoVerifyPasteFolder(Folder):
......@@ -34,10 +34,10 @@ def manage_addNoVerifyPasteFolder(container, id, title=''):
folder.title = title
@implementer(IFolder)
class FiveTraversableFolder(Folder):
"""Folder that is five-traversable
"""
implements(IFolder)
def manage_addFiveTraversableFolder(container, id, title=''):
......
......@@ -18,7 +18,7 @@ from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
......@@ -34,8 +34,8 @@ class IIndexSimpleContent(ISimpleContent):
pass
@implementer(ISimpleContent)
class SimpleContent(SimpleItem):
implements(ISimpleContent)
meta_type = 'Five SimpleContent'
security = ClassSecurityInfo()
......@@ -57,9 +57,9 @@ class SimpleContent(SimpleItem):
InitializeClass(SimpleContent)
@implementer(ICallableSimpleContent)
class CallableSimpleContent(SimpleItem):
"""A Viewable piece of content"""
implements(ICallableSimpleContent)
meta_type = "Five CallableSimpleContent"
......@@ -70,9 +70,9 @@ class CallableSimpleContent(SimpleItem):
InitializeClass(CallableSimpleContent)
@implementer(IIndexSimpleContent)
class IndexSimpleContent(SimpleItem):
"""A Viewable piece of content"""
implements(IIndexSimpleContent)
meta_type = 'Five IndexSimpleContent'
......
......@@ -18,7 +18,7 @@ Allows for arbitrary application of marker interfaces to objects.
from sets import Set
from zope.interface import implements, implementedBy, providedBy
from zope.interface import implementer, implementedBy, providedBy
from zope.interface import directlyProvides, directlyProvidedBy
from zope.interface.interfaces import IInterface
from zope.component.interface import getInterface, interfaceToName
......@@ -46,10 +46,9 @@ mark = interfaceStringCheck(mark)
erase = interfaceStringCheck(erase)
@implementer(IMarkerInterfaces)
class MarkerInterfacesAdapter(object):
implements(IMarkerInterfaces)
mark = staticmethod(mark)
erase = staticmethod(erase)
......
......@@ -64,8 +64,9 @@ Now we have to instantiate it in the context of an actual zope object:
>>> import zope.interface
>>> from OFS import SimpleItem, Folder
>>> class Content(SimpleItem.SimpleItem):
... zope.interface.implements(zope.interface.Interface)
>>> @zope.interface.implementer(zope.interface.Interface)
... class Content(SimpleItem.SimpleItem):
... pass
>>> obj_id = self.folder._setObject('content1', Content())
>>> content = self.folder[obj_id]
......@@ -89,8 +90,8 @@ But now we register some viewlets for the manager
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.browser.interfaces import IBrowserView
>>> class WeatherBox(object):
... zope.interface.implements(interfaces.IViewlet)
>>> @zope.interface.implementer(interfaces.IViewlet)
... class WeatherBox(object):
...
... def __init__(self, context, request, view, manager):
... self.__parent__ = view
......@@ -108,8 +109,8 @@ But now we register some viewlets for the manager
... IBrowserView, ILeftColumn),
... interfaces.IViewlet, name='weather')
>>> class SportBox(object):
... zope.interface.implements(interfaces.IViewlet)
>>> @zope.interface.implementer(interfaces.IViewlet)
... class SportBox(object):
...
... def __init__(self, context, request, view, manager):
... self.__parent__ = view
......@@ -426,8 +427,8 @@ generic contents view for files. The step is to create a file component:
>>> class IFile(zope.interface.Interface):
... data = zope.interface.Attribute('Data of file.')
>>> class File(SimpleItem.SimpleItem):
... zope.interface.implements(IFile)
>>> @zope.interface.implementer(IFile)
... class File(SimpleItem.SimpleItem):
... def __init__(self, data=''):
... self.__name__ = ''
... self.data = data
......@@ -436,9 +437,9 @@ Since we want to also provide the size of a file, here a simple implementation
of the ``ISized`` interface:
>>> from zope import size
>>> class FileSized(object):
... zope.interface.implements(size.interfaces.ISized)
... zope.component.adapts(IFile)
>>> @zope.interface.implementer(size.interfaces.ISized)
... @zope.component.adapter(IFile)
... class FileSized(object):
...
... def __init__(self, file):
... self.file = file
......@@ -497,8 +498,8 @@ different item:
>>> shownColumns = []
>>> class ContentsViewletManager(object):
... zope.interface.implements(interfaces.IViewletManager)
>>> @zope.interface.implementer(interfaces.IViewletManager)
... class ContentsViewletManager(object):
... index = None
...
... def __init__(self, context, request, view):
......@@ -761,16 +762,16 @@ sorting using a simple utility:
... def sort(values):
... """Sort the values."""
>>> class SortByName(object):
... zope.interface.implements(ISorter)
>>> @zope.interface.implementer(ISorter)
... class SortByName(object):
...
... def sort(self, values):
... return sorted(values, key=attrgetter('__name__'))
>>> zope.component.provideUtility(SortByName(), name='name')
>>> class SortBySize(object):
... zope.interface.implements(ISorter)
>>> @zope.interface.implementer(ISorter)
... class SortBySize(object):
...
... def sort(self, values):
... def _key(value):
......@@ -785,8 +786,8 @@ viewlet manager much simpler:
>>> sortByColumn = ''
>>> class SortedContentsViewletManager(manager.ViewletManagerBase):
... zope.interface.implements(interfaces.IViewletManager)
>>> @zope.interface.implementer(interfaces.IViewletManager)
... class SortedContentsViewletManager(manager.ViewletManagerBase):
... index = None
...
... def __init__(self, context, request, view):
......
......@@ -17,13 +17,14 @@
import unittest
from Testing.ZopeTestCase import FunctionalDocFileSuite
from zope.interface import Interface
from zope.interface import implements
from zope.interface import implementer
from zope.viewlet import interfaces
from OFS.SimpleItem import SimpleItem
@implementer(Interface)
class Content(SimpleItem):
implements(Interface)
pass
class UnitTestSecurityPolicy:
......
......@@ -21,7 +21,7 @@ import sys
from zope.component import queryUtility
from zope.i18n import translate
from zope.interface import implements
from zope.interface import implementer
from zope.pagetemplate.engine import ZopeEngine as Z3Engine
from zope.proxy import removeAllProxies
from zope.tales.expressions import DeferExpr
......@@ -353,12 +353,10 @@ class ZopeIterator(Iterator):
return super(ZopeIterator, self).next()
@implementer(ITraversable)
class PathIterator(ZopeIterator):
"""A TALES Iterator with the ability to use first() and last() on
subpaths of elements."""
# we want to control our own traversal so that we can deal with
# 'first' and 'last' when they appear in path expressions
implements(ITraversable)
def traverse(self, name, furtherPath):
if name in ('first', 'last'):
......
import re
import logging
from zope.interface import implements
from zope.interface import classProvides
from zope.interface import implementer
from zope.interface import provider
from zope.pagetemplate.interfaces import IPageTemplateEngine
from zope.pagetemplate.interfaces import IPageTemplateProgram
......@@ -37,9 +37,9 @@ re_match_pi = re.compile(r'<\?python([^\w].*?)\?>', re.DOTALL)
logger = logging.getLogger('Products.PageTemplates')
@implementer(IPageTemplateProgram)
@provider(IPageTemplateEngine)
class Program(object):
implements(IPageTemplateProgram)
classProvides(IPageTemplateEngine)
# Zope 2 Page Template expressions
secure_expression_types = {
......
......@@ -17,7 +17,7 @@ import sys
from Acquisition import aq_get
from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
from zope.interface import implements
from zope.interface import implementer
from zope.i18n.interfaces import IUserPreferredCharsets
if sys.version_info >= (3, ):
......@@ -26,14 +26,13 @@ if sys.version_info >= (3, ):
default_encoding = sys.getdefaultencoding()
@implementer(IUnicodeEncodingConflictResolver)
class DefaultUnicodeEncodingConflictResolver(object):
""" This resolver implements the old-style behavior and will
raise an exception in case of the string 'text' can't be converted
properly to unicode.
"""
implements(IUnicodeEncodingConflictResolver)
def resolve(self, context, text, expression):
return unicode(text)
......@@ -41,14 +40,13 @@ DefaultUnicodeEncodingConflictResolver = \
DefaultUnicodeEncodingConflictResolver()
@implementer(IUnicodeEncodingConflictResolver)
class Z2UnicodeEncodingConflictResolver(object):
""" This resolver tries to lookup the encoding from the
'management_page_charset' property and defaults to
sys.getdefaultencoding().
"""
implements(IUnicodeEncodingConflictResolver)
def __init__(self, mode='strict'):
self.mode = mode
......@@ -66,13 +64,12 @@ class Z2UnicodeEncodingConflictResolver(object):
return unicode(text, 'iso-8859-15', self.mode)
@implementer(IUnicodeEncodingConflictResolver)
class PreferredCharsetResolver(object):
""" A resolver that tries use the encoding information
from the HTTP_ACCEPT_CHARSET header.
"""
implements(IUnicodeEncodingConflictResolver)
def resolve(self, context, text, expression):
request = aq_get(context, 'REQUEST', None)
......
......@@ -29,7 +29,7 @@ import base
import interfaces
import utils
from zope.interface import implements
from zope.interface import implementer
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
......@@ -41,12 +41,11 @@ from ZopeTestCase import user_password
portal_name = 'portal'
@implementer(interfaces.IPortalTestCase,
interfaces.IPortalSecurity)
class PortalTestCase(base.TestCase):
'''Base test case for testing CMF-style portals'''
implements(interfaces.IPortalTestCase,
interfaces.IPortalSecurity)
_configure_portal = 1
def setUp(self):
......
......@@ -22,7 +22,7 @@ The default user is logged in and has the 'Access contents information'
and 'View' permissions given to his role.
"""
from zope.interface import implements
from zope.interface import implementer
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
......@@ -44,11 +44,10 @@ user_role = 'test_role_1_'
standard_permissions = [access_contents_information, view]
@implementer(interfaces.IZopeSecurity)
class ZopeTestCase(base.TestCase):
'''Base test case for Zope testing'''
implements(interfaces.IZopeSecurity)
_setup_fixture = 1
def _setup(self):
......
......@@ -16,7 +16,7 @@
import unittest
import transaction
from zope.interface import implements
from zope.interface import implementer
from AccessControl.SecurityManagement import noSecurityManager
from Testing.makerequest import makerequest
......@@ -39,12 +39,11 @@ def close(app):
connections.close(app)
@implementer(interfaces.IZopeTestCase)
class TestCase(unittest.TestCase, object):
'''Base test case for Zope testing
'''
implements(interfaces.IZopeTestCase)
layer = layer.ZopeLite
def afterSetUp(self):
......
......@@ -20,7 +20,7 @@ from functools import partial
import sys
import transaction
from zope.interface import implements
from zope.interface import implementer
from Testing.ZopeTestCase import interfaces
from Testing.ZopeTestCase import sandbox
......@@ -46,6 +46,7 @@ def savestate(func):
return wrapped_func
@implementer(interfaces.IFunctional)
class Functional(sandbox.Sandboxed):
'''Derive from this class and an xTestCase to get functional
testing support::
......@@ -54,8 +55,6 @@ class Functional(sandbox.Sandboxed):
...
'''
implements(interfaces.IFunctional)
@savestate
def publish(self, path, basic=None, env=None, extra=None,
request_method='GET', stdin=None, handle_errors=True):
......
......@@ -13,8 +13,8 @@
"""Placeless setup tests
"""
from zope.component import adapts
from zope.interface import implements, Interface
from zope.component import adapter
from zope.interface import implementer, Interface
from Testing import ZopeTestCase
......@@ -48,16 +48,16 @@ class IAdapted(Interface):
"""
@implementer(IAdaptable)
class Adaptable:
implements(IAdaptable)
def method(self):
return "The method"
@implementer(IAdapted)
@adapter(IAdaptable)
class Adapter:
implements(IAdapted)
adapts(IAdaptable)
def __init__(self, context):
self.context = context
......
......@@ -39,9 +39,8 @@ if sys.version_info >= (3, ):
basestring = str
class HTTPHeaderOutput:
class HTTPHeaderOutput(object):
# zope.interface.implements(zope.server.interfaces.IHeaderOutput)
status = '200'
reason = 'OK'
......@@ -214,7 +213,7 @@ def http(request_string, handle_errors=True):
response, outstream, path, header_output, wsgi_result, wsgi_headers)
class ZopeSuiteFactory:
class ZopeSuiteFactory(object):
def __init__(self, *args, **kw):
self._args = args
......
......@@ -25,7 +25,7 @@ from zExceptions import Forbidden
from zExceptions import NotFound
from zope.component import queryMultiAdapter
from zope.event import notify
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
from zope.location.interfaces import LocationError
from zope.publisher.defaultview import queryDefaultViewName
......@@ -70,10 +70,9 @@ class RequestContainer(Base):
return type_converters.keys()
@implementer(IBrowserPublisher)
class DefaultPublishTraverse(object):
implements(IBrowserPublisher)
def __init__(self, context, request):
self.context = context
self.request = request
......
......@@ -40,7 +40,7 @@ from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.locales import locales, LoadLocaleError
from zope.interface import directlyProvidedBy
from zope.interface import directlyProvides
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.base import DebugFlags
from zope.publisher.interfaces.browser import IBrowserRequest
......@@ -119,6 +119,7 @@ class NestedLoopExit(Exception):
pass
@implementer(IBrowserRequest)
class HTTPRequest(BaseRequest):
""" Model HTTP request data.
......@@ -171,11 +172,6 @@ class HTTPRequest(BaseRequest):
other variables, form data, and then cookies.
"""
# The claim to implement IBrowserRequest has been made during the Zope3
# integration project called Five but hasn't been completed in full.
implements(IBrowserRequest)
_hacked_path = None
args = ()
_file = None
......
import io
from zope.interface import Interface
from zope.interface import implements
from zope.interface import implementer
class IUnboundStreamIterator(Interface):
......@@ -38,14 +38,13 @@ class IStreamIterator(IUnboundStreamIterator):
"""
@implementer(IStreamIterator)
class filestream_iterator(io.FileIO):
"""
A FileIO subclass which implements an iterator that returns a
fixed-sized sequence of bytes.
"""
implements(IStreamIterator)
def __init__(self, name, mode='rb', bufsize=-1, streamsize=1 << 16):
super(filestream_iterator, self).__init__(name, mode)
self.streamsize = streamsize
......
......@@ -7,7 +7,7 @@ Subscriptions can be used for all kinds of request supervision,
e.g. request and error rate determination, writing high resolution logfiles
for detailed time related analysis, inline request monitoring.
'''
from zope.interface import implements
from zope.interface import implementer
from ZPublisher.interfaces import (
IPubStart, IPubSuccess, IPubFailure,
......@@ -23,46 +23,46 @@ class _Base(object):
self.request = request
@implementer(IPubStart)
class PubStart(_Base):
'''notified at the beginning of 'ZPublisher.Publish.publish'.'''
implements(IPubStart)
@implementer(IPubSuccess)
class PubSuccess(_Base):
'''notified at successful request end.'''
implements(IPubSuccess)
@implementer(IPubFailure)
class PubFailure(object):
'''notified at failed request end.'''
implements(IPubFailure)
def __init__(self, request, exc_info, retry):
self.request, self.exc_info, self.retry = request, exc_info, retry
@implementer(IPubAfterTraversal)
class PubAfterTraversal(_Base):
"""notified after traversal and an (optional) authentication."""
implements(IPubAfterTraversal)
@implementer(IPubBeforeCommit)
class PubBeforeCommit(_Base):
"""notified immediately before the commit."""
implements(IPubBeforeCommit)
@implementer(IPubBeforeAbort)
class PubBeforeAbort(_Base):
"""notified immediately before an abort."""
implements(IPubBeforeAbort)
def __init__(self, request, exc_info, retry):
self.request, self.exc_info, self.retry = request, exc_info, retry
@implementer(IPubBeforeStreaming)
class PubBeforeStreaming(object):
"""Notified immediately before streaming via response.write() commences
"""
implements(IPubBeforeStreaming)
def __init__(self, response):
self.response = response
import unittest
from zExceptions import NotFound
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound as ztkNotFound
@implementer(IPublishTraverse)
class DummyTraverser(object):
implements(IPublishTraverse)
def publishTraverse(self, request, name):
if name == 'dummy':
return 'dummy object'
......@@ -515,10 +514,10 @@ class TestRequestViewsBase(unittest.TestCase, BaseRequest_factory):
return IDummy
def _makeDummyObject(self, name='dummy'):
from zope.interface import implements
from zope.interface import implementer
@implementer(self._dummyInterface())
class DummyObjectZ3(self._makeBasicObjectClass()):
implements(self._dummyInterface())
def __init__(self, name):
self.name = name
......@@ -526,10 +525,10 @@ class TestRequestViewsBase(unittest.TestCase, BaseRequest_factory):
return DummyObjectZ3(name)
def _makeDummyObjectWithAttr(self, name):
from zope.interface import implements
from zope.interface import implementer
@implementer(self._dummyInterface())
class DummyObjectZ3WithAttr(self._makeBasicObjectClass()):
implements(self._dummyInterface())
def __init__(self, name):
self.name = name
......
......@@ -92,10 +92,10 @@ class WSGIResponseTests(unittest.TestCase):
def test_setBody_IUnboundStreamIterator(self):
from ZPublisher.Iterators import IUnboundStreamIterator
from zope.interface import implements
from zope.interface import implementer
@implementer(IUnboundStreamIterator)
class TestStreamIterator(object):
implements(IUnboundStreamIterator)
data = "hello"
done = 0
......@@ -115,10 +115,10 @@ class WSGIResponseTests(unittest.TestCase):
def test_setBody_IStreamIterator(self):
from ZPublisher.Iterators import IStreamIterator
from zope.interface import implements
from zope.interface import implementer
@implementer(IStreamIterator)
class TestStreamIterator(object):
implements(IStreamIterator)
data = "hello"
done = 0
......@@ -342,10 +342,10 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
def test_response_is_stream(self):
from ZPublisher.Iterators import IStreamIterator
from zope.interface import implements
from zope.interface import implementer
@implementer(IStreamIterator)
class TestStreamIterator(object):
implements(IStreamIterator)
data = "hello"
done = 0
......@@ -368,10 +368,10 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
def test_response_is_unboundstream(self):
from ZPublisher.Iterators import IUnboundStreamIterator
from zope.interface import implements
from zope.interface import implementer
@implementer(IUnboundStreamIterator)
class TestUnboundStreamIterator(object):
implements(IUnboundStreamIterator)
data = "hello"
done = 0
......
......@@ -13,17 +13,16 @@
##############################################################################
from zope.component import getUtility
from zope.interface import implements
from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.interfaces import IVocabularyRegistry
from zope.schema.vocabulary import setVocabularyRegistry
@implementer(IVocabularyRegistry)
class Zope2VocabularyRegistry(object):
"""IVocabularyRegistry that supports global and local utilities.
"""
implements(IVocabularyRegistry)
__slots__ = ()
def get(self, context, name):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment