Skip to content

Commit

Permalink
Use zope.interface decorator
Browse files Browse the repository at this point in the history
This not only makes code more pleasent to read,
but also makes the code python 3 compatible
(while maintaining python 2 compatibility).
  • Loading branch information
gforcada committed Jul 5, 2016
1 parent 6f0aa13 commit ef7e0cf
Show file tree
Hide file tree
Showing 37 changed files with 80 additions and 115 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ New features:

Bug fixes:

- *add item here*
- Use zope.interface decorator.
[gforcada]


2.2.12 (2016-05-15)
Expand Down
4 changes: 2 additions & 2 deletions Products/ATContentTypes/browser/download.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
from AccessControl import Unauthorized
from Products.Five import BrowserView
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound as pNotFound


@implementer(IPublishTraverse)
class DownloadArchetypeFile(BrowserView):
"""Basically, straight copy from plone.namedfile
"""
implements(IPublishTraverse)

def __init__(self, context, request):
super(DownloadArchetypeFile, self).__init__(context, request)
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/browser/nextprevious.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
from Products.CMFCore.utils import getToolByName
from zope.component import adapts
from zope.component import getUtility
from zope.interface import implements
from zope.interface import implementer


@implementer(INextPreviousProvider)
class ATFolderNextPrevious(object):
"""Let a folder act as a next/previous provider. This will be
automatically found by the @@plone_nextprevious_view and viewlet.
"""

implements(INextPreviousProvider)
adapts(IATFolder)

def __init__(self, context):
Expand Down
8 changes: 3 additions & 5 deletions Products/ATContentTypes/content/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from webdav.NullResource import NullResource
from webdav.Resource import Resource as WebdavResoure
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer

import logging
import os
Expand Down Expand Up @@ -88,6 +88,7 @@ def __getattr__(self, name):
return getattr(self.__ob, name)


@implementer(IATContentType)
class ATCTMixin(BrowserDefaultMixin):
"""Mixin class for AT Content Types"""

Expand All @@ -103,8 +104,6 @@ class ATCTMixin(BrowserDefaultMixin):
isDocTemp = False
_at_rename_after_creation = True # rename object according to the title?

implements(IATContentType)

security = ClassSecurityInfo()

@security.protected(ModifyPortalContent)
Expand Down Expand Up @@ -438,11 +437,10 @@ def get_size(self):
InitializeClass(ATCTFolder)


@implementer(ISelectableConstrainTypes)
class ATCTFolderMixin(ConstrainTypesMixin, ATCTMixin):
""" Constrained folderish type """

implements(ISelectableConstrainTypes)

security = ClassSecurityInfo()

def __browser_default__(self, request):
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from Products.CMFCore.utils import getToolByName
from Products.GenericSetup.interfaces import IDAVAware
from types import TupleType
from zope.interface import implements
from zope.interface import implementer
from ZPublisher.HTTPRequest import HTTPRequest


Expand Down Expand Up @@ -217,6 +217,7 @@ def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
RESPONSE)


@implementer(IATDocument, IDAVAware)
class ATDocument(ATDocumentBase):
"""A page in the site. Can contain rich text."""

Expand All @@ -228,6 +229,4 @@ class ATDocument(ATDocumentBase):
assocMimetypes = ('application/xhtml+xml', 'message/rfc822', 'text/*',)
assocFileExt = ('txt', 'stx', 'rst', 'rest', 'py',)

implements(IATDocument, IDAVAware)

registerATCT(ATDocument, PROJECTNAME)
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from Products.ATContentTypes.lib.historyaware import HistoryAwareMixin
from Products.CMFCore.permissions import ModifyPortalContent
from Products.CMFCore.permissions import View
from zope.interface import implements
from zope.interface import implementer


