From 6c4f51056c29d520b80a6763fee1687d9191cabe Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Fri, 4 Apr 2014 15:38:55 +0100 Subject: [PATCH] Refactoring to move ContainerItem and ContainerListing. Signed-off-by: Daira Hopwood --- src/allmydata/storage/backends/base.py | 51 +++++++++++++++++++ .../storage/backends/cloud/cloud_common.py | 50 ------------------ .../googlestorage/googlestorage_container.py | 3 +- .../storage/backends/cloud/mock_cloud.py | 4 +- .../cloud/msazure/msazure_container.py | 3 +- .../cloud/openstack/openstack_container.py | 4 +- src/allmydata/test/test_storage.py | 4 +- 7 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/allmydata/storage/backends/base.py b/src/allmydata/storage/backends/base.py index 7513dba7..ff45bc5c 100644 --- a/src/allmydata/storage/backends/base.py +++ b/src/allmydata/storage/backends/base.py @@ -4,6 +4,7 @@ from weakref import WeakValueDictionary from twisted.application import service from twisted.internet import defer +from allmydata.util.assertutil import precondition from allmydata.util.deferredutil import async_iterate, gatherResults from allmydata.storage.common import si_b2a from allmydata.storage.bucket import BucketReader @@ -244,3 +245,53 @@ def empty_check_testv(testv): test_good = False break return test_good + + +# Originally from txaws.s3.model (under different class names), which was under the MIT / Expat licence. + +class ContainerItem(object): + """ + An item in a listing of cloud objects. + """ + def __init__(self, key, modification_date, etag, size, storage_class, + owner=None): + self.key = key + self.modification_date = modification_date + self.etag = etag + self.size = size + self.storage_class = storage_class + self.owner = owner + + def __repr__(self): + return "" % ({ + "key": self.key, + "modification_date": self.modification_date, + "etag": self.etag, + "size": self.size, + "storage_class": self.storage_class, + "owner": self.owner, + },) + + +class ContainerListing(object): + def __init__(self, name, prefix, marker, max_keys, is_truncated, + contents=None, common_prefixes=None): + precondition(isinstance(is_truncated, str)) + self.name = name + self.prefix = prefix + self.marker = marker + self.max_keys = max_keys + self.is_truncated = is_truncated + self.contents = contents + self.common_prefixes = common_prefixes + + def __repr__(self): + return "" % ({ + "name": self.name, + "prefix": self.prefix, + "marker": self.marker, + "max_keys": self.max_keys, + "is_truncated": self.is_truncated, + "contents": self.contents, + "common_prefixes": self.common_prefixes, + }) diff --git a/src/allmydata/storage/backends/cloud/cloud_common.py b/src/allmydata/storage/backends/cloud/cloud_common.py index f07e3814..461ca807 100644 --- a/src/allmydata/storage/backends/cloud/cloud_common.py +++ b/src/allmydata/storage/backends/cloud/cloud_common.py @@ -281,56 +281,6 @@ class CloudServiceError(Error): raise NotImplementedError -# Originally from txaws.s3.model (under different class names), which was under the MIT / Expat licence. - -class ContainerItem(object): - """ - An item in a listing of cloud objects. - """ - def __init__(self, key, modification_date, etag, size, storage_class, - owner=None): - self.key = key - self.modification_date = modification_date - self.etag = etag - self.size = size - self.storage_class = storage_class - self.owner = owner - - def __repr__(self): - return "" % ({ - "key": self.key, - "modification_date": self.modification_date, - "etag": self.etag, - "size": self.size, - "storage_class": self.storage_class, - "owner": self.owner, - },) - - -class ContainerListing(object): - def __init__(self, name, prefix, marker, max_keys, is_truncated, - contents=None, common_prefixes=None): - precondition(isinstance(is_truncated, str)) - self.name = name - self.prefix = prefix - self.marker = marker - self.max_keys = max_keys - self.is_truncated = is_truncated - self.contents = contents - self.common_prefixes = common_prefixes - - def __repr__(self): - return "" % ({ - "name": self.name, - "prefix": self.prefix, - "marker": self.marker, - "max_keys": self.max_keys, - "is_truncated": self.is_truncated, - "contents": self.contents, - "common_prefixes": self.common_prefixes, - }) - - BACKOFF_SECONDS_BEFORE_RETRY = (0, 2, 10) diff --git a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py index 6294f4a3..cc5794df 100644 --- a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py +++ b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py @@ -29,8 +29,9 @@ except ImportError: from zope.interface import implements from allmydata.util import log +from allmydata.storage.backends.base import ContainerItem, ContainerListing from allmydata.storage.backends.cloud.cloud_common import IContainer, \ - ContainerItem, ContainerListing, CommonContainerMixin, HTTPClientMixin + CommonContainerMixin, HTTPClientMixin class AuthenticationClient(object): diff --git a/src/allmydata/storage/backends/cloud/mock_cloud.py b/src/allmydata/storage/backends/cloud/mock_cloud.py index 6894e6cc..dcb6f85c 100644 --- a/src/allmydata/storage/backends/cloud/mock_cloud.py +++ b/src/allmydata/storage/backends/cloud/mock_cloud.py @@ -8,9 +8,9 @@ from allmydata.util.deferredutil import async_iterate from zope.interface import implements from allmydata.util.assertutil import _assert +from allmydata.storage.backends.base import ContainerItem, ContainerListing from allmydata.storage.backends.cloud.cloud_common import IContainer, \ - CloudServiceError, ContainerItem, ContainerListing, \ - CommonContainerMixin, ContainerListMixin + CloudServiceError, CommonContainerMixin, ContainerListMixin from allmydata.util.time_format import iso_utc from allmydata.util import fileutil diff --git a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py index 8b6c987b..fec3d08b 100644 --- a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py +++ b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py @@ -21,8 +21,9 @@ from zope.interface import implements from twisted.web.http_headers import Headers from twisted.web.http import datetimeToString +from allmydata.storage.backends.base import ContainerItem, ContainerListing from allmydata.storage.backends.cloud.cloud_common import IContainer, \ - ContainerItem, ContainerListing, CommonContainerMixin, HTTPClientMixin + CommonContainerMixin, HTTPClientMixin class MSAzureStorageContainer(CommonContainerMixin, HTTPClientMixin): diff --git a/src/allmydata/storage/backends/cloud/openstack/openstack_container.py b/src/allmydata/storage/backends/cloud/openstack/openstack_container.py index 6e8c323b..384accaa 100644 --- a/src/allmydata/storage/backends/cloud/openstack/openstack_container.py +++ b/src/allmydata/storage/backends/cloud/openstack/openstack_container.py @@ -10,9 +10,9 @@ from zope.interface import implements, Interface from allmydata.util import log from allmydata.node import InvalidValueError +from allmydata.storage.backends.base import ContainerItem, ContainerListing from allmydata.storage.backends.cloud.cloud_common import IContainer, \ - CloudServiceError, ContainerItem, ContainerListing, CommonContainerMixin, \ - HTTPClientMixin + CloudServiceError, CommonContainerMixin, HTTPClientMixin # Enabling this will cause secrets to be logged. diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index dc23c73b..dcf026ae 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -22,14 +22,14 @@ from allmydata import interfaces from allmydata.util.assertutil import precondition from allmydata.util import fileutil, hashutil, base32, time_format from allmydata.storage.server import StorageServer +from allmydata.storage.backends.base import ContainerItem, ContainerListing from allmydata.storage.backends.null.null_backend import NullBackend from allmydata.storage.backends.disk.disk_backend import DiskBackend from allmydata.storage.backends.disk.immutable import load_immutable_disk_share, \ create_immutable_disk_share, ImmutableDiskShare from allmydata.storage.backends.disk.mutable import create_mutable_disk_share, MutableDiskShare from allmydata.storage.backends.cloud.cloud_backend import CloudBackend -from allmydata.storage.backends.cloud.cloud_common import CloudError, CloudServiceError, \ - ContainerItem, ContainerListing +from allmydata.storage.backends.cloud.cloud_common import CloudError, CloudServiceError from allmydata.storage.backends.cloud.mutable import MutableCloudShare from allmydata.storage.backends.cloud import mock_cloud, cloud_common from allmydata.storage.backends.cloud.mock_cloud import MockContainer -- 2.45.2