Use zope.interface decorator

This not only makes code more pleasent to read,
but also makes the code python 3 compatible
(while maintaining python 2 compatibility).
This commit is contained in:
Gil Forcada 2016-07-05 23:12:08 +02:00
parent 3619419df4
commit d5e7afcd23
8 changed files with 19 additions and 25 deletions

View File

@ -14,7 +14,8 @@ New features:
Bug fixes:
- *add item here*
- Use zope.interface decorator.
[gforcada]
2.4.16 (2016-06-27)

View File

@ -18,10 +18,10 @@ from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
@interface.implementer(ICaptcha)
class Captcha(Persistent):
"""Captcha input field.
"""
interface.implements(ICaptcha)
adapts(Comment)
captcha = u""

View File

@ -6,13 +6,14 @@ into an actual comment object.
from plone.app.discussion.interfaces import IConversation
from zope.component import adapts
from zope.component import queryAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.traversing.interfaces import ITraversable
from zope.traversing.interfaces import TraversalError
@implementer(ITraversable)
class ConversationNamespace(object):
"""Allow traversal into a conversation via a ++conversation++name
namespace. The name is the name of an adapter from context to
@ -20,8 +21,6 @@ class ConversationNamespace(object):
(unnamed) adapter. This is to work around a bug in OFS.Traversable which
does not allow traversal to namespaces with an empty string name.
"""
implements(ITraversable)
adapts(Interface, IBrowserRequest)
def __init__(self, context, request=None):

View File

@ -11,7 +11,7 @@ from z3c.form.interfaces import IValidator
from zope.component import adapts
from zope.component import getMultiAdapter
from zope.component import queryUtility
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
from zope.schema.interfaces import IField
@ -32,8 +32,8 @@ except ImportError:
pass
@implementer(IValidator)
class CaptchaValidator(validator.SimpleFieldValidator):
implements(IValidator)
adapts(Interface, IDiscussionLayer, Interface, IField, Interface)
# Object, Request, Form, Field, Widget,
# We adapt the CaptchaValidator class to all form fields (IField)

View File

@ -35,7 +35,7 @@ from zope.component.factory import Factory
from zope.event import notify
from zope.i18n import translate
from zope.i18nmessageid import Message
from zope.interface import implements
from zope.interface import implementer
import logging
@ -65,6 +65,7 @@ MAIL_NOTIFICATION_MESSAGE_MODERATOR = _(
logger = logging.getLogger('plone.app.discussion')
@implementer(IComment)
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
RoleManager, Owned, Implicit, Persistent):
"""A comment.
@ -73,8 +74,6 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
number of standard methods instead of subclassing, to have total control
over what goes into the object.
"""
implements(IComment)
security = ClassSecurityInfo()
meta_type = portal_type = 'Discussion Item'

View File

@ -34,7 +34,6 @@ from zope.component import adapts
from zope.container.contained import ContainerModifiedEvent
from zope.event import notify
from zope.interface import implementer
from zope.interface import implements
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectCreatedEvent
from zope.lifecycleevent import ObjectRemovedEvent
@ -42,6 +41,7 @@ from zope.lifecycleevent import ObjectRemovedEvent
import time
@implementer(IConversation, IHideFromBreadcrumbs)
class Conversation(Traversable, Persistent, Explicit):
"""A conversation is a container for all comments on a content object.
@ -49,8 +49,6 @@ class Conversation(Traversable, Persistent, Explicit):
comment lookup.
"""
implements(IConversation, IHideFromBreadcrumbs)
__allow_access_to_unprotected_subobjects__ = True
def __init__(self, id='++conversation++default'):
@ -327,13 +325,12 @@ else:
return conversationAdapterFactory(content)
@implementer(IReplies)
class ConversationReplies(object):
"""An IReplies adapter for conversations.
This makes it easy to work with top-level comments.
"""
implements(IReplies)
adapts(Conversation) # relies on implementation details
def __init__(self, context):
@ -404,14 +401,13 @@ class ConversationReplies(object):
return self.conversation._children.get(self.comment_id, LLSet())
@implementer(IReplies)
class CommentReplies(ConversationReplies):
"""An IReplies adapter for comments.
This makes it easy to work with replies to specific comments.
"""
implements(IReplies)
# depends on implementation details of conversation
# most likely, anyone writing a different type of Conversation will also
# have a different type of Comment

View File

@ -6,13 +6,13 @@ from plone.app.discussion.interfaces import ICommentRemovedEvent
from plone.app.discussion.interfaces import IDiscussionEvent
from plone.app.discussion.interfaces import IReplyAddedEvent
from plone.app.discussion.interfaces import IReplyRemovedEvent
from zope.interface import implements
from zope.interface import implementer
@implementer(IDiscussionEvent)
class DiscussionEvent(object):
""" Custom event
"""
implements(IDiscussionEvent)
def __init__(self, context, comment, **kwargs):
self.object = context
@ -26,25 +26,25 @@ class DiscussionEvent(object):
request.set('event', self)
@implementer(ICommentAddedEvent)
class CommentAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is added
"""
implements(ICommentAddedEvent)
@implementer(ICommentRemovedEvent)
class CommentRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is removed
"""
implements(ICommentRemovedEvent)
@implementer(IReplyAddedEvent)
class ReplyAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is added
"""
implements(IReplyAddedEvent)
@implementer(IReplyRemovedEvent)
class ReplyRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is removed
"""
implements(IReplyRemovedEvent)

View File

@ -14,10 +14,9 @@ from zope import interface
from zope.component import queryUtility
@interface.implementer(ICommentingTool)
class CommentingTool(UniqueObject, SimpleItem):
interface.implements(ICommentingTool)
meta_type = 'plone.app.discussion tool'
id = 'portal_discussion'