diff options
author | Helmut Grohne <helmut@subdivi.de> | 2008-07-12 15:00:14 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2008-07-12 15:00:14 +0200 |
commit | 3519854edbc2a1abb82e719306a074bddb8b18a7 (patch) | |
tree | ad5b6283793e7790cbdfea569d959da5925eef3f /wsgitools/middlewares.py | |
parent | 6be7a46a36c06f80e10565b74dbf0f44a6f4656a (diff) | |
download | wsgitools-3519854edbc2a1abb82e719306a074bddb8b18a7.tar.gz |
refactor middlewares.NoWriteCallableMiddleware
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index 201634b..eb7b913 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -71,15 +71,20 @@ class NoWriteCallableMiddleware: ret = self.app(environ, modified_start_response) assert hasattr(ret, "__iter__") + assert len(todo) == 1 - if todo and todo[0] is None: + if todo[0] is None: + return ret + + status, headers, data = todo[0] + data = data.getvalue() + + if not data: + start_response(status, headers) return ret if isinstance(ret, list): - status, headers, data = todo[0] - data = data.getvalue() - if data: - ret.insert(0, data) + ret.insert(0, data) start_response(status, headers) return ret @@ -90,8 +95,6 @@ class NoWriteCallableMiddleware: except StopIteration: stopped = True - status, headers, data = todo[0] - data = data.getvalue() start_response(status, headers) if stopped: |