fix the way the s3 driver downloaded streams. Use a similar pattern for raw response cls
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/e09a96b7 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/e09a96b7 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/e09a96b7 Branch: refs/heads/trunk Commit: e09a96b7c8f4bf7c3b9a965ab534f644ff3d0a2a Parents: cd399d9 Author: Anthony Shaw <anthonys...@apache.org> Authored: Sat Jan 7 19:19:38 2017 +1100 Committer: Anthony Shaw <anthonys...@apache.org> Committed: Sat Jan 7 19:19:38 2017 +1100 ---------------------------------------------------------------------- libcloud/common/base.py | 23 +++++++++-------------- libcloud/storage/drivers/s3.py | 3 ++- libcloud/test/storage/test_backblaze_b2.py | 8 ++++++++ libcloud/test/storage/test_cloudfiles.py | 12 +++--------- 4 files changed, 22 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/e09a96b7/libcloud/common/base.py ---------------------------------------------------------------------- diff --git a/libcloud/common/base.py b/libcloud/common/base.py index 180cc11..cb2764d 100644 --- a/libcloud/common/base.py +++ b/libcloud/common/base.py @@ -272,7 +272,7 @@ class XmlResponse(Response): class RawResponse(Response): - def __init__(self, connection): + def __init__(self, connection, response=None): """ :param connection: Parent connection object. :type connection: :class:`.Connection` @@ -283,6 +283,12 @@ class RawResponse(Response): self._error = None self._reason = None self.connection = connection + if response: + self.headers = lowercase_keys(dict(response.headers)) + self.error = response.reason + self.status = response.status_code + self.request = response.request + self.iter_content = response.iter_content def success(self): """ @@ -308,18 +314,6 @@ class RawResponse(Response): return self._response @property - def status(self): - if not self._status: - self._status = self.response.status_code - return self._status - - @property - def headers(self): - if not self._headers: - self._headers = lowercase_keys(dict(self.response.getheaders())) - return self._headers - - @property def reason(self): if not self._reason: self._reason = self.response.reason @@ -660,7 +654,8 @@ class Connection(object): if raw: responseCls = self.rawResponseCls - kwargs = {'connection': self} + kwargs = {'connection': self, + 'response': self.connection.getresponse()} else: responseCls = self.responseCls kwargs = {'connection': self, http://git-wip-us.apache.org/repos/asf/libcloud/blob/e09a96b7/libcloud/storage/drivers/s3.py ---------------------------------------------------------------------- diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py index b0cbd82..59b9021 100644 --- a/libcloud/storage/drivers/s3.py +++ b/libcloud/storage/drivers/s3.py @@ -414,7 +414,8 @@ class BaseS3StorageDriver(StorageDriver): def download_object_as_stream(self, obj, chunk_size=None): obj_path = self._get_object_path(obj.container, obj.name) - response = self.connection.request(obj_path, method='GET', stream=True) + response = self.connection.request(obj_path, method='GET', + stream=True, raw=True) return self._get_object(obj=obj, callback=read_in_chunks, response=response, http://git-wip-us.apache.org/repos/asf/libcloud/blob/e09a96b7/libcloud/test/storage/test_backblaze_b2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/storage/test_backblaze_b2.py b/libcloud/test/storage/test_backblaze_b2.py index d3a9ff4..c537762 100644 --- a/libcloud/test/storage/test_backblaze_b2.py +++ b/libcloud/test/storage/test_backblaze_b2.py @@ -224,6 +224,14 @@ class BackblazeB2MockHttp(StorageMockHttp, MockHttpTestCase): raise AssertionError('Unsupported method') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _file_test00001_2_txt(self, method, url, body, headers): + # test_download_object + if method == 'GET': + body = 'ab' + else: + raise AssertionError('Unsupported method') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + class BackblazeB2MockRawResponse(MockRawResponse): def _file_test00001_2_txt(self, method, url, body, headers): http://git-wip-us.apache.org/repos/asf/libcloud/blob/e09a96b7/libcloud/test/storage/test_cloudfiles.py ---------------------------------------------------------------------- diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py index 1c11a61..eba347f 100644 --- a/libcloud/test/storage/test_cloudfiles.py +++ b/libcloud/test/storage/test_cloudfiles.py @@ -54,10 +54,10 @@ class CloudFilesTests(unittest.TestCase): def setUp(self): self.driver_klass.connectionCls.conn_class = CloudFilesMockHttp - self.driver_klass.connectionCls.rawResponseCls = \ - CloudFilesMockRawResponse + #self.driver_klass.connectionCls.rawResponseCls = \ + # CloudFilesMockRawResponse CloudFilesMockHttp.type = None - CloudFilesMockRawResponse.type = None + #CloudFilesMockRawResponse.type = None driver_kwargs = self.driver_kwargs.copy() driver_kwargs['region'] = self.region @@ -1135,12 +1135,6 @@ class CloudFilesMockHttp(StorageMockHttp, MockHttpTestCase): return (status_code, body, headers, httplib.responses[httplib.OK]) - -class CloudFilesMockRawResponse(MockRawResponse): - - fixtures = StorageFileFixtures('cloudfiles') - base_headers = {'content-type': 'application/json; charset=UTF-8'} - def _v1_MossoCloudFS_py3_img_or_vid(self, method, url, body, headers): headers = {'etag': 'e2378cace8712661ce7beec3d9362ef6'} headers.update(self.base_headers)