From df02ee8e2a10d2f37a9c013dec157c88b8dce49d Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Sat, 1 Nov 2014 20:49:03 +0000 Subject: Fix Requests breaking download progress bar The move to the requests library (dbb242b) broke the progress bar during downloading an image with --progress enabled, due to requests returning a generator, which has no __len__ function. This patch adds an iterable wrapper which provides the length, sourced from Content-Length headers. Closes-Bug: #1384664 Change-Id: I48598a824396bc6e7cba69eb3ce32e7c8f30a18a --- glanceclient/common/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'glanceclient/common/utils.py') diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index fe7a51a..61c526e 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -421,3 +421,18 @@ def safe_header(name, value): return name, "{SHA1}%s" % d else: return name, value + + +class IterableWithLength(object): + def __init__(self, iterable, length): + self.iterable = iterable + self.length = length + + def __iter__(self): + return self.iterable + + def next(self): + return next(self.iterable) + + def __len__(self): + return self.length -- cgit v1.2.1