[Checkins] SVN: hurry.query/trunk/ Refresh dependencies and package description. Clean up code.
Dan Korostelev
nadako at gmail.com
Tue Sep 1 18:01:58 EDT 2009
Log message for revision 103474:
Refresh dependencies and package description. Clean up code.
Changed:
U hurry.query/trunk/CHANGES.txt
U hurry.query/trunk/README.txt
UU hurry.query/trunk/setup.py
UU hurry.query/trunk/src/hurry/__init__.py
UU hurry.query/trunk/src/hurry/query/__init__.py
U hurry.query/trunk/src/hurry/query/configure.zcml
UU hurry.query/trunk/src/hurry/query/interfaces.py
UU hurry.query/trunk/src/hurry/query/query.py
U hurry.query/trunk/src/hurry/query/query.txt
UU hurry.query/trunk/src/hurry/query/set.py
UU hurry.query/trunk/src/hurry/query/tests.py
UU hurry.query/trunk/src/hurry/query/value.py
-=-
Modified: hurry.query/trunk/CHANGES.txt
===================================================================
--- hurry.query/trunk/CHANGES.txt 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/CHANGES.txt 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,6 +1,16 @@
-hurry.query changes
-===================
+CHANGES
+=======
+1.0.0 (unreleased)
+------------------
+
+* Refresh dependencies. Use zope.catalog and zope.intid instead of
+ zope.app.catalog and zope.app.intid respectively. Don't zope.app.zapi.
+
+* Make package description more modern.
+
+* Clean up the code style.
+
0.9.3 (2008-09-29)
------------------
Modified: hurry.query/trunk/README.txt
===================================================================
--- hurry.query/trunk/README.txt 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/README.txt 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,4 +1,3 @@
-hurry.query - higher level query system built on top of the Zope 3
- catalog. Some inspiration came from Dieter Maurer's
- AdvancedQuery. See src/hurry/query/query.txt for
- documentation.
+hurry.query - higher level query system built on top of the zope.catalog.
+ Some inspiration came from Dieter Maurer's AdvancedQuery.
+ See src/hurry/query/query.txt for documentation.
Modified: hurry.query/trunk/setup.py
===================================================================
--- hurry.query/trunk/setup.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/setup.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -13,7 +13,7 @@
##############################################################################
"""Setup
-$Id: setup.py 91011 2008-09-09 22:01:02Z malthe $
+$Id$
"""
import os
from setuptools import setup, find_packages
@@ -25,16 +25,15 @@
setup(
name="hurry.query",
- version="0.9.3",
+ version="1.0.0dev",
author='Infrae',
author_email='faassen at startifact.com',
- description="""\
-hurry.query is a higher level query system built on top of the Zope 3
-catalogs. It makes it easy to perform catalog queries in Zope 3 code.
-""",
- long_description=read('src','hurry','query','query.txt'),
+ description="Higher level query system for the zope.catalog",
+ long_description=read('src','hurry','query','query.txt') +
+ '\n\n' +
+ read('CHANGES.txt'),
license='ZPL 2.1',
- keywords="zope zope3 query",
+ keywords="zope zope3 catalog index query",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
@@ -56,6 +55,12 @@
zip_safe=False,
install_requires=[
- 'zc.catalog >= 0.1.1',
- 'setuptools'],
+ 'setuptools',
+ 'zc.catalog',
+ 'ZODB3',
+ 'zope.catalog',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.intid',
+ ],
)
Property changes on: hurry.query/trunk/setup.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/__init__.py
===================================================================
--- hurry.query/trunk/src/hurry/__init__.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/__init__.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,7 +1 @@
-# this is a namespace package
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- import pkgutil
- __path__ = pkgutil.extend_path(__path__, __name__)
+__import__('pkg_resources').declare_namespace(__name__)
Property changes on: hurry.query/trunk/src/hurry/__init__.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/__init__.py
===================================================================
--- hurry.query/trunk/src/hurry/query/__init__.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/__init__.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005-2008 Zope Corporation and Contributors.
+# Copyright (c) 2005-2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -11,5 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
-from query import And, Or, Eq, NotEq, Between, In, Ge, Le, Text
+"""
+$Id$
+"""
+from hurry.query.query import And, Or, Eq, NotEq, Between, In, Ge, Le, Text
Property changes on: hurry.query/trunk/src/hurry/query/__init__.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/configure.zcml
===================================================================
--- hurry.query/trunk/src/hurry/query/configure.zcml 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/configure.zcml 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,9 +1,8 @@
-<configure
- xmlns="http://namespaces.zope.org/zope">
+<configure xmlns="http://namespaces.zope.org/zope">
<utility
- provides=".interfaces.IQuery"
- factory=".query.Query"
- />
+ provides=".interfaces.IQuery"
+ factory=".query.Query"
+ />
</configure>
Modified: hurry.query/trunk/src/hurry/query/interfaces.py
===================================================================
--- hurry.query/trunk/src/hurry/query/interfaces.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/interfaces.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005-2008 Zope Corporation and Contributors.
+# Copyright (c) 2005-2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -11,13 +11,16 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+"""
+$Id$
+"""
from zope.interface import Interface
class IQuery(Interface):
+
def searchResults(query):
"""Query indexes.
Argument is a query composed of terms.
"""
-
Property changes on: hurry.query/trunk/src/hurry/query/interfaces.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/query.py
===================================================================
--- hurry.query/trunk/src/hurry/query/query.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/query.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005-2008 Zope Corporation and Contributors.
+# Copyright (c) 2005-2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -11,18 +11,18 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
+"""
+$Id$
+"""
+from BTrees.IFBTree import weightedIntersection, union, difference, IFBTree
+from zope.catalog.catalog import ResultSet
+from zope.catalog.field import IFieldIndex
+from zope.catalog.interfaces import ICatalog
+from zope.catalog.text import ITextIndex
+from zope.component import getUtility
from zope.interface import implements
+from zope.intid.interfaces import IIntIds
-from zope.app import zapi
-from zope.app.intid.interfaces import IIntIds
-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 BTrees.IFBTree import weightedIntersection, union, difference, IFBTree
-
from hurry.query import interfaces
# XXX look into using multiunion for performance?
@@ -33,11 +33,13 @@
def searchResults(self, query):
results = query.apply()
if results is not None:
- uidutil = zapi.getUtility(IIntIds)
+ uidutil = getUtility(IIntIds)
results = ResultSet(results, uidutil)
return results
+
class Term(object):
+
def __and__(self, other):
return And(self, other)
@@ -53,7 +55,9 @@
def __invert__(self):
return Not(self)
+
class And(Term):
+
def __init__(self, *terms):
self.terms = terms
@@ -78,7 +82,9 @@
_, result = weightedIntersection(result, r)
return result
+
class Or(Term):
+
def __init__(self, *terms):
self.terms = terms
@@ -101,7 +107,9 @@
result = union(result, r)
return result
+
class Not(Term):
+
def __init__(self, term):
self.term = term
@@ -112,23 +120,27 @@
# XXX may not work well/be efficient with extentcatalog
# XXX not very efficient in general, better to use internal
# IntIds datastructure but that would break abstraction..
- intids = zapi.getUtility(IIntIds)
+ intids = getUtility(IIntIds)
result = IFBTree()
for uid in intids:
result.insert(uid, 0)
return result
+
class IndexTerm(Term):
+
def __init__(self, (catalog_name, index_name)):
self.catalog_name = catalog_name
self.index_name = index_name
def getIndex(self):
- catalog = zapi.getUtility(ICatalog, self.catalog_name)
+ catalog = getUtility(ICatalog, self.catalog_name)
index = catalog[self.index_name]
return index
+
class Text(IndexTerm):
+
def __init__(self, index_id, text):
super(Text, self).__init__(index_id)
self.text = text
@@ -142,13 +154,17 @@
index = self.getIndex()
return index.apply(self.text)
+
class FieldTerm(IndexTerm):
+
def getIndex(self):
index = super(FieldTerm, self).getIndex()
assert IFieldIndex.providedBy(index)
return index
+
class Eq(FieldTerm):
+
def __init__(self, index_id, value):
assert value is not None
super(Eq, self).__init__(index_id)
@@ -157,7 +173,9 @@
def apply(self):
return self.getIndex().apply((self.value, self.value))
+
class NotEq(FieldTerm):
+
def __init__(self, index_id, not_value):
super(NotEq, self).__init__(index_id)
self.not_value = not_value
@@ -168,7 +186,9 @@
r = index.apply((self.not_value, self.not_value))
return difference(all, r)
+
class Between(FieldTerm):
+
def __init__(self, index_id, min_value, max_value):
super(Between, self).__init__(index_id)
self.min_value = min_value
@@ -177,15 +197,21 @@
def apply(self):
return self.getIndex().apply((self.min_value, self.max_value))
+
class Ge(Between):
+
def __init__(self, index_id, min_value):
super(Ge, self).__init__(index_id, min_value, None)
+
class Le(Between):
+
def __init__(self, index_id, max_value):
super(Le, self).__init__(index_id, None, max_value)
+
class In(FieldTerm):
+
def __init__(self, index_id, values):
assert None not in values
super(In, self).__init__(index_id)
@@ -209,4 +235,3 @@
for r in results:
result = union(result, r)
return result
-
Property changes on: hurry.query/trunk/src/hurry/query/query.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/query.txt
===================================================================
--- hurry.query/trunk/src/hurry/query/query.txt 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/query.txt 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,11 +1,13 @@
Hurry Query
===========
-The hurry query system for the Zope 3 catalog builds on catalog
-indexes as defined in Zope 3 core, as well as the indexes in
-zc.catalog. It is in part inspired by AdvancedQuery for Zope 2 by
-Dieter Maurer, though has an independent origin.
+The hurry query system for the zope.catalog builds on its catalog
+indexes, as well as the indexes in zc.catalog. It is in part inspired
+by AdvancedQuery for Zope 2 by Dieter Maurer, though has an independent
+origin.
+.. contents::
+
Setup
-----
@@ -22,7 +24,7 @@
And its implementation::
- >>> from zope.app.container.contained import Contained
+ >>> from zope.container.contained import Contained
>>> class Content(Contained):
... implements(IContent)
... def __init__(self, id, f1='', f2='', f3='', f4='', t1='', t2=''):
@@ -44,10 +46,9 @@
the full-blown zope environment::
>>> from zope import interface
- >>> import zope.app.intid.interfaces
- >>> from zope.app.testing import ztapi
+ >>> import zope.intid.interfaces
>>> class DummyIntId(object):
- ... interface.implements(zope.app.intid.interfaces.IIntIds)
+ ... interface.implements(zope.intid.interfaces.IIntIds)
... MARKER = '__dummy_int_id__'
... def __init__(self):
... self.counter = 0
@@ -65,20 +66,20 @@
... def __iter__(self):
... return iter(self.data)
>>> intid = DummyIntId()
- >>> ztapi.provideUtility(
- ... zope.app.intid.interfaces.IIntIds, intid)
+ >>> from zope.component import provideUtility
+ >>> provideUtility(intid, zope.intid.interfaces.IIntIds)
Now let's register a catalog::
- >>> 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()
- >>> ztapi.provideUtility(ICatalog, catalog, 'catalog1')
+ >>> provideUtility(catalog, ICatalog, 'catalog1')
And set it up with various indexes::
- >>> 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
>>> catalog['f1'] = FieldIndex('f1', IContent)
>>> catalog['f2'] = FieldIndex('f2', IContent)
>>> catalog['f3'] = FieldIndex('f3', IContent)
@@ -105,15 +106,15 @@
>>> from hurry.query.query import Query
>>> from hurry.query.interfaces import IQuery
- >>> ztapi.provideUtility(IQuery, Query())
+ >>> provideUtility(Query(), IQuery)
Set up some code to make querying and display the result
easy::
- >>> from zope.app import zapi
+ >>> from zope.component import getUtility
>>> from hurry.query.interfaces import IQuery
>>> def displayQuery(q):
- ... query = zapi.getUtility(IQuery)
+ ... query = getUtility(IQuery)
... r = query.searchResults(q)
... return [e.id for e in sorted(list(r))]
@@ -216,12 +217,11 @@
it::
>>> intid = DummyIntId()
- >>> ztapi.provideUtility(
- ... zope.app.intid.interfaces.IIntIds, intid)
- >>> from zope.app.catalog.interfaces import ICatalog
- >>> from zope.app.catalog.catalog import Catalog
+ >>> provideUtility(intid, zope.intid.interfaces.IIntIds)
+ >>> from zope.catalog.interfaces import ICatalog
+ >>> from zope.catalog.catalog import Catalog
>>> catalog = Catalog()
- >>> ztapi.provideUtility(ICatalog, catalog, 'catalog1')
+ >>> provideUtility(catalog, ICatalog, 'catalog1')
>>> from zc.catalog.catalogindex import SetIndex
>>> catalog['f1'] = SetIndex('f1', IContent)
>>> catalog['f2'] = FieldIndex('f2', IContent)
@@ -281,12 +281,12 @@
``zc.catalog``. Let's make a catalog which uses it:
>>> intid = DummyIntId()
- >>> ztapi.provideUtility(zope.app.intid.interfaces.IIntIds, intid)
+ >>> provideUtility(intid, zope.intid.interfaces.IIntIds)
- >>> 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()
- >>> ztapi.provideUtility(ICatalog, catalog, 'catalog1')
+ >>> provideUtility(catalog, ICatalog, 'catalog1')
>>> from zc.catalog.catalogindex import ValueIndex
>>> catalog['f1'] = ValueIndex('f1', IContent)
Modified: hurry.query/trunk/src/hurry/query/set.py
===================================================================
--- hurry.query/trunk/src/hurry/query/set.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/set.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -1,15 +1,34 @@
-# Copyright (c) 2007 Infrae. All rights reserved.
-# See also LICENSE.txt
+##############################################################################
+#
+# Copyright (c) 2005-2009 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.
+#
+##############################################################################
+"""
+$Id$
+"""
from zc.catalog.interfaces import ISetIndex
+
from hurry.query import query
+
class SetTerm(query.IndexTerm):
+
def getIndex(self):
index = super(SetTerm, self).getIndex()
assert ISetIndex.providedBy(index)
return index
+
class AnyOf(SetTerm):
+
def __init__(self, index_id, values):
super(AnyOf, self).__init__(index_id)
self.values = values
@@ -17,7 +36,9 @@
def apply(self):
return self.getIndex().apply({'any_of': self.values})
+
class AllOf(SetTerm):
+
def __init__(self, index_id, values):
super(AllOf, self).__init__(index_id)
self.values = values
@@ -25,7 +46,9 @@
def apply(self):
return self.getIndex().apply({'all_of': self.values})
+
class SetBetween(SetTerm):
+
def __init__(self, index_id,
minimum=None, maximum=None,
include_minimum=False, include_maximum=False):
@@ -35,9 +58,10 @@
def apply(self):
return self.getIndex().apply({'between': self.tuple})
+
class ExtentAny(SetTerm):
- """Any ids in the extent that are indexed by this index.
- """
+ """Any ids in the extent that are indexed by this index."""
+
def __init__(self, index_id, extent):
super(Any, self).__init__(index_id)
self.extent = extent
@@ -45,9 +69,10 @@
def apply(self):
return self.getIndex().apply({'any': self.extent})
+
class ExtentNone(SetTerm):
- """Any ids in the extent that are not indexed by this index.
- """
+ """Any ids in the extent that are not indexed by this index."""
+
def __init__(self, extent):
super(None, self).__init__(index_id)
self.extent = extent
Property changes on: hurry.query/trunk/src/hurry/query/set.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/tests.py
===================================================================
--- hurry.query/trunk/src/hurry/query/tests.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/tests.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -11,7 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
+"""
+$Id$
+"""
import unittest
from zope.testing import doctest
@@ -19,6 +21,3 @@
return unittest.TestSuite((
doctest.DocFileSuite('query.txt'),
))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Property changes on: hurry.query/trunk/src/hurry/query/tests.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: hurry.query/trunk/src/hurry/query/value.py
===================================================================
--- hurry.query/trunk/src/hurry/query/value.py 2009-09-01 21:35:08 UTC (rev 103473)
+++ hurry.query/trunk/src/hurry/query/value.py 2009-09-01 22:01:57 UTC (rev 103474)
@@ -11,17 +11,24 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+"""
+$Id$
+"""
+from zc.catalog.interfaces import IValueIndex
-from zc.catalog.interfaces import IValueIndex
from hurry.query import query
+
class ValueTerm(query.IndexTerm):
+
def getIndex(self):
index = super(ValueTerm, self).getIndex()
assert IValueIndex.providedBy(index)
return index
+
class Eq(ValueTerm):
+
def __init__(self, index_id, value):
assert value is not None
super(Eq, self).__init__(index_id)
@@ -30,7 +37,9 @@
def apply(self):
return self.getIndex().apply({'any_of': (self.value,)})
+
class NotEq(ValueTerm):
+
def __init__(self, index_id, not_value):
super(NotEq, self).__init__(index_id)
self.not_value = not_value
@@ -48,7 +57,9 @@
pass
return index.apply({'any_of': values})
+
class Between(ValueTerm):
+
def __init__(self, index_id, min_value=None, max_value=None,
exclude_min=False, exclude_max=False):
super(Between, self).__init__(index_id)
@@ -62,15 +73,21 @@
{'between': (self.min_value, self.max_value,
self.exclude_min, self.exclude_max)})
+
class Ge(Between):
+
def __init__(self, index_id, min_value):
super(Ge, self).__init__(index_id, min_value=min_value)
+
class Le(Between):
+
def __init__(self, index_id, max_value):
super(Le, self).__init__(index_id, max_value=max_value)
+
class In(ValueTerm):
+
def __init__(self, index_id, values):
assert None not in values
super(In, self).__init__(index_id)
@@ -79,9 +96,10 @@
def apply(self):
return self.getIndex().apply({'any_of': self.values})
+
class ExtentAny(ValueTerm):
- """Any ids in the extent that are indexed by this index.
- """
+ """Any ids in the extent that are indexed by this index."""
+
def __init__(self, index_id, extent):
super(ExtentAny, self).__init__(index_id)
self.extent = extent
@@ -89,9 +107,10 @@
def apply(self):
return self.getIndex().apply({'any': self.extent})
+
class ExtentNone(ValueTerm):
- """Any ids in the extent that are not indexed by this index.
- """
+ """Any ids in the extent that are not indexed by this index."""
+
def __init__(self, index_id, extent):
super(ExtentNone, self).__init__(index_id)
self.extent = extent
Property changes on: hurry.query/trunk/src/hurry/query/value.py
___________________________________________________________________
Added: svn:keywords
+ Id
More information about the checkins
mailing list