diff options
author | Helmut Grohne <helmut@subdivi.de> | 2007-04-21 20:48:43 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2007-04-21 20:48:43 +0200 |
commit | 5b5b4992ffdc3c3dc3b28c004f211288fb6affcf (patch) | |
tree | 8b2b1ac20aaea7d988ea7189cbf31d8617c66e61 /wsgitools/middlewares.py | |
parent | 5835a547893a7e89ef19e1e4e0b270b78c814a28 (diff) | |
download | wsgitools-5b5b4992ffdc3c3dc3b28c004f211288fb6affcf.tar.gz |
added some assertions
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index 597c584..4020f90 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -17,6 +17,7 @@ class SubdirMiddleware: self.mapping = mapping def __call__(self, environ, start_response): """wsgi interface""" + assert isinstance(environ, dict) app = None script = environ["PATH_INFO"] path_info = "" @@ -45,8 +46,11 @@ class NoWriteCallableMiddleware: self.app = app def __call__(self, environ, start_response): """wsgi interface""" + assert isinstance(environ, dict) todo = [] def modified_start_response(status, headers, exc_info=None): + assert isinstance(status, str) + assert isinstance(headers, list) if exc_info is not None: todo.append(None) return start_response(status, headers, exc_info) @@ -56,6 +60,7 @@ class NoWriteCallableMiddleware: return sio.write ret = self.app(environ, modified_start_response) + assert hasattr(ret, "__iter__") if todo and todo[0] is None: return ret @@ -101,8 +106,11 @@ class ContentLengthMiddleware: self.maxstore = maxstore def __call__(self, environ, start_response): """wsgi interface""" + assert isinstance(environ, dict) todo = [] def modified_start_response(status, headers, exc_info=None): + assert isinstance(status, str) + assert isinstance(headers, list) if (exc_info is not None or [v for h, v in headers if h.lower() == "content-length"]): todo[:] = (None,) @@ -114,6 +122,7 @@ class ContentLengthMiddleware: return raise_not_imp ret = self.app(environ, modified_start_response) + assert hasattr(ret, "__iter__") if todo and todo[0] is None: # nothing to do #print "content-length: nothing" @@ -185,6 +194,7 @@ class CachingMiddleware: self.cache = {} def __call__(self, environ, start_response): """wsgi interface""" + assert isinstance(environ, dict) if not self.storable(environ): return self.app(environ, start_response) path = environ.get("SCRIPT_NAME", "/") @@ -198,6 +208,8 @@ class CachingMiddleware: del self.cache[path] cache_object = [time.time(), "", [], []] def modified_start_respesponse(status, headers, exc_info): + assert isinstance(status, str) + assert isinstance(headers, list) if exc_info is not None: return self.app(status, headers, exc_info) cache_object[1] = status @@ -207,7 +219,10 @@ class CachingMiddleware: cache_object[3].append(data) write(data) return modified_write + ret = self.app(environ, modified_start_respesponse) + assert hasattr(ret, "__iter__") + if isinstance(ret, list): cache_object[3].extend(ret) self.cache[path] = cache_object @@ -244,6 +259,7 @@ class BasicAuthMiddleware: def __call__(self, environ, start_response): """wsgi interface""" + assert isinstance(environ, dict) auth = environ.get("HTTP_AUTHORIZATION") if not auth or ' ' not in auth: return self.authorization_required(environ, start_response) @@ -283,7 +299,10 @@ class TracebackMiddleware: def __call__(self, environ, start_response): """wsgi interface""" try: + assert isinstance(environ, dict) ret = self.app(environ, start_response) + assert hasattr(ret, "__iter__") + if isinstance(ret, list): return ret # Take the first element of the iterator and possibly catch an |