Commit df082f19 authored by Tres Seaver's avatar Tres Seaver

Drop support for Python 2.4 and 2.5.

Replace deprecated 'zope.component.adapts' usage with equivalent
'zope.component.adapter' decorator.

Replace deprecated 'zope.interface.implements' usage with equivalent
'zope.interface.implementer' decorator.
parent 6d8039d9
......@@ -2,9 +2,17 @@
CHANGES
=======
3.12.1 (unreleased)
4.0.0 (unreleased)
-------------------
- Replaced deprecated ``zope.component.adapts`` usage with equivalent
``zope.component.adapter`` decorator.
- Replaced deprecated ``zope.interface.implements`` usage with equivalent
``zope.interface.implementer`` decorator.
- Dropped support for Python 2.4 and 2.5.
- Send ``IContainerModifiedEvent`` *after* the container is modified
(LP#705600).
......
......@@ -25,7 +25,7 @@ def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='zope.container',
version = '3.12.1dev',
version = '4.0.0dev',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Container',
......@@ -45,11 +45,14 @@ setup(name='zope.container',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
'Framework :: Zope3',
],
url='http://pypi.python.org/pypi/zope.container',
license='ZPL 2.1',
packages=find_packages('src'),
......
......@@ -21,7 +21,7 @@ from BTrees.Length import Length
from zope.container.interfaces import IBTreeContainer
from zope.container.contained import Contained, setitem, uncontained
from zope.interface import implements
from zope.interface import implementer
class Lazy(object):
......@@ -44,10 +44,9 @@ class Lazy(object):
return value
@implementer(IBTreeContainer)
class BTreeContainer(Contained, Persistent):
implements(IBTreeContainer)
def __init__(self):
# We keep the previous attribute to store the data
# for backward compatibility
......
......@@ -34,8 +34,8 @@
... __setitem__.precondition = preNoZ
>>> from zope.container.interfaces import IContainer
>>> class C1(object):
... zope.interface.implements(I1, IContainer)
>>> @zope.interface.implementer(I1, IContainer)
... class C1(object):
... def __repr__(self):
... return 'C1'
......@@ -66,8 +66,9 @@
>>> class I2(zope.interface.Interface):
... __parent__ = zope.schema.Field(constraint = con1)
>>> class O(object):
... zope.interface.implements(I2)
>>> @zope.interface.implementer(I2)
... class O(object):
... pass
If the constraint isn't satisfied, we'll get a validation error when we
check whether the object can be added:
......@@ -90,8 +91,9 @@
>>> class I2(zope.interface.Interface):
... __parent__ = zope.schema.Field(constraint = con1)
>>> class O(object):
... zope.interface.implements(I2)
>>> @zope.interface.implementer(I2)
... class O(object):
... pass
>>> checkObject(c1, "bob", O())
Traceback (most recent call last):
......@@ -279,6 +281,7 @@ class _TypesBased(object):
self.types = types
@zope.interface.implementer(IItemTypePrecondition)
class ItemTypePrecondition(_TypesBased):
"""Specify a `__setitem__` precondition that restricts item types
......@@ -326,7 +329,6 @@ class ItemTypePrecondition(_TypesBased):
"""
zope.interface.implements(IItemTypePrecondition)
def __call__(self, container, name, object):
for iface in self.types:
......@@ -399,6 +401,7 @@ class IContainerTypesConstraint(zope.interface.Interface):
"""
@zope.interface.implementer(IContainerTypesConstraint)
class ContainerTypesConstraint(_TypesBased):
"""Constrain a container to be one of a number of types
......@@ -423,9 +426,6 @@ class ContainerTypesConstraint(_TypesBased):
True
"""
zope.interface.implements(IContainerTypesConstraint)
def __call__(self, object):
for iface in self.types:
if iface.providedBy(object):
......
......@@ -31,11 +31,13 @@ folders:
>>> from zope import interface
>>> class Buddy:
... interface.implements(IBuddy)
>>> @interface.implementer(IBuddy)
... class Buddy:
... pass
>>> class BuddyFolder:
... interface.implements(IBuddyFolder)
>>> @interface.implementer(IBuddyFolder)
... class BuddyFolder:
... pass
>>> from zope.container.constraints import checkObject, checkFactory
>>> from zope.component.factory import Factory
......@@ -46,11 +48,13 @@ folders:
If we try to use other containers or folders, we'll get errors:
>>> class Container:
... interface.implements(IContainer)
>>> @interface.implementer(IContainer)
... class Container:
... pass
>>> class Contained:
... interface.implements(IContained)
>>> @interface.implementer(IContained)
... class Contained:
... pass
>>> checkObject(Container(), 'x', Buddy())
... # doctest: +ELLIPSIS
......@@ -77,11 +81,13 @@ could have defined these in the opposite order:
>>> class IContacts(IContainer):
... contains(IContact)
>>> class Contact:
... interface.implements(IContact)
>>> @interface.implementer(IContact)
... class Contact:
... pass
>>> class Contacts:
... interface.implements(IContacts)
>>> @interface.implementer(IContacts)
... class Contacts:
... pass
>>> checkObject(Contacts(), 'x', Contact())
......
......@@ -44,17 +44,17 @@ except ImportError:
from zope.broken.interfaces import IBroken
@zope.interface.implementer(IContained)
class Contained(object):
"""Stupid mix-in that defines `__parent__` and `__name__` attributes"""
zope.interface.implements(IContained)
__parent__ = __name__ = None
@zope.interface.implementer(IContainerModifiedEvent)
class ContainerModifiedEvent(ObjectModifiedEvent):
"""The container has been modified."""
zope.interface.implements(IContainerModifiedEvent)
def dispatchToSublocations(object, event):
......@@ -67,8 +67,8 @@ def dispatchToSublocations(object, event):
Suppose, for example, that we define some location objects.
>>> class L(object):
... zope.interface.implements(ILocation)
>>> @zope.interface.implementer(ILocation)
... class L(object):
... def __init__(self, name):
... self.__name__ = name
... self.__parent__ = None
......@@ -76,8 +76,8 @@ def dispatchToSublocations(object, event):
... return '%s(%s)' % (
... self.__class__.__name__, str(self.__name__))
>>> class C(L):
... zope.interface.implements(ISublocations)
>>> @zope.interface.implementer(ISublocations)
... class C(L):
... def __init__(self, name, *subs):
... L.__init__(self, name)
... self.subs = subs
......@@ -342,8 +342,8 @@ def setitem(container, setitemf, name, object):
>>> class IItem(zope.interface.Interface):
... pass
>>> class Item(Contained):
... zope.interface.implements(IItem)
>>> @zope.interface.implementer(IItem)
... class Item(Contained):
... def setAdded(self, event):
... self.added = event
... def setMoved(self, event):
......@@ -683,10 +683,9 @@ def uncontained(object, container, name=None):
object.__name__ = None
notifyContainerModified(container)
@zope.interface.implementer(INameChooser)
class NameChooser(object):
zope.interface.implements(INameChooser)
def __init__(self, context):
self.context = context
......@@ -730,9 +729,9 @@ class NameChooser(object):
to a container:
>>> from zope.container.interfaces import IContainer
>>> class ReservedNames(object):
... zope.component.adapts(IContainer)
... zope.interface.implements(IReservedNames)
>>> @zope.component.adapter(IContainer)
... @zope.interface.implementer(IReservedNames)
... class ReservedNames(object):
...
... def __init__(self, context):
... self.reservedNames = set(('reserved', 'other'))
......@@ -855,15 +854,18 @@ class DecoratorSpecificationDescriptor(
>>> class I4(Interface):
... pass
>>> class D1(ContainedProxy):
... implements(I1)
>>> @implementer(I1)
... class D1(ContainedProxy):
... pass
>>> class D2(ContainedProxy):
... implements(I2)
>>> @implementer(I2)
... class D2(ContainedProxy):
... pass
>>> class X:
... implements(I3)
>>> @implementer(I3)
... class X:
... pass
>>> x = X()
>>> directlyProvides(x, I4)
......@@ -923,6 +925,7 @@ class ContainedProxyClassProvides(zope.interface.declarations.ClassProvides):
inst = getProxiedObject(inst)
del inst.__provides__
@zope.interface.implementer(IContained)
class ContainedProxy(ContainedProxyBase):
# Prevent proxies from having their own instance dictionaries:
......@@ -930,8 +933,6 @@ class ContainedProxy(ContainedProxyBase):
__safe_for_unpickling__ = True
zope.interface.implements(IContained)
__providedBy__ = DecoratorSpecificationDescriptor()
__Security_checker__ = DecoratedSecurityCheckerDescriptor()
......
......@@ -23,7 +23,7 @@ providing a file-system representation for containers:
"""
__docformat__ = 'restructuredtext'
from zope.interface import implements
from zope.interface import implementer
from zope.component.interfaces import ISite
from zope.security.proxy import removeSecurityProxy
......@@ -40,15 +40,13 @@ def noop(container):
return container
@implementer(zope.filerepresentation.interfaces.IDirectoryFactory)
class Cloner(object):
"""`IContainer` to `IDirectoryFactory` adapter that clones
This adapter provides a factory that creates a new empty container
of the same class as it's context.
"""
implements(zope.filerepresentation.interfaces.IDirectoryFactory)
def __init__(self, context):
self.context = context
......
......@@ -15,14 +15,13 @@
"""
__docformat__ = 'restructuredtext'
from zope.interface import implements
from zope.interface import implementer
from interfaces import IFind, IIdFindFilter, IObjectFindFilter
from interfaces import IReadContainer
@implementer(IFind)
class FindAdapter(object):
implements(IFind)
__used_for__ = IReadContainer
def __init__(self, context):
......@@ -62,10 +61,9 @@ def _find_helper(id, object, container, id_filters, object_filters, result):
for id, object in container.items():
_find_helper(id, object, container, id_filters, object_filters, result)
@implementer(IIdFindFilter)
class SimpleIdFindFilter(object):
implements(IIdFindFilter)
def __init__(self, ids):
self._ids = ids
......@@ -73,9 +71,9 @@ class SimpleIdFindFilter(object):
'See INameFindFilter'
return id in self._ids
@implementer(IObjectFindFilter)
class SimpleInterfacesFindFilter(object):
"""Filter objects on the provided interfaces"""
implements(IObjectFindFilter)
def __init__(self, *interfaces):
self.interfaces = interfaces
......
......@@ -19,7 +19,7 @@ from BTrees.OOBTree import OOBTree
from persistent import Persistent
from zope.container.interfaces import IContainer, IContentContainer
from zope.container.contained import Contained, setitem, uncontained
from zope.interface import implements, directlyProvides
from zope.interface import implementer
# XXX This container implementation is really only used by
# zope.site.folder.Folder. Please do not use it.
......@@ -27,10 +27,10 @@ from zope.interface import implements, directlyProvides
# XXX Check whether this IContainer implementation cannot really
# be replaced by the BTreeContainer.
@implementer(IContentContainer)
class Folder(Persistent, Contained):
"""The standard Zope Folder implementation."""
implements(IContentContainer)
def __init__(self):
self.data = OOBTree()
......
......@@ -16,7 +16,7 @@
__docformat__ = 'restructuredtext'
from zope.container.interfaces import IOrderedContainer
from zope.interface import implements
from zope.interface import implementer
from persistent import Persistent
from persistent.dict import PersistentDict
from persistent.list import PersistentList
......@@ -24,6 +24,7 @@ from types import StringTypes, TupleType, ListType
from zope.container.contained import Contained, setitem, uncontained
from zope.container.contained import notifyContainerModified
@implementer(IOrderedContainer)
class OrderedContainer(Persistent, Contained):
""" `OrderedContainer` maintains entries' order as added and moved.
......@@ -33,9 +34,6 @@ class OrderedContainer(Persistent, Contained):
>>> len(oc)
0
"""
implements(IOrderedContainer)
def __init__(self):
self._data = PersistentDict()
......
......@@ -21,17 +21,17 @@ need a very different implementation.
__docformat__ = 'restructuredtext'
from zope.container.interfaces import IContainer
from zope.interface import implements
from zope.interface import implementer
from zope.container.contained import Contained, setitem, uncontained
@implementer(IContainer)
class SampleContainer(Contained):
"""Sample container implementation suitable for testing.
It is not suitable, directly as a base class unless the subclass
overrides `_newContainerData` to return a persistent mapping object.
"""
implements(IContainer)
def __init__(self):
self.__data = self._newContainerData()
......
......@@ -18,12 +18,11 @@ __docformat__ = 'restructuredtext'
from zope.container.i18n import ZopeMessageFactory as _
from zope.size.interfaces import ISized
from zope.interface import implements
from zope.interface import implementer
@implementer(ISized)
class ContainerSized(object):
implements(ISized)
def __init__(self, container):
self._container = container
......
......@@ -97,8 +97,9 @@ def test_declarations_on_ContainedProxy():
>>> class I1(zope.interface.Interface):
... pass
>>> class C(object):
... zope.interface.implements(I1)
>>> @zope.interface.implementer(I1)
... class C(object):
... pass
>>> c = C()
>>> p = ContainedProxy(c)
......@@ -350,9 +351,9 @@ class TestNameChooser(unittest.TestCase):
self.assertEqual(True, checkName(u'r\xe9served', object()))
# reserved names
@zope.component.adapter(IContainer)
@zope.interface.implementer(IReservedNames)
class ReservedNames(object):
zope.component.adapts(IContainer)
zope.interface.implements(IReservedNames)
def __init__(self, context):
self.reservedNames = set(('reserved', 'other'))
zope.component.getSiteManager().registerAdapter(ReservedNames)
......
......@@ -15,16 +15,15 @@
"""
import unittest
from zope.testing.cleanup import CleanUp
from zope.interface import implements
from zope.interface import implementer
from zope.traversing.interfaces import TraversalError
from zope.container.traversal import ContainerTraversable
from zope.container.interfaces import IContainer
@implementer(IContainer)
class Container(object):
implements(IContainer)
def __init__(self, attrs={}, objs={}):
for attr,value in attrs.iteritems():
setattr(self, attr, value)
......
......@@ -14,7 +14,7 @@
"""Container Traverser Tests
"""
import unittest
from zope.interface import Interface, implements
from zope.interface import Interface, implementer
from zope import component
from zope.publisher.interfaces import NotFound, IDefaultViewName
from zope.publisher.browser import TestRequest
......@@ -24,8 +24,8 @@ from zope.container.traversal import ContainerTraverser
from zope.container.interfaces import IReadContainer
from zope.container import testing
@implementer(IReadContainer)
class TestContainer(object):
implements(IReadContainer)
def __init__(self, **kw):
for name, value in kw.items():
......
import unittest
from zope.configuration.xmlconfig import XMLConfig
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPublisher
......@@ -22,8 +22,9 @@ class ZCMLDependencies(ContainerPlacelessSetup, unittest.TestCase):
request = TestRequest()
@implementer(IItemContainer)
class SampleItemContainer(object):
implements(IItemContainer)
pass
sampleitemcontainer = SampleItemContainer()
res = zope.component.getMultiAdapter(
......@@ -31,8 +32,9 @@ class ZCMLDependencies(ContainerPlacelessSetup, unittest.TestCase):
self.failUnless(isinstance(res, ItemTraverser))
self.failUnless(res.context is sampleitemcontainer)
@implementer(ISimpleReadContainer)
class SampleSimpleReadContainer(object):
implements(ISimpleReadContainer)
pass
samplesimplereadcontainer = SampleSimpleReadContainer()
res = zope.component.getMultiAdapter(
......
......@@ -18,10 +18,10 @@ from zope.container.interfaces import IReadContainer
from zope.container.interfaces import IObjectFindFilter
from zope.container.find import FindAdapter, SimpleIdFindFilter
from zope.container.find import SimpleInterfacesFindFilter
from zope.interface import implements, Interface, directlyProvides
from zope.interface import implementer, Interface, directlyProvides
@implementer(IReadContainer)
class FakeContainer(object):
implements(IReadContainer)
def __init__(self, id, objects):
self._id = id
......@@ -67,8 +67,8 @@ class FakeInterfaceBar(Interface):
class FakeInterfaceSpam(Interface):
"""Test interface Spam"""
@implementer(IObjectFindFilter)
class TestObjectFindFilter(object):
implements(IObjectFindFilter)
def __init__(self, count):
self._count = count
......
......@@ -15,14 +15,13 @@
"""
import unittest
from zope.interface import implements
from zope.interface import implementer
from zope.size.interfaces import ISized
from zope.container.interfaces import IContainer
@implementer(IContainer)
class DummyContainer(object):
implements(IContainer)
def __init__(self, numitems):
self._numitems = numitems
......
......@@ -15,7 +15,7 @@
"""
__docformat__ = 'restructuredtext'
from zope.interface import implements, providedBy
from zope.interface import implementer, providedBy
from zope.component import queryMultiAdapter, getSiteManager
from zope.component import ComponentLookupError
from zope.traversing.interfaces import TraversalError, ITraversable
......@@ -29,10 +29,10 @@ from zope.container.interfaces import IReadContainer
# Note that the next two classes are included here because they
# can be used for multiple view types.
@implementer(IBrowserPublisher, IXMLRPCPublisher)
class ContainerTraverser(object):
"""A traverser that knows how to look up objects by name in a container."""
implements(IBrowserPublisher, IXMLRPCPublisher)
__used_for__ = ISimpleReadContainer
def __init__(self, container, request):
......@@ -84,10 +84,10 @@ class ItemTraverser(ContainerTraverser):
_marker = object()
@implementer(ITraversable)
class ContainerTraversable(object):
"""Traverses containers via `getattr` and `get`."""
implements(ITraversable)
__used_for__ = IReadContainer
def __init__(self, container):
......
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