catalog: Python3 fixes (+ some fixes in relation)
This commit is contained in:
parent
ad632e23ee
commit
c5fe028756
6 changed files with 38 additions and 96 deletions
|
@ -16,12 +16,12 @@ for testing purposes here) and a catalog with a few indexes.
|
|||
>>> intid = IntIdsStub()
|
||||
>>> component.provideUtility(intid)
|
||||
|
||||
>>> from zope.app.catalog.interfaces import ICatalog
|
||||
>>> from zope.app.catalog.catalog import Catalog
|
||||
>>> from zope.catalog.interfaces import ICatalog
|
||||
>>> from zope.catalog.catalog import Catalog
|
||||
>>> catalog = Catalog()
|
||||
>>> component.provideUtility(catalog, ICatalog)
|
||||
|
||||
>>> from zope.interface import Interface, Attribute, implements
|
||||
>>> from zope.interface import Interface, Attribute, implementer
|
||||
>>> class IContent(Interface):
|
||||
... f1 = Attribute('f1')
|
||||
... f2 = Attribute('f2')
|
||||
|
@ -30,8 +30,8 @@ for testing purposes here) and a catalog with a few indexes.
|
|||
... t2 = Attribute('t2')
|
||||
... k1 = Attribute('k1')
|
||||
|
||||
>>> from zope.app.catalog.field import FieldIndex
|
||||
>>> from zope.app.catalog.text import TextIndex
|
||||
>>> from zope.catalog.field import FieldIndex
|
||||
>>> from zope.catalog.text import TextIndex
|
||||
>>> from cybertools.catalog.keyword import KeywordIndex
|
||||
>>> catalog['f1'] = FieldIndex('f1', IContent)
|
||||
>>> catalog['f2'] = FieldIndex('f2', IContent)
|
||||
|
@ -45,7 +45,6 @@ to index and query.
|
|||
|
||||
>>> from zope.app.container.contained import Contained
|
||||
>>> class Content(Contained):
|
||||
... implements(IContent)
|
||||
... def __init__(self, id, f1='', f2='', f3='', t1='', t2='', k1=[]):
|
||||
... self.id = id
|
||||
... self.f1 = f1
|
||||
|
@ -56,6 +55,7 @@ to index and query.
|
|||
... self.k1 = k1
|
||||
... def __cmp__(self, other):
|
||||
... return cmp(self.id, other.id)
|
||||
>>> Content = implementer(IContent)(Content)
|
||||
|
||||
The id attribute is just so we can identify objects we find again
|
||||
easily. By including the __cmp__ method we make sure search results
|
||||
|
|
|
@ -1,43 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# cybertools.catalog.keyword
|
||||
|
||||
"""Keyword catalog index.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import zope.index.keyword
|
||||
import zope.interface
|
||||
|
||||
import zope.app.container.contained
|
||||
import zope.app.catalog.attribute
|
||||
import zope.app.catalog.interfaces
|
||||
import zope.catalog.attribute
|
||||
import zope.catalog.interfaces
|
||||
|
||||
|
||||
class IKeywordIndex(zope.app.catalog.interfaces.IAttributeIndex,
|
||||
zope.app.catalog.interfaces.ICatalogIndex):
|
||||
class IKeywordIndex(zope.catalog.interfaces.IAttributeIndex,
|
||||
zope.catalog.interfaces.ICatalogIndex):
|
||||
"""Interface-based catalog keyword index.
|
||||
"""
|
||||
|
||||
|
||||
class KeywordIndex(zope.app.catalog.attribute.AttributeIndex,
|
||||
@zope.interface.implementer(IKeywordIndex)
|
||||
class KeywordIndex(zope.catalog.attribute.AttributeIndex,
|
||||
zope.index.keyword.KeywordIndex,
|
||||
zope.app.container.contained.Contained):
|
||||
|
||||
zope.interface.implements(IKeywordIndex)
|
||||
|
||||
pass
|
||||
|
|
|
@ -1,37 +1,18 @@
|
|||
#
|
||||
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# cybertools.catalog.query
|
||||
|
||||
"""
|
||||
Catalog query terms and their logical combinations.
|
||||
""" Catalog query terms and their logical combinations.
|
||||
|
||||
This is mainly a simplified version of Martijn Faassen's hurry.query
|
||||
(http://cheeseshop.python.org/pypi/hurry.query).
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from BTrees.IFBTree import weightedIntersection, weightedUnion
|
||||
from BTrees.IFBTree import difference, IFBTree, IFBucket, IFSet
|
||||
from BTrees.IIBTree import IISet, union
|
||||
from zope.app.catalog.catalog import ResultSet
|
||||
from zope.app.catalog.field import IFieldIndex
|
||||
from zope.app.catalog.text import ITextIndex
|
||||
from zope.app.catalog.interfaces import ICatalog
|
||||
from zope.catalog.catalog import ResultSet
|
||||
from zope.catalog.field import IFieldIndex
|
||||
from zope.catalog.text import ITextIndex
|
||||
from zope.catalog.interfaces import ICatalog
|
||||
from zope import component
|
||||
from zope.intid.interfaces import IIntIds
|
||||
|
||||
|
@ -72,7 +53,7 @@ class And(Term):
|
|||
if not results:
|
||||
# no applicable terms at all
|
||||
return IFBucket()
|
||||
results.sort()
|
||||
#results.sort()
|
||||
_, result = results.pop(0)
|
||||
for _, r in results:
|
||||
w, result = weightedIntersection(result, r)
|
||||
|
@ -122,9 +103,8 @@ class Not(Term):
|
|||
|
||||
class IndexTerm(Term):
|
||||
|
||||
def __init__(self, (catalog_name, index_name)):
|
||||
self.catalog_name = catalog_name
|
||||
self.index_name = index_name
|
||||
def __init__(self, index_id):
|
||||
self.catalog_name, self.index_name = index_id
|
||||
|
||||
def getIndex(self):
|
||||
catalog = component.getUtility(ICatalog, self.catalog_name)
|
||||
|
|
|
@ -1,38 +1,19 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
# -*- Mode: Python; py-indent-offset: 4 -*-
|
||||
#
|
||||
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# cybertools.relation
|
||||
|
||||
"""
|
||||
The relation package provides all you need for setting up dyadic and
|
||||
""" The relation package provides all you need for setting up dyadic and
|
||||
triadic relations.
|
||||
"""
|
||||
|
||||
from persistent import Persistent
|
||||
from zope.interface import implements
|
||||
from interfaces import IPredicate
|
||||
from interfaces import IRelation, IDyadicRelation, ITriadicRelation
|
||||
from interfaces import IRelatable
|
||||
from zope.interface import implementer
|
||||
from cybertools.relation.interfaces import IPredicate
|
||||
from cybertools.relation.interfaces import IRelation, IDyadicRelation, ITriadicRelation
|
||||
from cybertools.relation.interfaces import IRelatable
|
||||
|
||||
|
||||
@implementer(IPredicate, IRelation)
|
||||
class Relation(Persistent):
|
||||
|
||||
implements(IPredicate, IRelation)
|
||||
|
||||
order = 0
|
||||
relevance = 1.0
|
||||
fallback = None
|
||||
|
@ -55,20 +36,18 @@ class Relation(Persistent):
|
|||
'must provide the IRelatable interface.')
|
||||
|
||||
|
||||
@implementer(IDyadicRelation)
|
||||
class DyadicRelation(Relation):
|
||||
|
||||
implements(IDyadicRelation)
|
||||
|
||||
def __init__(self, first, second):
|
||||
self.first = first
|
||||
self.second = second
|
||||
self.checkRelatable(first, second)
|
||||
|
||||
|
||||
@implementer(ITriadicRelation)
|
||||
class TriadicRelation(Relation):
|
||||
|
||||
implements(ITriadicRelation)
|
||||
|
||||
def __init__(self, first, second, third):
|
||||
self.first = first
|
||||
self.second = second
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# $Id$
|
||||
# cybertools.relation.tests
|
||||
|
||||
import unittest, doctest
|
||||
from zope.app.testing import ztapi
|
||||
from zope.interface.verify import verifyClass
|
||||
from zope.interface import implements
|
||||
from zope.interface import implementer
|
||||
from zope.intid.interfaces import IIntIds
|
||||
|
||||
from cybertools.relation.interfaces import IDyadicRelation, ITriadicRelation
|
||||
|
@ -12,9 +12,9 @@ from cybertools.relation import Relation, DyadicRelation, TriadicRelation
|
|||
from cybertools.relation.interfaces import IRelationRegistry
|
||||
|
||||
|
||||
@implementer(IIntIds)
|
||||
class IntIdsStub(object):
|
||||
"""A testing stub (mock utility) for IntIds."""
|
||||
implements(IIntIds)
|
||||
|
||||
def __init__(self):
|
||||
self.objs = []
|
||||
|
@ -35,7 +35,7 @@ class IntIdsStub(object):
|
|||
self.objs[id] = None
|
||||
|
||||
def __iter__(self):
|
||||
return iter(xrange(len(self.objs)))
|
||||
return iter(range(len(self.objs)))
|
||||
|
||||
|
||||
class TestRelation(unittest.TestCase):
|
||||
|
|
|
@ -21,6 +21,7 @@ dependencies = [
|
|||
"zope.app.testing",
|
||||
"zope.authentication",
|
||||
"zope.browserpage",
|
||||
"zope.catalog",
|
||||
"zope.component",
|
||||
"zope.container",
|
||||
"zope.i18nmessageid",
|
||||
|
|
Loading…
Add table
Reference in a new issue