/usr/share/pyshared/zope/index/topic/filter.py is in python-zope.index 3.6.4-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 | ##############################################################################
#
# Copyright (c) 2002 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
#
##############################################################################
"""Filters for TopicIndexes
"""
import BTrees
from zope.index.topic.interfaces import ITopicFilteredSet
from zope.interface import implements
class FilteredSetBase(object):
""" Base class for all filtered sets.
A filtered set is a collection of documents represented
by their document ids that match a common criteria given
by a condition.
"""
implements(ITopicFilteredSet)
family = BTrees.family32
def __init__(self, id, expr, family=None):
if family is not None:
self.family = family
self.id = id
self.expr = expr
self.clear()
def clear(self):
self._ids = self.family.IF.Set()
def index_doc(self, docid, context):
raise NotImplementedError
def unindex_doc(self, docid):
try:
self._ids.remove(docid)
except KeyError:
pass
def getId(self):
return self.id
def getExpression(self):
return self.expr
def setExpression(self, expr):
self.expr = expr
def getIds(self):
return self._ids
def __repr__(self): #pragma NO COVERAGE
return '%s: (%s) %s' % (self.id, self.expr, list(self._ids))
__str__ = __repr__
class PythonFilteredSet(FilteredSetBase):
""" a topic filtered set to check a context against a Python expression """
def index_doc(self, docid, context):
try:
if eval(self.expr):
self._ids.insert(docid)
except:
pass # ignore errors
|