From bda3adc0789cb4ee999246708edc7f7a977e79b8 Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Wed, 7 Aug 2013 16:15:34 +0200 Subject: [PATCH] utils: Group the exceptions in yield_or_abort. Additionally, the empty yield is rather unnecessary. --- puppetboard/utils.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/puppetboard/utils.py b/puppetboard/utils.py index 9ae5a8b..8390ceb 100644 --- a/puppetboard/utils.py +++ b/puppetboard/utils.py @@ -40,22 +40,13 @@ def yield_or_stop(generator): generators and handle certain errors. Since this is also used in streaming responses where we can't just abort - a request we always yield empty and then raise StopIteration. + a request we raise StopIteration. """ while True: try: yield next(generator) except StopIteration: raise - except ExperimentalDisabledError: - yield - raise StopIteration - except EmptyResponseError: - yield - raise StopIteration - except ConnectionError: - yield - raise StopIteration - except HTTPError: - yield + except (ExperimentalDisabledError, EmptyResponseError, + ConnectionError, HTTPError): raise StopIteration