Repository: libcloud Updated Branches: refs/heads/trunk f3792b2dc -> 87878a922
Fix container name encoding in iterate_container_objects and get_container_cdn_url method in the CloudFiles driver. Reported by Brian Metzler part of LIBCLOUD-552. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/87878a92 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/87878a92 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/87878a92 Branch: refs/heads/trunk Commit: 87878a9225ea5b94dba1de6512d21c2b16808bdb Parents: f3792b2 Author: Tomaz Muraus <[email protected]> Authored: Fri May 16 21:25:31 2014 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Fri May 16 21:41:45 2014 +0200 ---------------------------------------------------------------------- CHANGES.rst | 12 ++++++++++++ libcloud/storage/drivers/cloudfiles.py | 11 +++++++---- libcloud/test/storage/test_cloudfiles.py | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/87878a92/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index ca519ad..d5c4120 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -138,6 +138,18 @@ Compute constant. [Tomaz Muraus] +Storage +~~~~~~~ + +- Fix container name encoding in the iterate_container_objects and + get_container_cdn_url method in the CloudFiles driver. Previously, those + methods would throw an exception if user passed in a container name which + contained a whitespace. + + Reported by Brian Metzler. + (LIBCLOUD-552) + [Tomaz MUraus] + Load Balancer ~~~~~~~~~~~~~ http://git-wip-us.apache.org/repos/asf/libcloud/blob/87878a92/libcloud/storage/drivers/cloudfiles.py ---------------------------------------------------------------------- diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py index a828490..52b999f 100644 --- a/libcloud/storage/drivers/cloudfiles.py +++ b/libcloud/storage/drivers/cloudfiles.py @@ -280,8 +280,8 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin): raise LibcloudError('Unexpected status code: %s' % (response.status)) def get_container_cdn_url(self, container): - container_name = container.name - response = self.connection.request('/%s' % (container_name), + container_name_encoded = self._encode_container_name(container.name) + response = self.connection.request('/%s' % (container_name_encoded), method='HEAD', cdn_request=True) @@ -290,7 +290,7 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin): return cdn_url elif response.status == httplib.NOT_FOUND: raise ContainerDoesNotExistError(value='', - container_name=container_name, + container_name=container.name, driver=self) raise LibcloudError('Unexpected status code: %s' % (response.status)) @@ -691,7 +691,10 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin): params['prefix'] = ex_prefix while True: - response = self.connection.request('/%s' % (container.name), + container_name_encoded = \ + self._encode_container_name(container.name) + response = self.connection.request('/%s' % + (container_name_encoded), params=params) if response.status == httplib.NO_CONTENT: http://git-wip-us.apache.org/repos/asf/libcloud/blob/87878a92/libcloud/test/storage/test_cloudfiles.py ---------------------------------------------------------------------- diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py index 2878c1e..84ec615 100644 --- a/libcloud/test/storage/test_cloudfiles.py +++ b/libcloud/test/storage/test_cloudfiles.py @@ -177,6 +177,13 @@ class CloudFilesTests(unittest.TestCase): self.assertEqual(obj.size, 1160520) self.assertEqual(obj.container.name, 'test_container') + def test_list_container_object_name_encoding(self): + CloudFilesMockHttp.type = 'EMPTY' + container = Container(name='test container 1', extra={}, + driver=self.driver) + objects = self.driver.list_container_objects(container=container) + self.assertEqual(len(objects), 0) + def test_list_container_objects_with_prefix(self): CloudFilesMockHttp.type = 'EMPTY' container = Container( @@ -841,6 +848,13 @@ class CloudFilesMockHttp(StorageMockHttp, MockHttpTestCase): self.base_headers, httplib.responses[httplib.OK]) + def _v1_MossoCloudFS_test_20container_201_EMPTY(self, method, url, body, headers): + body = self.fixtures.load('list_container_objects_empty.json') + return (httplib.OK, + body, + self.base_headers, + httplib.responses[httplib.OK]) + def _v1_MossoCloudFS_test_container(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'GET':
