/usr/share/pyshared/kiwi/db/query.py is in python-kiwi 1.9.22-2.
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #
# Kiwi: a Framework and Enhanced Widgets for Python
#
# Copyright (C) 2007 Async Open Source
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# Author(s): Johan Dahlin <jdahlin@async.com.br>
#
from kiwi.interfaces import ISearchFilter
#
# Query building
#
class QueryState(object):
def __init__(self, search_filter):
"""
Create a new QueryState object.
@param search_filter: search filter this query state is associated with
@type search_filter: L{SearchFilter}
"""
self.filter = search_filter
class NumberQueryState(QueryState):
"""
Create a new NumberQueryState object.
@cvar value: number
"""
def __init__(self, filter, value):
QueryState.__init__(self, filter)
self.value = value
def __repr__(self):
return '<NumberQueryState value=%r>' % (self.value,)
class StringQueryState(QueryState):
"""
Create a new StringQueryState object.
@cvar text: string
"""
def __init__(self, filter, text):
QueryState.__init__(self, filter)
self.text = text
def __repr__(self):
return '<StringQueryState text=%r>' % (self.text,)
class DateQueryState(QueryState):
"""
Create a new DateQueryState object.
@cvar date: date
"""
def __init__(self, filter, date):
QueryState.__init__(self, filter)
self.date = date
def __repr__(self):
return '<DateQueryState date=%r>' % (self.date,)
class DateIntervalQueryState(QueryState):
"""
Create a new DateIntervalQueryState object.
@cvar start: start of interval
@cvar end: end of interval
"""
def __init__(self, filter, start, end):
QueryState.__init__(self, filter)
self.start = start
self.end = end
def __repr__(self):
return '<DateIntervalQueryState start=%r, end=%r>' % (
self.start, self.end)
class QueryExecuter(object):
"""
A QueryExecuter is responsible for taking the state (as in QueryState)
objects from search filters and construct a query.
How the query is constructed is ORM/DB-layer dependent.
@cvar default_search_limit: The default search limit.
"""
default_search_limit = 1000
def __init__(self):
self._columns = {}
self._limit = self.default_search_limit
#
# Public API
#
def set_filter_columns(self, search_filter, columns):
if not ISearchFilter.providedBy(search_filter):
pass
#raise TypeError("search_filter must implement ISearchFilter")
assert not search_filter in self._columns
self._columns[search_filter] = columns
#
# Overridable
#
def search(self, states):
"""
Execute a search.
@param states:
@type states: list of L{QueryStates}
@returns: list of objects matching query
"""
raise NotImplementedError
def set_limit(self, limit):
"""
Set the maximum number of result items to return in a search query.
@param limit:
"""
self._limit = limit
def get_limit(self):
return self._limit
|