/usr/share/pyshared/hurry/query/value.py is in python-hurry.query 1.1.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | ##############################################################################
#
# Copyright (c) 2005-2008 Zope Foundation 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.
#
##############################################################################
"""Query terms for zc.catalog's ValueIndex
$Id: value.py 112992 2010-06-03 08:22:48Z janwijbrand $
"""
from zc.catalog.interfaces import IValueIndex
from hurry.query import query
class ValueTerm(query.IndexTerm):
def getIndex(self, context):
index = super(ValueTerm, self).getIndex(context)
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)
self.value = value
def apply(self, context=None):
return self.getIndex(context).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
def apply(self, context=None):
index = self.getIndex(context)
values = list(index.values())
# the remove method produces a value error when the value to
# be removed is not in the list in the first place. Having a
# try/except clause is more efficent than first searching the
# list for the value to remove.
try:
values.remove(self.not_value)
except ValueError:
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)
self.min_value = min_value
self.max_value = max_value
self.exclude_min = exclude_min
self.exclude_max = exclude_max
def apply(self, context=None):
return self.getIndex(context).apply(
{'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)
self.values = values
def apply(self, context=None):
return self.getIndex(context).apply({'any_of': self.values})
class ExtentAny(ValueTerm):
"""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
def apply(self, context=None):
return self.getIndex(context).apply({'any': self.extent})
class ExtentNone(ValueTerm):
"""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
def apply(self, context=None):
return self.getIndex(context).apply({'none': self.extent})
|