ATEventSchema = ATContentTypeSchema.copy() + Schema((
Expand Down Expand Up @@ -164,6 +164,7 @@
ATEventSchema.moveField('location', before='startDate')


@implementer(IATEvent)
class ATEvent(ATCTContent, CalendarSupportMixin, HistoryAwareMixin):
"""Information about an upcoming event.
Expand All @@ -183,8 +184,6 @@ class ATEvent(ATCTContent, CalendarSupportMixin, HistoryAwareMixin):
'start_date', 'end_date', 'contact_name', 'contact_email',
'contact_phone', 'event_url')

implements(IATEvent)

security = ClassSecurityInfo()

@security.private
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from Products.validation.config import validation
from Products.validation.validators.SupplValidators import MaxSizeValidator
from urllib import quote
from zope.interface import implements
from zope.interface import implementer

import logging

Expand Down Expand Up @@ -56,6 +56,7 @@
finalizeATCTSchema(ATFileSchema)


@implementer(IATFile)
class ATFile(ATCTFileContent):
"""An external file uploaded to the site."""

Expand All @@ -74,8 +75,6 @@ class ATFile(ATCTFileContent):
'application/pdf',
'application/x-shockwave-flash',)

implements(IATFile)

security = ClassSecurityInfo()

@security.protected(View)
Expand Down
8 changes: 3 additions & 5 deletions Products/ATContentTypes/content/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from Products.ATContentTypes.interfaces import IATFolder
from Products.ATContentTypes.lib.constraintypes import ConstrainTypesMixinSchema # noqa
from Products.CMFCore.permissions import View
from zope.interface import implements
from zope.interface import implementer


ATFolderSchema = folder.ATFolderSchema
Expand All @@ -32,6 +32,7 @@
HAS_LINGUAPLONE = False


@implementer(IATFolder, IOrderedContainer)
class ObsoleteATFolder(ATCTOrderedFolder):
"""A folder which can contain other items."""

Expand All @@ -45,8 +46,6 @@ class ObsoleteATFolder(ATCTOrderedFolder):
assocFileExt = ()
cmf_edit_kws = ()

implements(IATFolder, IOrderedContainer)

# Enable marshalling via WebDAV/FTP.
__dav_marshall__ = True

Expand Down Expand Up @@ -96,6 +95,7 @@ class ATFolder(folder.ATFolder):
registerATCT(ATFolder, PROJECTNAME)


@implementer(IATBTreeFolder)
class ATBTreeFolder(ATCTBTreeFolder):
"""A folder suitable for holding a very large number of items.
Expand All @@ -115,8 +115,6 @@ class ATBTreeFolder(ATCTBTreeFolder):
assocFileExt = ()
cmf_edit_kws = ()

implements(IATBTreeFolder)

# Enable marshalling via WebDAV/FTP.
__dav_marshall__ = True

Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from Products.validation import V_REQUIRED
from Products.validation.config import validation
from Products.validation.validators.SupplValidators import MaxSizeValidator
from zope.interface import implements
from zope.interface import implementer


validation.register(MaxSizeValidator('checkImageMaxSize',
Expand Down Expand Up @@ -65,6 +65,7 @@
finalizeATCTSchema(ATImageSchema)


@implementer(IATImage)
class ATImage(ATCTFileContent, ATCTImageTransform):
"""An image, which can be referenced in documents.
Expand All @@ -81,8 +82,6 @@ class ATImage(ATCTFileContent, ATCTImageTransform):
assocFileExt = ('jpg', 'jpeg', 'png', 'gif', )
cmf_edit_kws = ('file', )

implements(IATImage)

security = ClassSecurityInfo()

def exportImage(self, format, width, height):
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from Products.CMFCore.permissions import ModifyPortalContent
from Products.CMFCore.permissions import View
from urllib import quote
from zope.interface import implements
from zope.interface import implementer

import urlparse

Expand All @@ -35,6 +35,7 @@
finalizeATCTSchema(ATLinkSchema)


@implementer(IATLink)
class ATLink(ATCTContent):
"""A link to an internal or external resource."""

Expand All @@ -47,8 +48,6 @@ class ATLink(ATCTContent):
assocFileExt = ('link', 'url', )
cmf_edit_kws = ('remote_url', )

implements(IATLink)

security = ClassSecurityInfo()

@security.protected(ModifyPortalContent)
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/content/newsitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from Products.validation import V_REQUIRED
from Products.validation.config import validation
from Products.validation.validators.SupplValidators import MaxSizeValidator
from zope.interface import implements
from zope.interface import implementer


validation.register(MaxSizeValidator('checkNewsImageMaxSize',
Expand Down Expand Up @@ -90,6 +90,7 @@
finalizeATCTSchema(ATNewsItemSchema)


@implementer(IATNewsItem)
class ATNewsItem(ATDocumentBase, ATCTImageTransform):
"""An announcement that will show up on the news portlet.
Expand All @@ -106,8 +107,6 @@ class ATNewsItem(ATDocumentBase, ATCTImageTransform):
assocFileExt = ('news', )
cmf_edit_kws = ATDocumentBase.cmf_edit_kws

implements(IATNewsItem)

security = ClassSecurityInfo()

@security.protected(View)
Expand Down
4 changes: 2 additions & 2 deletions Products/ATContentTypes/content/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from types import StringType
from types import TupleType
from webdav.Resource import Resource as WebdavResoure
from zope.interface import implements
from zope.interface import implementer
from ZPublisher.HTTPRequest import HTTPRequest


Expand Down Expand Up @@ -144,6 +144,7 @@
finalizeATCTSchema(ATTopicSchema, folderish=False, moveDiscussion=False)


@implementer(IATTopic, IDisabledExport)
class ATTopic(ATCTFolder):
"""An automatically updated stored search.
Expand All @@ -159,7 +160,6 @@ class ATTopic(ATCTFolder):
assocMimetypes = ()
assocFileExt = ()
cmf_edit_kws = ()
implements(IATTopic, IDisabledExport)

# Enable marshalling via WebDAV/FTP
__dav_marshall__ = True
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/criteria/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Products.CMFCore.permissions import View
from zope.interface import classImplementsOnly
from zope.interface import implementedBy
from zope.interface import implements
from zope.interface import implementer


class NonRefCatalogContent(BaseContentMixin):
Expand Down Expand Up @@ -42,13 +42,12 @@ def reindexObject(self, *args, **kwargs): pass
if iface is not IReferenceable))


@implementer(IATTopicCriterion)
class ATBaseCriterion(NonRefCatalogContent):
"""A basic criterion"""

security = ClassSecurityInfo()

implements(IATTopicCriterion)

schema = ATBaseCriterionSchema
meta_type = 'ATBaseCriterion'
archetype_name = 'Base Criterion'
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/criteria/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
from Products.ATContentTypes.permission import ChangeTopics
from Products.CMFCore.permissions import View
from zope.interface import implements
from zope.interface import implementer


ATBooleanCriterionSchema = ATBaseCriterionSchema + Schema((
Expand All @@ -30,11 +30,10 @@
))


@implementer(IATTopicSearchCriterion)
class ATBooleanCriterion(ATBaseCriterion):
"""A boolean criterion"""

implements(IATTopicSearchCriterion)

security = ClassSecurityInfo()
schema = ATBooleanCriterionSchema
meta_type = 'ATBooleanCriterion'
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/criteria/currentauthor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
from Products.CMFCore.permissions import View
from Products.CMFCore.utils import getToolByName
from zope.interface import implements
from zope.interface import implementer


ATCurrentAuthorSchema = ATBaseCriterionSchema


@implementer(IATTopicSearchCriterion)
class ATCurrentAuthorCriterion(ATBaseCriterion):
"""A criterion that searches for the currently logged in user's id"""

implements(IATTopicSearchCriterion)

security = ClassSecurityInfo()
schema = ATCurrentAuthorSchema
meta_type = 'ATCurrentAuthorCriterion'
Expand Down
5 changes: 2 additions & 3 deletions Products/ATContentTypes/criteria/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
from Products.ATContentTypes.permission import ChangeTopics
from Products.CMFCore.permissions import View
from zope.interface import implements
from zope.interface import implementer


DateOptions = IntDisplayList((
Expand Down Expand Up @@ -97,11 +97,10 @@
))


@implementer(IATTopicSearchCriterion)
class ATDateCriteria(ATBaseCriterion):
"""A relative date criterion"""

implements(IATTopicSearchCriterion)

security = ClassSecurityInfo()
schema = ATDateCriteriaSchema
meta_type = 'ATFriendlyDateCriteria'
Expand Down
Loading

0 comments on commit ef7e0cf

Please sign in to comment.