Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Zope2 Interfaces package delenda est\!
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Apr 28, 2008
2 parents b2412f4 + 0fb9696 commit 78cc04d
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 91 deletions.
3 changes: 2 additions & 1 deletion BaseIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import ZODB
from Persistence import Persistent
from zope.interface import implements

# Instead of storing floats, we generally store scaled ints. Binary pickles
# can store those more efficiently. The default SCALE_FACTOR of 1024
Expand All @@ -52,7 +53,7 @@ def unique(L):

class BaseIndex(Persistent):

__implements__ = IIndex
implements(IIndex)

def __init__(self, lexicon):
self._lexicon = lexicon
Expand Down
3 changes: 2 additions & 1 deletion CosineIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import math

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

from Products.ZCTextIndex.IIndex import IIndex
from Products.ZCTextIndex.BaseIndex import BaseIndex, \
Expand All @@ -25,7 +26,7 @@

class CosineIndex(BaseIndex):

__implements__ = IIndex
implements(IIndex)

def __init__(self, lexicon):
BaseIndex.__init__(self, lexicon)
Expand Down
3 changes: 2 additions & 1 deletion HTMLSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

from Products.ZCTextIndex.ISplitter import ISplitter
from Products.ZCTextIndex.PipelineFactory import element_factory
from zope.interface import implements

import re

class HTMLWordSplitter:

__implements__ = ISplitter
implements(ISplitter)

def process(self, text, wordpat=r"(?L)\w+"):
splat = []
Expand Down
4 changes: 2 additions & 2 deletions IIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Index Interface."""

import Interface
from zope.interface import Interface

class IIndex(Interface.Base):
class IIndex(Interface):
"""Interface for an Index."""

def length():
Expand Down
28 changes: 0 additions & 28 deletions ILexicon.py

This file was deleted.

4 changes: 2 additions & 2 deletions INBest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"""


import Interface
from zope.interface import Interface

class INBest(Interface.Base):
class INBest(Interface):
"""Interface for an N-Best chooser."""

def add(item, score):
Expand Down
2 changes: 1 addition & 1 deletion IPipelineElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################

from Interface import Interface
from zope.interface import Interface

class IPipelineElement(Interface):

Expand Down
2 changes: 1 addition & 1 deletion IPipelineElementFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################

from Interface import Interface
from zope.interface import Interface

class IPipelineElementFactory(Interface):
"""Class for creating pipeline elements by name"""
Expand Down
4 changes: 2 additions & 2 deletions IQueryParseTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Query Parser Tree Interface."""

import Interface
from zope.interface import Interface

class IQueryParseTree(Interface.Base):
class IQueryParseTree(Interface):
"""Interface for parse trees returned by parseQuery()."""

def nodeType():
Expand Down
4 changes: 2 additions & 2 deletions IQueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Query Parser Interface."""

import Interface
from zope.interface import Interface

class IQueryParser(Interface.Base):
class IQueryParser(Interface):
"""Interface for Query Parsers."""

def parseQuery(query):
Expand Down
2 changes: 1 addition & 1 deletion ISplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################

from Interface import Interface
from zope.interface import Interface

class ISplitter(Interface):
"""A splitter."""
Expand Down
2 changes: 0 additions & 2 deletions Lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
from Products.ZCTextIndex.StopDict import get_stopdict
from Products.ZCTextIndex.ParseTree import QueryError
from Products.ZCTextIndex.PipelineFactory import element_factory
from ILexicon import ILexicon as z2ILexicon
from interfaces import ILexicon


class Lexicon(Persistent):

__implements__ = z2ILexicon
implements(ILexicon)

def __init__(self, *pipeline):
Expand Down
3 changes: 2 additions & 1 deletion NBest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"""

from bisect import bisect
from zope.interface import implements

from Products.ZCTextIndex.INBest import INBest

class NBest:
__implements__ = INBest
implements(INBest)

def __init__(self, N):
"Build an NBest object to remember the N best-scoring objects."
Expand Down
3 changes: 2 additions & 1 deletion OkapiIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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

from Products.ZCTextIndex.IIndex import IIndex
from Products.ZCTextIndex.BaseIndex import BaseIndex, \
Expand All @@ -28,7 +29,7 @@

class OkapiIndex(BaseIndex):

__implements__ = IIndex
implements(IIndex)

# BM25 free parameters.
K1 = 1.2
Expand Down
3 changes: 2 additions & 1 deletion ParseTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
##############################################################################

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

from BTrees.IIBTree import difference

Expand All @@ -28,7 +29,7 @@ class ParseError(Exception):

class ParseTreeNode:

__implements__ = IQueryParseTree
implements(IQueryParseTree)

_nodeType = None

Expand Down
3 changes: 2 additions & 1 deletion PipelineFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from zope.interface import implements

from Products.ZCTextIndex.IPipelineElementFactory \
import IPipelineElementFactory

class PipelineElementFactory:

__implements__ = IPipelineElementFactory
implements(IPipelineElementFactory)

def __init__(self):
self._groups = {}
Expand Down
3 changes: 2 additions & 1 deletion QueryParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"""

