| OLD | NEW |
| 1 # Copyright 2010 Google Inc. | 1 # Copyright 2010 Google Inc. |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 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 | 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- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return dst_bucket.copy_key(dst_key, self.bucket.name, | 118 return dst_bucket.copy_key(dst_key, self.bucket.name, |
| 119 self.name, metadata) | 119 self.name, metadata) |
| 120 | 120 |
| 121 | 121 |
| 122 class MockBucket(object): | 122 class MockBucket(object): |
| 123 | 123 |
| 124 def __init__(self, connection=None, name=None, key_class=NOT_IMPL): | 124 def __init__(self, connection=None, name=None, key_class=NOT_IMPL): |
| 125 self.name = name | 125 self.name = name |
| 126 self.keys = {} | 126 self.keys = {} |
| 127 self.acls = {name: MockAcl()} | 127 self.acls = {name: MockAcl()} |
| 128 # default object ACLs are one per bucket and not supported for keys |
| 129 self.def_acl = MockAcl() |
| 128 self.subresources = {} | 130 self.subresources = {} |
| 129 self.connection = connection | 131 self.connection = connection |
| 130 self.logging = False | 132 self.logging = False |
| 131 | 133 |
| 132 def copy_key(self, new_key_name, src_bucket_name, | 134 def copy_key(self, new_key_name, src_bucket_name, |
| 133 src_key_name, metadata=NOT_IMPL, src_version_id=NOT_IMPL, | 135 src_key_name, metadata=NOT_IMPL, src_version_id=NOT_IMPL, |
| 134 storage_class=NOT_IMPL, preserve_acl=NOT_IMPL): | 136 storage_class=NOT_IMPL, preserve_acl=NOT_IMPL): |
| 135 new_key = self.new_key(key_name=new_key_name) | 137 new_key = self.new_key(key_name=new_key_name) |
| 136 src_key = mock_connection.get_bucket( | 138 src_key = mock_connection.get_bucket( |
| 137 src_bucket_name).get_key(src_key_name) | 139 src_bucket_name).get_key(src_key_name) |
| 138 new_key.data = copy.copy(src_key.data) | 140 new_key.data = copy.copy(src_key.data) |
| 139 new_key.size = len(new_key.data) | 141 new_key.size = len(new_key.data) |
| 140 return new_key | 142 return new_key |
| 141 | 143 |
| 142 def disable_logging(self): | 144 def disable_logging(self): |
| 143 self.logging = False | 145 self.logging = False |
| 144 | 146 |
| 145 def enable_logging(self, target_bucket_prefix): | 147 def enable_logging(self, target_bucket_prefix): |
| 146 self.logging = True | 148 self.logging = True |
| 147 | 149 |
| 148 def get_acl(self, key_name='', headers=NOT_IMPL, version_id=NOT_IMPL): | 150 def get_acl(self, key_name='', headers=NOT_IMPL, version_id=NOT_IMPL): |
| 149 if key_name: | 151 if key_name: |
| 150 # Return ACL for the key. | 152 # Return ACL for the key. |
| 151 return self.acls[key_name] | 153 return self.acls[key_name] |
| 152 else: | 154 else: |
| 153 # Return ACL for the bucket. | 155 # Return ACL for the bucket. |
| 154 return self.acls[self.name] | 156 return self.acls[self.name] |
| 155 | 157 |
| 158 def get_def_acl(self, key_name=NOT_IMPL, headers=NOT_IMPL, |
| 159 version_id=NOT_IMPL): |
| 160 # Return default ACL for the bucket. |
| 161 return self.def_acl |
| 162 |
| 156 def get_subresource(self, subresource, key_name=NOT_IMPL, headers=NOT_IMPL, | 163 def get_subresource(self, subresource, key_name=NOT_IMPL, headers=NOT_IMPL, |
| 157 version_id=NOT_IMPL): | 164 version_id=NOT_IMPL): |
| 158 if subresource in self.subresources: | 165 if subresource in self.subresources: |
| 159 return self.subresources[subresource] | 166 return self.subresources[subresource] |
| 160 else: | 167 else: |
| 161 return '<Subresource/>' | 168 return '<Subresource/>' |
| 162 | 169 |
| 163 def new_key(self, key_name=None): | 170 def new_key(self, key_name=None): |
| 164 mock_key = MockKey(self, key_name) | 171 mock_key = MockKey(self, key_name) |
| 165 self.keys[key_name] = mock_key | 172 self.keys[key_name] = mock_key |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 version_id=NOT_IMPL): | 205 version_id=NOT_IMPL): |
| 199 # We only handle setting ACL XML here; if you pass a canned ACL | 206 # We only handle setting ACL XML here; if you pass a canned ACL |
| 200 # the get_acl call will just return that string name. | 207 # the get_acl call will just return that string name. |
| 201 if key_name: | 208 if key_name: |
| 202 # Set ACL for the key. | 209 # Set ACL for the key. |
| 203 self.acls[key_name] = acl_or_str | 210 self.acls[key_name] = acl_or_str |
| 204 else: | 211 else: |
| 205 # Set ACL for the bucket. | 212 # Set ACL for the bucket. |
| 206 self.acls[self.name] = acl_or_str | 213 self.acls[self.name] = acl_or_str |
| 207 | 214 |
| 215 def set_def_acl(self, acl_or_str, key_name=NOT_IMPL, headers=NOT_IMPL, |
| 216 version_id=NOT_IMPL): |
| 217 # We only handle setting ACL XML here; if you pass a canned ACL |
| 218 # the get_acl call will just return that string name. |
| 219 # Set default ACL for the bucket. |
| 220 self.def_acl = acl_or_str |
| 221 |
| 208 def set_subresource(self, subresource, value, key_name=NOT_IMPL, | 222 def set_subresource(self, subresource, value, key_name=NOT_IMPL, |
| 209 headers=NOT_IMPL, version_id=NOT_IMPL): | 223 headers=NOT_IMPL, version_id=NOT_IMPL): |
| 210 self.subresources[subresource] = value | 224 self.subresources[subresource] = value |
| 211 | 225 |
| 212 | 226 |
| 213 class MockConnection(object): | 227 class MockConnection(object): |
| 214 | 228 |
| 215 def __init__(self, aws_access_key_id=NOT_IMPL, | 229 def __init__(self, aws_access_key_id=NOT_IMPL, |
| 216 aws_secret_access_key=NOT_IMPL, is_secure=NOT_IMPL, | 230 aws_secret_access_key=NOT_IMPL, is_secure=NOT_IMPL, |
| 217 port=NOT_IMPL, proxy=NOT_IMPL, proxy_port=NOT_IMPL, | 231 port=NOT_IMPL, proxy=NOT_IMPL, proxy_port=NOT_IMPL, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 validate=NOT_IMPL, headers=NOT_IMPL, | 318 validate=NOT_IMPL, headers=NOT_IMPL, |
| 305 version_id=NOT_IMPL): | 319 version_id=NOT_IMPL): |
| 306 self.get_bucket().enable_logging(target_bucket) | 320 self.get_bucket().enable_logging(target_bucket) |
| 307 | 321 |
| 308 def equals(self, uri): | 322 def equals(self, uri): |
| 309 return self.uri == uri.uri | 323 return self.uri == uri.uri |
| 310 | 324 |
| 311 def get_acl(self, validate=NOT_IMPL, headers=NOT_IMPL, version_id=NOT_IMPL): | 325 def get_acl(self, validate=NOT_IMPL, headers=NOT_IMPL, version_id=NOT_IMPL): |
| 312 return self.get_bucket().get_acl(self.object_name) | 326 return self.get_bucket().get_acl(self.object_name) |
| 313 | 327 |
| 328 def get_def_acl(self, validate=NOT_IMPL, headers=NOT_IMPL, |
| 329 version_id=NOT_IMPL): |
| 330 return self.get_bucket().get_def_acl(self.object_name) |
| 331 |
| 314 def get_subresource(self, subresource, validate=NOT_IMPL, headers=NOT_IMPL, | 332 def get_subresource(self, subresource, validate=NOT_IMPL, headers=NOT_IMPL, |
| 315 version_id=NOT_IMPL): | 333 version_id=NOT_IMPL): |
| 316 return self.get_bucket().get_subresource(subresource, self.object_name) | 334 return self.get_bucket().get_subresource(subresource, self.object_name) |
| 317 | 335 |
| 318 def get_all_buckets(self, headers=NOT_IMPL): | 336 def get_all_buckets(self, headers=NOT_IMPL): |
| 319 return self.connect().get_all_buckets() | 337 return self.connect().get_all_buckets() |
| 320 | 338 |
| 321 def get_all_keys(self, validate=NOT_IMPL, headers=NOT_IMPL): | 339 def get_all_keys(self, validate=NOT_IMPL, headers=NOT_IMPL): |
| 322 return self.get_bucket().get_all_keys(self) | 340 return self.get_bucket().get_all_keys(self) |
| 323 | 341 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 341 return self.object_name | 359 return self.object_name |
| 342 | 360 |
| 343 def new_key(self, validate=NOT_IMPL, headers=NOT_IMPL): | 361 def new_key(self, validate=NOT_IMPL, headers=NOT_IMPL): |
| 344 bucket = self.get_bucket() | 362 bucket = self.get_bucket() |
| 345 return bucket.new_key(self.object_name) | 363 return bucket.new_key(self.object_name) |
| 346 | 364 |
| 347 def set_acl(self, acl_or_str, key_name='', validate=NOT_IMPL, | 365 def set_acl(self, acl_or_str, key_name='', validate=NOT_IMPL, |
| 348 headers=NOT_IMPL, version_id=NOT_IMPL): | 366 headers=NOT_IMPL, version_id=NOT_IMPL): |
| 349 self.get_bucket().set_acl(acl_or_str, key_name) | 367 self.get_bucket().set_acl(acl_or_str, key_name) |
| 350 | 368 |
| 369 def set_def_acl(self, acl_or_str, key_name=NOT_IMPL, validate=NOT_IMPL, |
| 370 headers=NOT_IMPL, version_id=NOT_IMPL): |
| 371 self.get_bucket().set_def_acl(acl_or_str) |
| 372 |
| 351 def set_subresource(self, subresource, value, validate=NOT_IMPL, | 373 def set_subresource(self, subresource, value, validate=NOT_IMPL, |
| 352 headers=NOT_IMPL, version_id=NOT_IMPL): | 374 headers=NOT_IMPL, version_id=NOT_IMPL): |
| 353 self.get_bucket().set_subresource(subresource, value, self.object_name) | 375 self.get_bucket().set_subresource(subresource, value, self.object_name) |
| OLD | NEW |