Skip to content

Commit

Permalink
Use @implementer class decorator.
Browse files Browse the repository at this point in the history
Also fix test_retrieval in DateRangeIndex/tests.
  • Loading branch information
hannosch committed Sep 13, 2016
1 parent d77ff7f commit 8c7fb9d
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
4.0 (unreleased)
----------------

- Use `@implementer` class decorator.

- Add `__contains__` method to ZCatalogIndexes, fixes zopefoundation/Zope#69.

- Raise BadRequest instead of returning MessageDialog.
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/CompositeIndex/CompositeIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from BTrees.OOBTree import difference
from BTrees.OOBTree import OOSet
from Persistence import PersistentMapping
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import ITransposeQuery
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
Expand Down Expand Up @@ -146,12 +146,12 @@ def __repr__(self):
(self.id, self.meta_type, self.attributes)


@implementer(ITransposeQuery)
class CompositeIndex(KeywordIndex):

"""Index for composition of simple fields.
or sequences of items
"""
implements(ITransposeQuery)

meta_type = "CompositeIndex"

Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/DateIndex/DateIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from DateTime.DateTime import DateTime
from OFS.PropertyManager import PropertyManager
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import IDateIndex
from Products.PluginIndexes.unindex import UnIndex
Expand Down Expand Up @@ -76,10 +76,10 @@ def _isdst(self, dt):
###############################################################################


@implementer(IDateIndex)
class DateIndex(UnIndex, PropertyManager):
"""Index for dates.
"""
implements(IDateIndex)

meta_type = 'DateIndex'
query_options = ('query', 'range', 'not')
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from BTrees.IOBTree import IOBTree
from BTrees.Length import Length
from DateTime.DateTime import DateTime
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import IDateRangeIndex
from Products.PluginIndexes.unindex import UnIndex
Expand All @@ -38,6 +38,7 @@
MAX32 = int(2 ** 31 - 1)


@implementer(IDateRangeIndex)
class DateRangeIndex(UnIndex):

"""Index for date ranges, such as the "effective-expiration" range in CMF.
Expand All @@ -58,7 +59,6 @@ class DateRangeIndex(UnIndex):
- Objects which match only during a specific interval.
"""
implements(IDateRangeIndex)

security = ClassSecurityInfo()

Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/DateRangeIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_retrieval(self):
for value in range(-1, 15):
matches = matchingDummiesByTimeValue(value)
results, used = self._checkApply(index, {'work': value}, matches)
matches = sorted(matches, key=lambda d: d[1].name)
matches = sorted(matches, key=lambda d: d[1].name())