import re
from zope.interface import implements

from Products.ZCTextIndex.IQueryParser import IQueryParser
from Products.ZCTextIndex import ParseTree
Expand Down Expand Up @@ -95,7 +96,7 @@

class QueryParser:

__implements__ = IQueryParser
implements(IQueryParser)

# This class is not thread-safe;
# each thread should have its own instance
Expand Down
11 changes: 2 additions & 9 deletions ZCTextIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from AccessControl.Permissions import manage_zcatalog_indexes, search_zcatalog
from zope.interface import implements

from Products.PluginIndexes.common.PluggableIndex import \
PluggableIndexInterface
from Products.PluginIndexes.common.util import parseIndexRequest
from Products.PluginIndexes.common import safe_callable
from Products.PluginIndexes.interfaces import IPluggableIndex
Expand All @@ -38,7 +36,6 @@
from Products.ZCTextIndex.NBest import NBest
from Products.ZCTextIndex.QueryParser import QueryParser
from CosineIndex import CosineIndex
from ILexicon import ILexicon as z2ILexicon
from interfaces import ILexicon
from interfaces import IZCLexicon
from interfaces import IZCTextIndex
Expand All @@ -54,8 +51,6 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):

"""Persistent text index.
"""

__implements__ = PluggableIndexInterface
implements(IZCTextIndex, IPluggableIndex)

## Magic class attributes ##
Expand Down Expand Up @@ -89,8 +84,7 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,
if lexicon is None:
raise LookupError, 'Lexicon "%s" not found' % escape(lexicon_id)

if not (ILexicon.providedBy(lexicon) or
z2ILexicon.isImplementedBy(lexicon)):
if not ILexicon.providedBy(lexicon):
raise ValueError('Object "%s" does not implement '
'ZCTextIndex Lexicon interface'
% lexicon.getId())
Expand Down Expand Up @@ -135,8 +129,7 @@ def getLexicon(self):
return self._v_lexicon
except AttributeError:
lexicon = getattr(aq_parent(aq_inner(self)), self.lexicon_id)
if not (ILexicon.providedBy(lexicon) or
z2ILexicon.isImplementedBy(lexicon)):
if not ILexicon.providedBy(lexicon):
raise TypeError('Object "%s" is not a ZCTextIndex Lexicon'
% repr(lexicon))
self._v_lexicon = lexicon
Expand Down
6 changes: 0 additions & 6 deletions tests/testLexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ def process(self, seq):

class Test(unittest.TestCase):

def test_z2interfaces(self):
from Interface.Verify import verifyClass
from Products.ZCTextIndex.ILexicon import ILexicon

verifyClass(ILexicon, Lexicon)

def test_z3interfaces(self):
from Products.ZCTextIndex.interfaces import ILexicon
from zope.interface.verify import verifyClass
Expand Down
59 changes: 59 additions & 0 deletions tests/testParseTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##############################################################################
#
# Copyright (c) 2008 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

import unittest

class ParseTreeTests(unittest.TestCase):

def _conforms(self, klass):
from zope.interface.verify import verifyClass
from Products.ZCTextIndex.IQueryParseTree import IQueryParseTree
verifyClass(IQueryParseTree, klass)

def test_ParseTreeNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import ParseTreeNode
self._conforms(ParseTreeNode)

def test_OrNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import OrNode
self._conforms(OrNode)

def test_AndNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import AndNode
self._conforms(AndNode)

def test_NotNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import NotNode
self._conforms(NotNode)

def test_GlobNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import GlobNode
self._conforms(GlobNode)

def test_AtomNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import AtomNode
self._conforms(AtomNode)

def test_PhraseNode_conforms_to_IQueryParseTree(self):
from Products.ZCTextIndex.ParseTree import PhraseNode
self._conforms(PhraseNode)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ParseTreeTests),
))

if __name__=="__main__":
unittest.main(defaultTest='test_suite')
3 changes: 2 additions & 1 deletion tests/testPipelineFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
from unittest import TestCase, TestSuite, main, makeSuite
from Products.ZCTextIndex.IPipelineElement import IPipelineElement
from Products.ZCTextIndex.PipelineFactory import PipelineElementFactory
from zope.interface import implements

class NullPipelineElement:

__implements__ = IPipelineElement
implements(IPipelineElement)

def process(source):
pass
Expand Down
Loading

0 comments on commit 78cc04d

Please sign in to comment.