summaryrefslogtreecommitdiff
path: root/wsgitools/middlewares.py
diff options
context:
space:
mode:
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r--wsgitools/middlewares.py28
1 files changed, 10 insertions, 18 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py
index 32ecb59..ef9fe84 100644
--- a/wsgitools/middlewares.py
+++ b/wsgitools/middlewares.py
@@ -8,20 +8,12 @@ import collections
import io
from wsgitools.internal import bytes2str, str2bytes
-
-if sys.version_info[0] >= 3:
- def exc_info_for_raise(exc_info):
- return exc_info[1].with_traceback(exc_info[2])
-else:
- def exc_info_for_raise(exc_info):
- return exc_info[0], exc_info[1], exc_info[2]
-
from wsgitools.filters import CloseableList, CloseableIterator
from wsgitools.authentication import AuthenticationRequired, \
ProtocolViolation, AuthenticationMiddleware
__all__.append("SubdirMiddleware")
-class SubdirMiddleware(object):
+class SubdirMiddleware:
"""Middleware choosing wsgi applications based on a dict."""
def __init__(self, default, mapping={}):
"""
@@ -54,7 +46,7 @@ class SubdirMiddleware(object):
return app(environ, start_response)
__all__.append("NoWriteCallableMiddleware")
-class NoWriteCallableMiddleware(object):
+class NoWriteCallableMiddleware:
"""This middleware wraps a wsgi application that needs the return value of
C{start_response} function to a wsgi application that doesn't need one by
writing the data to a C{BytesIO} and then making it be the first result
@@ -78,7 +70,7 @@ class NoWriteCallableMiddleware(object):
try:
if sio.tell() > 0 or gotiterdata:
assert exc_info is not None
- raise exc_info_for_raise(exc_info)
+ raise exc_info[1].with_traceback(exc_info[2])
finally:
exc_info = None
assert isinstance(status, str)
@@ -121,7 +113,7 @@ class NoWriteCallableMiddleware(object):
(data,), ret)
__all__.append("ContentLengthMiddleware")
-class ContentLengthMiddleware(object):
+class ContentLengthMiddleware:
"""Guesses the content length header if possible.
@note: The application used must not use the C{write} callable returned by
C{start_response}."""
@@ -149,7 +141,7 @@ class ContentLengthMiddleware(object):
try:
if gotdata:
assert exc_info is not None
- raise exc_info_for_raise(exc_info)
+ raise exc_info[1].with_traceback(exc_info[2])
finally:
exc_info = None
assert isinstance(status, str)
@@ -216,11 +208,11 @@ def cacheable(environ):
return True
__all__.append("CachingMiddleware")
-class CachingMiddleware(object):
+class CachingMiddleware:
"""Caches reponses to requests based on C{SCRIPT_NAME}, C{PATH_INFO} and
C{QUERY_STRING}."""
- class CachedRequest(object):
+ class CachedRequest:
def __init__(self, timestamp):
self.timestamp = timestamp
self.status = ""
@@ -291,7 +283,7 @@ class CachingMiddleware(object):
try:
if cache_object.body:
assert exc_info is not None
- raise exc_info_for_raise(exc_info)
+ raise exc_info[1].with_traceback(exc_info[2])
finally:
exc_info = None
assert isinstance(status, str)
@@ -319,7 +311,7 @@ class CachingMiddleware(object):
return CloseableIterator(getattr(ret, "close", None), pass_through())
__all__.append("DictAuthChecker")
-class DictAuthChecker(object):
+class DictAuthChecker:
"""Verifies usernames and passwords by looking them up in a dict."""
def __init__(self, users):
"""
@@ -390,7 +382,7 @@ class BasicAuthMiddleware(AuthenticationMiddleware):
self, environ, start_response, exception)
__all__.append("TracebackMiddleware")
-class TracebackMiddleware(object):
+class TracebackMiddleware:
"""In case the application throws an exception this middleware will show an
html-formatted traceback using C{cgitb}."""
def __init__(self, app):