From: Daira Hopwood Date: Fri, 4 Apr 2014 14:38:55 +0000 (+0100) Subject: Refactoring to move ContainerItem and ContainerListing. X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/flags/-?a=commitdiff_plain;h=16827171f8ed27f332aaf87a112f22d7214b2690;p=tahoe-lafs%2Ftahoe-lafs.git Refactoring to move ContainerItem and ContainerListing. Signed-off-by: Daira Hopwood --- 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 3ad7ae90..e2ad2149 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