summaryrefslogtreecommitdiff
path: root/swiftclient/utils.py
diff options
context:
space:
mode:
authorClay Gerrard <clay.gerrard@gmail.com>2014-02-24 22:41:45 -0800
committerClay Gerrard <clay.gerrard@gmail.com>2014-02-25 01:12:51 -0800
commit3d35a3e989a180b3785b4f259a03c09eed32a14d (patch)
treee479fff74f43d9cc68a32dc253ae7f0296581695 /swiftclient/utils.py
parentf4e057923c8b880b3d25486a72830d938085cd64 (diff)
downloadpython-swiftclient-3d35a3e989a180b3785b4f259a03c09eed32a14d.tar.gz
Add LengthWrapper in put_object to honor content_length param
Closes-Bug:#1284360 Change-Id: Iec63a3fde77bb8195bfe46c764403b367999ff43
Diffstat (limited to 'swiftclient/utils.py')
-rw-r--r--swiftclient/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
index a038dcc..5095f9d 100644
--- a/swiftclient/utils.py
+++ b/swiftclient/utils.py
@@ -55,3 +55,21 @@ def prt_bytes(bytes, human_flag):
bytes = '%12s' % bytes
return(bytes)
+
+
+class LengthWrapper(object):
+
+ def __init__(self, readable, length):
+ self._length = self._remaining = length
+ self._readable = readable
+
+ def __len__(self):
+ return self._length
+
+ def read(self, *args, **kwargs):
+ if self._remaining <= 0:
+ return ''
+ chunk = self._readable.read(
+ *args, **kwargs)[:self._remaining]
+ self._remaining -= len(chunk)
+ return chunk