From 125fbbbff45bf4e3902127ef0f88e979153e5f85 Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Tue, 5 Jul 2016 23:13:15 +0200 Subject: [PATCH 1/2] 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). --- CHANGES.rst | 3 ++- .../indexmodifiers/query_index_modifiers.py | 8 +++----- plone/app/querystring/tests/index_testmodifier.py | 11 ++++------- plone/app/querystring/tests/testQueryParser.py | 5 +++-- plone/app/querystring/tests/testRegistryReader.py | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 795abf2..fb3545b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,8 @@ New features: Bug fixes: -- *add item here* +- Use zope.interface decorator. + [gforcada] 1.3.15 (2016-05-25) diff --git a/plone/app/querystring/indexmodifiers/query_index_modifiers.py b/plone/app/querystring/indexmodifiers/query_index_modifiers.py index bc03efb..d0fcf1d 100644 --- a/plone/app/querystring/indexmodifiers/query_index_modifiers.py +++ b/plone/app/querystring/indexmodifiers/query_index_modifiers.py @@ -1,9 +1,10 @@ # -*- coding: utf8 -*- from dateutil.parser import parse from plone.app.querystring.interfaces import IParsedQueryIndexModifier -from zope.interface import implements +from zope.interface import implementer +@implementer(IParsedQueryIndexModifier) class Subject(object): """ @@ -17,8 +18,6 @@ class Subject(object): be removed. """ - implements(IParsedQueryIndexModifier) - def __call__(self, value): query = value['query'] # query can be a unicode string or a list of unicode strings. @@ -42,6 +41,7 @@ def __call__(self, value): return ('Subject', value) +@implementer(IParsedQueryIndexModifier) class base(object): """ @@ -49,8 +49,6 @@ class base(object): see Products.PluginIndexes.DateIndex.DateIndex.DateIndex._convert function """ - implements(IParsedQueryIndexModifier) - def __call__(self, value): query = value['query'] if isinstance(query, unicode): diff --git a/plone/app/querystring/tests/index_testmodifier.py b/plone/app/querystring/tests/index_testmodifier.py index daa87fe..a36c267 100644 --- a/plone/app/querystring/tests/index_testmodifier.py +++ b/plone/app/querystring/tests/index_testmodifier.py @@ -1,35 +1,32 @@ # -*- coding: utf8 -*- -from zope.interface import implements +from zope.interface import implementer from plone.app.querystring.interfaces import IParsedQueryIndexModifier +@implementer(IParsedQueryIndexModifier) class SimpleFooIndexModifier(object): """Test simple index modifier that do nothing""" - implements(IParsedQueryIndexModifier) - def __call__(self, value): raise Exception("SimpleFooIndexModifier has been called!") +@implementer(IParsedQueryIndexModifier) class TitleFooIndexModifier(object): """Test index modifier that check always Foo""" - implements(IParsedQueryIndexModifier) - def __call__(self, value): return ('Title', 'Foo') +@implementer(IParsedQueryIndexModifier) class AbstractToDescriptionIndexModifier(object): """ Test index modifier that translate "Abstract" to Description index but where value do not count letter "e" """ - implements(IParsedQueryIndexModifier) - def __call__(self, value): value['query'] = value['query'].replace('e', '') return ('Description', value) diff --git a/plone/app/querystring/tests/testQueryParser.py b/plone/app/querystring/tests/testQueryParser.py index 809bf49..d11cbae 100644 --- a/plone/app/querystring/tests/testQueryParser.py +++ b/plone/app/querystring/tests/testQueryParser.py @@ -74,8 +74,8 @@ class MockSiteProperties(object): navtree_properties = MockNavtreeProperties() +@implementer(INavigationRoot, IPloneSiteRoot) class MockSite(object): - implements(INavigationRoot, IPloneSiteRoot) def __init__(self, portal_membership=None): self.reference_catalog = MockCatalog() @@ -88,8 +88,9 @@ def getPhysicalPath(self): return ["", MOCK_SITE_ID] +@implementer(INavigationRoot) class MockNavRoot(MockObject): - implements(INavigationRoot) + pass class MockUser(object): diff --git a/plone/app/querystring/tests/testRegistryReader.py b/plone/app/querystring/tests/testRegistryReader.py index 6db9597..e0f7ba0 100644 --- a/plone/app/querystring/tests/testRegistryReader.py +++ b/plone/app/querystring/tests/testRegistryReader.py @@ -1,7 +1,7 @@ from plone.registry.interfaces import IRegistry from plone.registry import Registry from zope.component import getGlobalSiteManager -from zope.interface import implements +from zope.interface import implementer from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleVocabulary @@ -14,8 +14,8 @@ import unittest2 as unittest +@implementer(IVocabularyFactory) class TestVocabulary(object): - implements(IVocabularyFactory) def __call__(self, context): return SimpleVocabulary([ From 9d09353a3b76762f1d447a90cecedee3c55df9ca Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Mon, 25 Jul 2016 13:55:08 +0200 Subject: [PATCH 2/2] one more implements -> implementer --- plone/app/querystring/tests/testQueryParser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plone/app/querystring/tests/testQueryParser.py b/plone/app/querystring/tests/testQueryParser.py index d11cbae..bf05871 100644 --- a/plone/app/querystring/tests/testQueryParser.py +++ b/plone/app/querystring/tests/testQueryParser.py @@ -12,7 +12,7 @@ NOT_INSTALLED_PLONEAPPQUERYSTRING_INTEGRATION_TESTING from zope.component import getGlobalSiteManager -from zope.interface.declarations import implements +from zope.interface import implementer import unittest2 as unittest