for result, match in map(None, results, matches):
self.assertEqual(index.getEntryForObject(result),
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/PathIndex/PathIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from BTrees.OOBTree import OOBTree
from BTrees.Length import Length
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import (
IPathIndex,
Expand All @@ -38,6 +38,7 @@
LOG = getLogger('Zope.PathIndex')


@implementer(IPathIndex, IQueryIndex, IUniqueValueIndex, ISortIndex)
class PathIndex(Persistent, SimpleItem):

"""Index for paths returned by getPhysicalPath.
Expand All @@ -53,7 +54,6 @@ class PathIndex(Persistent, SimpleItem):
- the value is a mapping 'level of the path component' to
'all docids with this path component on this level'
"""
implements(IPathIndex, IQueryIndex, IUniqueValueIndex, ISortIndex)

meta_type = "PathIndex"

Expand Down
5 changes: 2 additions & 3 deletions src/Products/PluginIndexes/TopicIndex/FilteredSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
from Persistence import Persistent
from RestrictedPython.Eval import RestrictionCapableEval
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import IFilteredSet

LOG = getLogger('Zope.TopicIndex.FilteredSet')


@implementer(IFilteredSet)
class FilteredSetBase(Persistent):
# A pre-calculated result list based on an expression.

implements(IFilteredSet)

def __init__(self, id, expr):
self.id = id
self.expr = expr
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/TopicIndex/TopicIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from BTrees.OOBTree import OOBTree
from OFS.SimpleItem import SimpleItem
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import (
IQueryIndex,
Expand All @@ -33,13 +33,13 @@
LOG = getLogger('Zope.TopicIndex')


@implementer(ITopicIndex, IQueryIndex)
class TopicIndex(Persistent, SimpleItem):
"""A TopicIndex maintains a set of FilteredSet objects.
Every FilteredSet object consists of an expression and and IISet with all
Ids of indexed objects that eval with this expression to 1.
"""
implements(ITopicIndex, IQueryIndex)

meta_type = "TopicIndex"
query_options = ('query', 'operator')
Expand Down
6 changes: 3 additions & 3 deletions src/Products/PluginIndexes/unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from BTrees.OOBTree import OOBTree
from OFS.SimpleItem import SimpleItem
from ZODB.POSException import ConflictError
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.cache import RequestCache
from Products.PluginIndexes.interfaces import (
Expand All @@ -48,11 +48,11 @@
LOG = getLogger('Zope.UnIndex')


@implementer(ILimitedResultIndex, IQueryIndex, IUniqueValueIndex,
ISortIndex, IRequestCacheIndex)
class UnIndex(SimpleItem):
"""Simple forward and reverse index.
"""
implements(ILimitedResultIndex, IQueryIndex, IUniqueValueIndex,
ISortIndex, IRequestCacheIndex)

_counter = None
operators = ('or', 'and')
Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/BaseIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from BTrees.IIBTree import intersection
from BTrees.Length import Length
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex import WidCode
from Products.ZCTextIndex.interfaces import IIndex
Expand Down Expand Up @@ -55,10 +55,9 @@ def unique(l):
return IITreeSet(l).keys()


@implementer(IIndex)
class BaseIndex(Persistent):

implements(IIndex)

def __init__(self, lexicon):
self._lexicon = lexicon

Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/CosineIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import math

from BTrees.IIBTree import IIBucket
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import IIndex
from Products.ZCTextIndex.BaseIndex import BaseIndex
Expand All @@ -26,10 +26,9 @@
from Products.ZCTextIndex.BaseIndex import SCALE_FACTOR


@implementer(IIndex)
class CosineIndex(BaseIndex):

implements(IIndex)

def __init__(self, lexicon):
BaseIndex.__init__(self, lexicon)

Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/HTMLSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
##############################################################################
import re

from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import ISplitter
from Products.ZCTextIndex.PipelineFactory import element_factory


@implementer(ISplitter)
class HTMLWordSplitter(object):

implements(ISplitter)

def process(self, text, wordpat=r"(?L)\w+"):
splat = []
for t in text:
Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/Lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
from BTrees.OIBTree import OIBTree
from BTrees.Length import Length
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import ILexicon
from Products.ZCTextIndex.StopDict import get_stopdict
from Products.ZCTextIndex.ParseTree import QueryError
from Products.ZCTextIndex.PipelineFactory import element_factory


@implementer(ILexicon)
class Lexicon(Persistent):

implements(ILexicon)

_v_nextid = None
_wid_length_based = True # Flag to distinguish new and old lexica

Expand Down
4 changes: 2 additions & 2 deletions src/Products/ZCTextIndex/NBest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"""

from bisect import bisect
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import INBest


@implementer(INBest)
class NBest(object):
implements(INBest)

def __init__(self, n):
"Build an NBest object to remember the N best-scoring objects."
Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/OkapiIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@

from BTrees.IIBTree import IIBucket
from BTrees.Length import Length
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import IIndex
from Products.ZCTextIndex.BaseIndex import BaseIndex
from Products.ZCTextIndex.BaseIndex import inverse_doc_frequency
from Products.ZCTextIndex.BaseIndex import scaled_int


@implementer(IIndex)
class OkapiIndex(BaseIndex):

implements(IIndex)

# BM25 free parameters.
K1 = 1.2
B = 0.75
Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/ParseTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Generic parser support: exception and parse tree nodes."""
from BTrees.IIBTree import difference
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import IQueryParseTree
from Products.ZCTextIndex.SetOps import mass_weightedIntersection
Expand All @@ -29,10 +29,9 @@ class ParseError(Exception):
pass


@implementer(IQueryParseTree)
class ParseTreeNode(object):

implements(IQueryParseTree)

_nodeType = None

def __init__(self, value):
Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/PipelineFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import IPipelineElementFactory


@implementer(IPipelineElementFactory)
class PipelineElementFactory(object):

implements(IPipelineElementFactory)

def __init__(self):
self._groups = {}

Expand Down
5 changes: 2 additions & 3 deletions src/Products/ZCTextIndex/QueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import re
import sys

from zope.interface import implements
from zope.interface import implementer

from Products.ZCTextIndex.interfaces import IQueryParser
from Products.ZCTextIndex import ParseTree
Expand Down Expand Up @@ -118,10 +118,9 @@ def __repr__(self):
_tokenizer_regex.pattern, _tokenizer_regex.flags | re.UNICODE)


@implementer(IQueryParser)
class QueryParser(object):

implements(IQueryParser)

# This class is not thread-safe;
# each thread should have its own instance

Expand Down
7 changes: 3 additions & 4 deletions src/Products/ZCTextIndex/ZCTextIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from App.special_dtml import DTMLFile
from OFS.SimpleItem import SimpleItem
from Persistence import Persistent
from zope.interface import implements
from zope.interface import implementer

from Products.PluginIndexes.interfaces import IPluggableIndex
from Products.PluginIndexes.interfaces import IQueryIndex
Expand All @@ -55,11 +55,11 @@
basestring = str


@implementer(IZCTextIndex, IQueryIndex, IPluggableIndex)
class ZCTextIndex(Persistent, Implicit, SimpleItem):

"""Persistent text index.
"""
implements(IZCTextIndex, IQueryIndex, IPluggableIndex)

meta_type = 'ZCTextIndex'
operators = ('and', 'or')
Expand Down Expand Up @@ -312,13 +312,12 @@ def manage_addLexicon(self, id, title='', elements=[], REQUEST=None):
LexiconMgmtPerm = manage_vocabulary


@implementer(IZCLexicon)
class PLexicon(Lexicon, Implicit, SimpleItem):

"""Lexicon for ZCTextIndex.
"""

implements(IZCLexicon)

meta_type = 'ZCTextIndex Lexicon'

manage_options = ({'label': 'Overview', 'action': 'manage_main'},
Expand Down
Loading

0 comments on commit 8c7fb9d

Please sign in to comment.