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 bucket_lister(bucket, prefix='', delimiter='', marker='', headers=None):
24
A generator function for listing keys in a bucket.
29
rs = bucket.get_all_keys(prefix=prefix, marker=marker,
30
delimiter=delimiter, headers=headers)
35
more_results= rs.is_truncated
37
class BucketListResultSet:
39
A resultset for listing keys within a bucket. Uses the bucket_lister
40
generator function and implements the iterator interface. This
41
transparently handles the results paging from S3 so even if you have
42
many thousands of keys within the bucket you can iterate over all
43
keys in a reasonably efficient manner.
46
def __init__(self, bucket=None, prefix='', delimiter='', marker='', headers=None):
49
self.delimiter = delimiter
51
self.headers = headers
54
return bucket_lister(self.bucket, prefix=self.prefix,
55
delimiter=self.delimiter, marker=self.marker, headers=self.headers)
57
def versioned_bucket_lister(bucket, prefix='', delimiter='',
58
key_marker='', version_id_marker='', headers=None):
60
A generator function for listing versions in a bucket.
65
rs = bucket.get_all_versions(prefix=prefix, key_marker=key_marker,
66
version_id_marker=version_id_marker,
67
delimiter=delimiter, headers=headers)
70
key_marker = rs.key_marker
71
version_id_marker = rs.version_id_marker
72
more_results= rs.is_truncated
74
class VersionedBucketListResultSet:
76
A resultset for listing versions within a bucket. Uses the bucket_lister
77
generator function and implements the iterator interface. This
78
transparently handles the results paging from S3 so even if you have
79
many thousands of keys within the bucket you can iterate over all
80
keys in a reasonably efficient manner.
83
def __init__(self, bucket=None, prefix='', delimiter='', key_marker='',
84
version_id_marker='', headers=None):
87
self.delimiter = delimiter
88
self.key_marker = key_marker
89
self.version_id_marker = version_id_marker
90
self.headers = headers
93
return versioned_bucket_lister(self.bucket, prefix=self.prefix,
94
delimiter=self.delimiter,
95
key_marker=self.key_marker,
96
version_id_marker=self.version_id_marker,