diff --git a/swiftclient/service.py b/swiftclient/service.py index 326a041..eb36818 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -305,13 +305,14 @@ class _SwiftReader(object): errors on failures caused by either invalid md5sum or size of the data read. """ - def __init__(self, path, body, headers): + def __init__(self, path, body, headers, out_file): self._path = path self._body = body self._actual_read = 0 self._content_length = None self._actual_md5 = None self._expected_etag = headers.get('etag') + self._out_file = out_file if ('x-object-manifest' not in headers and 'x-static-large-object' not in headers): @@ -327,6 +328,9 @@ class _SwiftReader(object): return self def __exit__(self, exc_type, exc_val, exc_tb): + if self._out_file == "-": + return + if self._actual_md5 and self._expected_etag: etag = self._actual_md5.hexdigest() if etag != self._expected_etag: @@ -341,6 +345,10 @@ class _SwiftReader(object): self._path, self._actual_read, self._content_length)) + def __iter__(self): + for chunk in self.buffer(): + yield chunk + def buffer(self): for chunk in self._body: if self._actual_md5: @@ -1014,7 +1022,7 @@ class SwiftService(object): response_dict=results_dict) headers_receipt = time() - reader = _SwiftReader(path, body, headers) + reader = _SwiftReader(path, body, headers, out_file) with reader as obj_body: fp = None try: