Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/s3/bucketlistresultset.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | |
2 # | |
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- | |
9 # lowing conditions: | |
10 # | |
11 # The above copyright notice and this permission notice shall be included | |
12 # in all copies or substantial portions of the Software. | |
13 # | |
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 | |
20 # IN THE SOFTWARE. | |
21 | |
22 from boto.compat import unquote_str | |
23 | |
24 def bucket_lister(bucket, prefix='', delimiter='', marker='', headers=None, | |
25 encoding_type=None): | |
26 """ | |
27 A generator function for listing keys in a bucket. | |
28 """ | |
29 more_results = True | |
30 k = None | |
31 while more_results: | |
32 rs = bucket.get_all_keys(prefix=prefix, marker=marker, | |
33 delimiter=delimiter, headers=headers, | |
34 encoding_type=encoding_type) | |
35 for k in rs: | |
36 yield k | |
37 if k: | |
38 marker = rs.next_marker or k.name | |
39 if marker and encoding_type == "url": | |
40 marker = unquote_str(marker) | |
41 more_results= rs.is_truncated | |
42 | |
43 class BucketListResultSet(object): | |
44 """ | |
45 A resultset for listing keys within a bucket. Uses the bucket_lister | |
46 generator function and implements the iterator interface. This | |
47 transparently handles the results paging from S3 so even if you have | |
48 many thousands of keys within the bucket you can iterate over all | |
49 keys in a reasonably efficient manner. | |
50 """ | |
51 | |
52 def __init__(self, bucket=None, prefix='', delimiter='', marker='', | |
53 headers=None, encoding_type=None): | |
54 self.bucket = bucket | |
55 self.prefix = prefix | |
56 self.delimiter = delimiter | |
57 self.marker = marker | |
58 self.headers = headers | |
59 self.encoding_type = encoding_type | |
60 | |
61 def __iter__(self): | |
62 return bucket_lister(self.bucket, prefix=self.prefix, | |
63 delimiter=self.delimiter, marker=self.marker, | |
64 headers=self.headers, | |
65 encoding_type=self.encoding_type) | |
66 | |
67 def versioned_bucket_lister(bucket, prefix='', delimiter='', | |
68 key_marker='', version_id_marker='', headers=None, | |
69 encoding_type=None): | |
70 """ | |
71 A generator function for listing versions in a bucket. | |
72 """ | |
73 more_results = True | |
74 k = None | |
75 while more_results: | |
76 rs = bucket.get_all_versions(prefix=prefix, key_marker=key_marker, | |
77 version_id_marker=version_id_marker, | |
78 delimiter=delimiter, headers=headers, | |
79 max_keys=999, encoding_type=encoding_type) | |
80 for k in rs: | |
81 yield k | |
82 key_marker = rs.next_key_marker | |
83 if key_marker and encoding_type == "url": | |
84 key_marker = unquote_str(key_marker) | |
85 version_id_marker = rs.next_version_id_marker | |
86 more_results= rs.is_truncated | |
87 | |
88 class VersionedBucketListResultSet(object): | |
89 """ | |
90 A resultset for listing versions within a bucket. Uses the bucket_lister | |
91 generator function and implements the iterator interface. This | |
92 transparently handles the results paging from S3 so even if you have | |
93 many thousands of keys within the bucket you can iterate over all | |
94 keys in a reasonably efficient manner. | |
95 """ | |
96 | |
97 def __init__(self, bucket=None, prefix='', delimiter='', key_marker='', | |
98 version_id_marker='', headers=None, encoding_type=None): | |
99 self.bucket = bucket | |
100 self.prefix = prefix | |
101 self.delimiter = delimiter | |
102 self.key_marker = key_marker | |
103 self.version_id_marker = version_id_marker | |
104 self.headers = headers | |
105 self.encoding_type = encoding_type | |
106 | |
107 def __iter__(self): | |
108 return versioned_bucket_lister(self.bucket, prefix=self.prefix, | |
109 delimiter=self.delimiter, | |
110 key_marker=self.key_marker, | |
111 version_id_marker=self.version_id_marker, | |
112 headers=self.headers, | |
113 encoding_type=self.encoding_type) | |
114 | |
115 def multipart_upload_lister(bucket, key_marker='', | |
116 upload_id_marker='', | |
117 headers=None, encoding_type=None): | |
118 """ | |
119 A generator function for listing multipart uploads in a bucket. | |
120 """ | |
121 more_results = True | |
122 k = None | |
123 while more_results: | |
124 rs = bucket.get_all_multipart_uploads(key_marker=key_marker, | |
125 upload_id_marker=upload_id_marker, | |
126 headers=headers, | |
127 encoding_type=encoding_type) | |
128 for k in rs: | |
129 yield k | |
130 key_marker = rs.next_key_marker | |
131 if key_marker and encoding_type == "url": | |
132 key_marker = unquote_str(key_marker) | |
133 upload_id_marker = rs.next_upload_id_marker | |
134 more_results= rs.is_truncated | |
135 | |
136 class MultiPartUploadListResultSet(object): | |
137 """ | |
138 A resultset for listing multipart uploads within a bucket. | |
139 Uses the multipart_upload_lister generator function and | |
140 implements the iterator interface. This | |
141 transparently handles the results paging from S3 so even if you have | |
142 many thousands of uploads within the bucket you can iterate over all | |
143 keys in a reasonably efficient manner. | |
144 """ | |
145 def __init__(self, bucket=None, key_marker='', | |
146 upload_id_marker='', headers=None, encoding_type=None): | |
147 self.bucket = bucket | |
148 self.key_marker = key_marker | |
149 self.upload_id_marker = upload_id_marker | |
150 self.headers = headers | |
151 self.encoding_type = encoding_type | |
152 | |
153 def __iter__(self): | |
154 return multipart_upload_lister(self.bucket, | |
155 key_marker=self.key_marker, | |
156 upload_id_marker=self.upload_id_marker, | |
157 headers=self.headers, | |
158 encoding_type=self.encoding_type) |