From 668e8991889cbb5068bb636e5bdfe2200431e4da Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 5 Aug 2018 22:54:53 +0000 Subject: [PATCH] Handle StopIteration for Py3.7 Catch the raise of StopIteration with return. PEP 0479, https://www.python.org/dev/peps/pep-0479/, makes the following change: "when StopIteration is raised inside a generator, it is replaced it with RuntimeError". And states: "If raise StopIteration occurs directly in a generator, simply replace it with return." Closes-Bug: #1785309 Change-Id: Ib751b680b7357782cb5359526e1e83ee8c5c80dd --- zunclient/common/httpclient.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zunclient/common/httpclient.py b/zunclient/common/httpclient.py index f4802ff8..5f89439e 100644 --- a/zunclient/common/httpclient.py +++ b/zunclient/common/httpclient.py @@ -395,7 +395,10 @@ class ResponseBodyIterator(object): def __iter__(self): while True: - yield self.next() + try: + yield self.next() + except StopIteration: + return def next(self): chunk = self.resp.read(CHUNKSIZE)