summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2008-07-12 15:00:14 +0200
committerHelmut Grohne <helmut@subdivi.de>2008-07-12 15:00:14 +0200
commit3519854edbc2a1abb82e719306a074bddb8b18a7 (patch)
treead5b6283793e7790cbdfea569d959da5925eef3f
parent6be7a46a36c06f80e10565b74dbf0f44a6f4656a (diff)
downloadwsgitools-3519854edbc2a1abb82e719306a074bddb8b18a7.tar.gz
refactor middlewares.NoWriteCallableMiddleware
-rw-r--r--wsgitools/middlewares.py17
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: