diff --git a/CHANGES.rst b/CHANGES.rst index 5e8c7c56..fadf16da 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,8 @@ New features: Bug fixes: -- *add item here* +- Use zope.interface decorator. + [gforcada] 2.2.20 (2016-04-15) diff --git a/Products/CMFEditions/ArchivistTool.py b/Products/CMFEditions/ArchivistTool.py index ae0141b6..06af845a 100644 --- a/Products/CMFEditions/ArchivistTool.py +++ b/Products/CMFEditions/ArchivistTool.py @@ -27,7 +27,7 @@ import time from StringIO import StringIO from cPickle import Pickler, Unpickler -from zope.interface import implements, alsoProvides +from zope.interface import implementer, alsoProvides from App.class_init import InitializeClass from Persistence import Persistent @@ -72,10 +72,10 @@ def deepcopy(obj): u = Unpickler(stream) return u.load() +@implementer(IVersionData) class VersionData: """ """ - implements(IVersionData) def __init__(self, data, refs_to_be_deleted, attr_handling_references, preserved_data, metadata): @@ -87,8 +87,8 @@ def __init__(self, data, refs_to_be_deleted, attr_handling_references, self.app_metadata = metadata['app_metadata'] +@implementer(IAttributeAdapter) class AttributeAdapter(Persistent): - implements(IAttributeAdapter) def __init__(self, parent, attr_name, type=None): self._parent = aq_base(parent) @@ -109,8 +109,8 @@ def getAttributeName(self): def getType(self): return self._type +@implementer(IAttributeAdapter) class ObjectManagerStorageAdapter(Persistent): - implements(IAttributeAdapter) def __init__(self, parent, attr_name, type=None): self._parent = aq_base(parent) @@ -135,10 +135,10 @@ def getType(self): return self._type +@implementer(IVersionAwareReference) class VersionAwareReference(Persistent): """A Reference that is version aware (and in future also location aware). """ - implements(IVersionAwareReference) def __init__(self, **info): self.history_id = None @@ -172,10 +172,10 @@ def __of__(self, obj): return self +@implementer(IArchivistTool, IArchivist, IPurgeSupport) class ArchivistTool(UniqueObject, SimpleItem): """ """ - implements(IArchivistTool, IArchivist, IPurgeSupport) id = 'portal_archivist' alternative_id = 'portal_standard_archivist' @@ -405,10 +405,10 @@ def getUserId(): return getSecurityManager().getUser().getUserName() +@implementer(IObjectData) class ObjectData(Persistent): """ """ - implements(IObjectData) def __init__(self, obj, inside_refs=(), outside_refs=()): self.object = obj @@ -416,10 +416,10 @@ def __init__(self, obj, inside_refs=(), outside_refs=()): self.outside_refs = outside_refs +@implementer(IPreparedObject) class PreparedObject: """ """ - implements(IPreparedObject) def __init__(self, history_id, original, clone, referenced_data, app_metadata, sys_metadata, is_registered, approxSize): @@ -460,10 +460,10 @@ def copyVersionIdFromClone(self): self.original.object.version_id = self.clone.object.version_id +@implementer(IHistory) class LazyHistory: """Lazy history. """ - implements(IHistory) def __init__(self, archivist, obj, history_id, preserve, countPurged): """Sets up a lazy history. diff --git a/Products/CMFEditions/CopyModifyMergeRepositoryTool.py b/Products/CMFEditions/CopyModifyMergeRepositoryTool.py index 9144bd83..02f07877 100644 --- a/Products/CMFEditions/CopyModifyMergeRepositoryTool.py +++ b/Products/CMFEditions/CopyModifyMergeRepositoryTool.py @@ -35,7 +35,7 @@ from OFS.SimpleItem import SimpleItem from BTrees.OOBTree import OOBTree from zope.event import notify -from zope.interface import implements, Interface +from zope.interface import implementer, Interface from zope.lifecycleevent import ObjectModifiedEvent from Products.CMFCore.utils import UniqueObject, getToolByName from Products.CMFCore.utils import _checkPermission @@ -88,19 +88,17 @@ class IBaseObject(Interface): 'enable': 'enablePolicyOnTypeHook', 'disable': 'disablePolicyOnTypeHook'} +@implementer( + IPurgeSupport, + ICopyModifyMergeRepository, + IContentTypeVersionPolicySupport, + IRepositoryTool,) class CopyModifyMergeRepositoryTool(UniqueObject, SimpleItem): """See ICopyModifyMergeRepository """ - implements( - IPurgeSupport, - ICopyModifyMergeRepository, - IContentTypeVersionPolicySupport, - IRepositoryTool, - ) - id = 'portal_repository' alternative_id = 'portal_copymergerepository' @@ -739,10 +737,10 @@ def createTestHierarchy(self, context): createTestHierarchy(context) +@implementer(IVersionData) class VersionData: """ """ - implements(IVersionData) security = ClassSecurityInfo() security.declareObjectPublic() @@ -761,10 +759,10 @@ def __init__(self, object, preserved_data, sys_metadata, app_metadata): self.version_id = object.version_id +@implementer(IHistory) class LazyHistory: """Lazy history. """ - implements(IHistory) __allow_access_to_unprotected_subobjects__ = 1 diff --git a/Products/CMFEditions/KeepLastNVersionsTool.py b/Products/CMFEditions/KeepLastNVersionsTool.py index 52488cb1..15c4ff91 100644 --- a/Products/CMFEditions/KeepLastNVersionsTool.py +++ b/Products/CMFEditions/KeepLastNVersionsTool.py @@ -25,7 +25,7 @@ """ __version__ = "$Revision$" -from zope.interface import implements +from zope.interface import implementer from App.class_init import InitializeClass from AccessControl import ClassSecurityInfo @@ -39,12 +39,11 @@ from Products.CMFEditions.interfaces import IPurgePolicyTool from Products.CMFEditions.interfaces.IPurgePolicy import IPurgePolicy +@implementer(IPurgePolicyTool, IPurgePolicy) class KeepLastNVersionsTool(UniqueObject, SimpleItem, PropertyManager): """ """ - implements(IPurgePolicyTool, IPurgePolicy) - id = 'portal_purgepolicy' alternative_id = 'portal_keeplastnversions' diff --git a/Products/CMFEditions/ModifierRegistryTool.py b/Products/CMFEditions/ModifierRegistryTool.py index 43dbf74d..e2f30e2f 100644 --- a/Products/CMFEditions/ModifierRegistryTool.py +++ b/Products/CMFEditions/ModifierRegistryTool.py @@ -23,7 +23,7 @@ """ -from zope.interface import implements +from zope.interface import implementer from App.class_init import InitializeClass from Missing import MV @@ -52,16 +52,14 @@ from Products.CMFEditions.Modifiers import ConditionalTalesModifier -class ModifierRegistryTool(UniqueObject, OrderedFolder): - __doc__ = __doc__ # copy from module - - implements( +@implementer( IAttributeModifier, ISaveRetrieveModifier, ICloneModifier, IModifierRegistrySet, IModifierRegistryQuery, # IBulkEditableSubscriberRegistry, # not yet implemented - IPortalModifierTool, - ) + IPortalModifierTool,) +class ModifierRegistryTool(UniqueObject, OrderedFolder): + __doc__ = __doc__ # copy from module id = 'portal_modifier' alternative_id = 'portal_modifierregistry' diff --git a/Products/CMFEditions/Modifiers.py b/Products/CMFEditions/Modifiers.py index 4fd7f934..040ce8f0 100644 --- a/Products/CMFEditions/Modifiers.py +++ b/Products/CMFEditions/Modifiers.py @@ -26,7 +26,7 @@ from App.class_init import InitializeClass from Acquisition import aq_base, aq_parent, aq_inner -from zope.interface import implements +from zope.interface import implementer from OFS.SimpleItem import SimpleItem from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -43,14 +43,12 @@ globals(), __name__='manage_addModifierForm') +@implementer( + IConditionalModifier,) class ConditionalModifier(SimpleItem): """This is a wrapper for a modifier. """ - implements( - IConditionalModifier, - ) - modifierEditForm = PageTemplateFile('www/modifierEditForm.pt', globals(), __name__='modifierEditForm') @@ -105,14 +103,12 @@ def getModifier(self): globals(), __name__='manage_addTalesModifierForm') +@implementer( + IConditionalTalesModifier,) class ConditionalTalesModifier(ConditionalModifier): """This is a wrapper with a tales condition for a modifier. """ - implements( - IConditionalTalesModifier, - ) - modifierEditForm = PageTemplateFile('www/talesModifierEditForm.pt', globals(), __name__='modifierEditForm') diff --git a/Products/CMFEditions/ReferenceFactoriesTool.py b/Products/CMFEditions/ReferenceFactoriesTool.py index 9dd11583..ca1a8f17 100644 --- a/Products/CMFEditions/ReferenceFactoriesTool.py +++ b/Products/CMFEditions/ReferenceFactoriesTool.py @@ -26,7 +26,7 @@ from App.class_init import InitializeClass from AccessControl import ClassSecurityInfo -from zope.interface import implements +from zope.interface import implementer from Acquisition import aq_parent, aq_inner from OFS.OrderedFolder import OrderedFolder @@ -38,13 +38,11 @@ from Products.CMFEditions.interfaces.IReferenceFactories \ import IReferenceFactories +@implementer( + IReferenceFactories,) class ReferenceFactoriesTool(UniqueObject, OrderedFolder): __doc__ = __doc__ # copy from module - implements( - IReferenceFactories, - ) - id = 'portal_referencefactories' alternative_id = 'portal_referencefactoryregistry' diff --git a/Products/CMFEditions/StandardModifiers.py b/Products/CMFEditions/StandardModifiers.py index ec2169de..41b2322e 100644 --- a/Products/CMFEditions/StandardModifiers.py +++ b/Products/CMFEditions/StandardModifiers.py @@ -31,7 +31,7 @@ from zope.copy import copy from Acquisition import aq_base -from zope.interface import implements, Interface +from zope.interface import implementer, Interface from zope.component.interfaces import ComponentLookupError from zope.component.interfaces import IPossibleSite from ZODB.blob import Blob @@ -365,11 +365,11 @@ def manage_addSkip_z3c_blobfile(self, id, title=None, REQUEST=None): # Standard modifier implementation #---------------------------------------------------------------------- +@implementer(ISaveRetrieveModifier) class RetainAttributeAnnotationItemsBase: """Standard modifier retaining values of specific annotations from the working copy """ - implements(ISaveRetrieveModifier) PRESERVE_ANNOTATION_KEYS = () @@ -453,6 +453,7 @@ def _getAttributeNamesHandlingSubObjects(self, obj, repo_clone): return attrs +@implementer(ICloneModifier, ISaveRetrieveModifier) class OMOutsideChildrensModifier(OMBaseModifier): """ObjectManager modifier treating all childrens as outside refs @@ -460,8 +461,6 @@ class OMOutsideChildrensModifier(OMBaseModifier): knows what to do with that fact). """ - implements(ICloneModifier, ISaveRetrieveModifier) - def getOnCloneModifiers(self, obj): """Removes all childrens and returns them as references. """ @@ -515,6 +514,7 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(OMOutsideChildrensModifier) +@implementer(ICloneModifier, ISaveRetrieveModifier) class OMInsideChildrensModifier(OMBaseModifier): """ObjectManager modifier treating all childrens as inside refs @@ -522,8 +522,6 @@ class OMInsideChildrensModifier(OMBaseModifier): knows what to do with that fact). """ - implements(ICloneModifier, ISaveRetrieveModifier) - def getOnCloneModifiers(self, obj): """Removes all childrens and returns them as references. """ @@ -591,12 +589,11 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(OMInsideChildrensModifier) +@implementer(IReferenceAdapter) class OMSubObjectAdapter: """Adapter to an object manager children. """ - implements(IReferenceAdapter) - def __init__(self, obj, name): """Initialize the adapter. """ @@ -626,14 +623,13 @@ def remove(self, permanent=False): self._obj._delObject(self._name, suppress_events=True) +@implementer(ISaveRetrieveModifier) class RetainWorkflowStateAndHistory: """Standard modifier retaining the working copies workflow state Avoids the objects workflow state from beeing retrieved also. """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): # Saving the ``review_state`` as this is hard to achieve at retreive # (or because I'm dumb). What happened is that ``getInfoFor`` always @@ -673,14 +669,13 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(RetainWorkflowStateAndHistory) +@implementer(ISaveRetrieveModifier) class RetainPermissionsSettings: """Standard modifier retaining permissions settings This is nearly essential if we are going to be retaining workflow. """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): return {}, [], [] @@ -700,13 +695,12 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(RetainPermissionsSettings) +@implementer(ISaveRetrieveModifier) class RetainUIDs: """Modifier which ensures uid consistency by retaining the uid from the working copy. Ensuring that newly created objects are assigned an appropriate uid is a job for the repository tool. """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): return {}, [], [] @@ -743,13 +737,12 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(RetainUIDs) +@implementer(ISaveRetrieveModifier) class RetainATRefs: """Modifier which ensures the Archetypes references of the working copy are preserved when reverting to a previous version """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): return {}, [], [] @@ -769,6 +762,7 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(RetainATRefs) +@implementer(ISaveRetrieveModifier) class NotRetainATRefs: """Modifier which removes Archetypes references of the working copy when reverting to a previous version without those references. @@ -776,8 +770,6 @@ class NotRetainATRefs: keep the reference_catalog in sync, and to call the delHook(). """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): return {}, [], [] @@ -807,14 +799,13 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(NotRetainATRefs) +@implementer(IAttributeModifier) class SaveFileDataInFileTypeByReference: """Standard modifier avoiding unnecessary cloning of the file data. Called on 'Portal File' objects. """ - implements(IAttributeModifier) - def getReferencedAttributes(self, obj): return {'data': getattr(aq_base(obj),'data', None)} @@ -827,13 +818,12 @@ def reattachReferencedAttributes(self, obj, attrs_dict): InitializeClass(SaveFileDataInFileTypeByReference) +@implementer(ICloneModifier, ISaveRetrieveModifier) class SkipParentPointers: """Standard modifier to avoid cloning of __parent__ pointers and restore them from context """ - implements(ICloneModifier, ISaveRetrieveModifier) - def getOnCloneModifiers(self, obj): """Removes parent pointers and stores a marker """ @@ -868,13 +858,12 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(SkipParentPointers) +@implementer(ICloneModifier, ISaveRetrieveModifier) class SkipRegistryBasesPointers: """Standard modifier to avoid cloning of component registry __bases__ and restore them from context """ - implements(ICloneModifier, ISaveRetrieveModifier) - def querySiteManager(self, obj): if not IPossibleSite.providedBy(obj): return @@ -929,6 +918,7 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(SkipRegistryBasesPointers) +@implementer(ISaveRetrieveModifier) class SillyDemoRetrieveModifier: """Silly Retrieve Modifier for Demos @@ -938,8 +928,6 @@ class SillyDemoRetrieveModifier: This is really just as silly example though for demo purposes!!! """ - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, clone): return {}, [], [] @@ -965,6 +953,7 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): ANNOTATION_PREFIX = 'Archetypes.storage.AnnotationStorage-' +@implementer(IConditionalTalesModifier, ICloneModifier) class AbortVersioningOfLargeFilesAndImages(ConditionalTalesModifier): """Raises an error if a file or image attribute stored on the object in a specified field is larger than a fixed default""" @@ -972,8 +961,6 @@ class AbortVersioningOfLargeFilesAndImages(ConditionalTalesModifier): field_names = ('file', 'image') max_size = 26214400 # This represents a 400 element long Pdata list - implements(IConditionalTalesModifier, ICloneModifier) - modifierEditForm = PageTemplateFile('www/fieldModifierEditForm.pt', globals(), __name__='modifierEditForm') @@ -1056,14 +1043,13 @@ class LargeFilePlaceHolder(object): def getSize(): return sys.maxint +@implementer(IConditionalTalesModifier, ICloneModifier, + ISaveRetrieveModifier) class SkipVersioningOfLargeFilesAndImages(AbortVersioningOfLargeFilesAndImages): """Replaces any excessively large file and images stored as annotations or attributes on the object with a marker. On retrieve, the marker will be replaced with the current value..""" - implements(IConditionalTalesModifier, ICloneModifier, - ISaveRetrieveModifier) - def getOnCloneModifiers(self, obj): """Removes large file objects and returns them as references """ @@ -1121,14 +1107,13 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): class BlobProxy(object): pass +@implementer(ICloneModifier, ISaveRetrieveModifier) class SkipBlobs: """Standard avoid storing blob data, may be useful for extremely large files where versioing the non-file metadata is important but the cost of versioning the file data is too high. """ - implements(ICloneModifier, ISaveRetrieveModifier) - def getOnCloneModifiers(self, obj): """Removes blob objects and stores a marker """ @@ -1164,13 +1149,12 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()): InitializeClass(SkipBlobs) +@implementer(IAttributeModifier, ICloneModifier) class CloneBlobs: """Standard modifier to save an un-cloned reference to the blob to avoid it being packed away. """ - implements(IAttributeModifier, ICloneModifier) - def getReferencedAttributes(self, obj): file_data = {} @@ -1253,14 +1237,13 @@ def persistent_load(obj): InitializeClass(CloneBlobs) +@implementer(ICloneModifier, ISaveRetrieveModifier) class Skip_z3c_blobfile: """Standard avoid storing blob data, may be useful for extremely large files where versioing the non-file metadata is important but the cost of versioning the file data is too high. """ - implements(ICloneModifier, ISaveRetrieveModifier) - def _blob_file_classes(self): blob_file_classes = [] try: diff --git a/Products/CMFEditions/VersionPolicies.py b/Products/CMFEditions/VersionPolicies.py index fbaa18f8..6bb5853d 100644 --- a/Products/CMFEditions/VersionPolicies.py +++ b/Products/CMFEditions/VersionPolicies.py @@ -28,14 +28,13 @@ from OFS.SimpleItem import SimpleItem from Products.CMFCore.utils import getToolByName from Products.CMFEditions.interfaces.IVersionPolicy import IVersionPolicy -from zope.interface import implements +from zope.interface import implementer +@implementer(IVersionPolicy) class VersionPolicy(SimpleItem): """A simple class for storing version policy information""" - implements(IVersionPolicy) - security = ClassSecurityInfo() def __init__(self, obj_id, title, **kw): diff --git a/Products/CMFEditions/ZVCStorageTool.py b/Products/CMFEditions/ZVCStorageTool.py index 1dc96a2f..42a66ff3 100644 --- a/Products/CMFEditions/ZVCStorageTool.py +++ b/Products/CMFEditions/ZVCStorageTool.py @@ -30,7 +30,7 @@ import types from StringIO import StringIO from cPickle import Pickler, Unpickler, dumps, loads, HIGHEST_PROTOCOL -from zope.interface import implements +from zope.interface import implementer from App.class_init import InitializeClass from BTrees.OOBTree import OOBTree @@ -127,6 +127,10 @@ def getSize(obj): return size +@implementer( + IPurgeSupport, + IStorage, + IStorageTool,) class ZVCStorageTool(UniqueObject, SimpleItem): """Zope Version Control Based Version Storage @@ -148,12 +152,6 @@ class ZVCStorageTool(UniqueObject, SimpleItem): objects. """ - implements( - IPurgeSupport, - IStorage, - IStorageTool, - ) - id = 'portal_historiesstorage' alternative_id = 'portal_zvcstorage' @@ -981,8 +979,8 @@ def __init__(self, reason, metadata): self.metadata = metadata +@implementer(IVersionData) class VersionData: - implements(IVersionData) def __init__(self, object, referenced_data, metadata): self.object = object @@ -994,14 +992,12 @@ def isValid(self): """ return not isinstance(self.object, Removed) +@implementer( + IHistory,) class LazyHistory: """Lazy history adapter. """ - implements( - IHistory, - ) - def __init__(self, storage, history_id, countPurged=True, substitute=True): """See IHistory. """ diff --git a/Products/CMFEditions/tests/DummyTools.py b/Products/CMFEditions/tests/DummyTools.py index 8dc864f1..ddd9ff14 100644 --- a/Products/CMFEditions/tests/DummyTools.py +++ b/Products/CMFEditions/tests/DummyTools.py @@ -4,7 +4,7 @@ from StringIO import StringIO import types -from zope.interface import implements +from zope.interface import implementer from Acquisition import aq_base from DateTime import DateTime @@ -459,9 +459,8 @@ def __init__(self, reason, metadata): self.reason = reason self.metadata = metadata +@implementer(IStorage, IPurgeSupport) class MemoryStorage(DummyBaseTool): - - implements(IStorage, IPurgeSupport) id = 'portal_historiesstorage' @@ -627,10 +626,10 @@ def retrieve(self, selector, ignored=True): item = self[selector] return {'metadata': item.metadata} +@implementer(IPurgePolicy) class DummyPurgePolicy(DummyBaseTool): """Dummy Purge Policy """ - implements(IPurgePolicy) id = 'portal_purgepolicy' def beforeSaveHook(self, history_id, obj, metadata={}): @@ -663,11 +662,10 @@ def retrieveSubstitute(self, history_id, selector, default=None): return default +@implementer(IStorage, IPurgeSupport) class PurgePolicyTestDummyStorage(DummyBaseTool): """Partial Storage used for PurgePolicy Tetss """ - - implements(IStorage, IPurgeSupport) id = 'portal_historiesstorage' def __init__(self): diff --git a/Products/CMFEditions/tests/test_ModifierRegistryTool.py b/Products/CMFEditions/tests/test_ModifierRegistryTool.py index 978541ac..287d31c5 100644 --- a/Products/CMFEditions/tests/test_ModifierRegistryTool.py +++ b/Products/CMFEditions/tests/test_ModifierRegistryTool.py @@ -29,7 +29,7 @@ from zope.interface.verify import verifyObject from Acquisition import aq_base -from zope.interface import implements +from zope.interface import implementer from Products.CMFCore.utils import getToolByName @@ -49,10 +49,9 @@ def deepcopy(obj): deepcopy(Dummy()) +@implementer(ISaveRetrieveModifier) class SimpleModifierBase: - implements(ISaveRetrieveModifier) - def beforeSaveModifier(self, obj, copy_obj): try: bsm = getattr(copy_obj, self.beforeSaveModifierAttribute) @@ -96,10 +95,9 @@ def dictToString(dict): dict_list.append("%s = %s" % (k, dict[k])) return ', '.join(dict_list) +@implementer(IAttributeModifier, ICloneModifier, ISaveRetrieveModifier) class LoggingModifierBase: - implements(IAttributeModifier, ICloneModifier, ISaveRetrieveModifier) - def getReferencedAttributes(self, obj): referenced_data = { 'k1': 'v1:'+str(self.__class__.__name__),