1
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
def query_lister(domain, query='', max_items=None, attr_names=None):
27
rs = domain.connection.query_with_attributes(domain, query, attr_names,
28
next_token=next_token)
31
if num_results == max_items:
35
next_token = rs.next_token
36
more_results = next_token != None
40
def __init__(self, domain=None, query='', max_items=None, attr_names=None):
41
self.max_items = max_items
44
self.attr_names = attr_names
47
return query_lister(self.domain, self.query, self.max_items, self.attr_names)
49
def select_lister(domain, query='', max_items=None):
54
rs = domain.connection.select(domain, query, next_token=next_token)
57
if num_results == max_items:
61
next_token = rs.next_token
62
more_results = next_token != None
64
class SelectResultSet(object):
66
def __init__(self, domain=None, query='', max_items=None,
67
next_token=None, consistent_read=False):
70
self.consistent_read = consistent_read
71
self.max_items = max_items
72
self.next_token = next_token
78
rs = self.domain.connection.select(self.domain, self.query,
79
next_token=self.next_token,
80
consistent_read=self.consistent_read)
82
if self.max_items and num_results >= self.max_items:
86
self.next_token = rs.next_token
87
if self.max_items and num_results >= self.max_items:
89
more_results = self.next_token != None
92
return self.__iter__().next()