summaryrefslogtreecommitdiff
path: root/wsgitools/middlewares.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2009-03-29 17:42:48 +0200
committerHelmut Grohne <helmut@subdivi.de>2009-03-29 17:42:48 +0200
commit5c0a3965cdb9cac87d0b0ea773a6276c73a27ba6 (patch)
tree56619fbd0631ae08e01adca15e2994c689dfe8b4 /wsgitools/middlewares.py
parentac99754f5e68f3731b7bdd7c8070c58346983bf4 (diff)
downloadwsgitools-5c0a3965cdb9cac87d0b0ea773a6276c73a27ba6.tar.gz
quite some changes for py3
These changes introduce some compatibility code. They don't make wsgitools usable with Python 3.0, but they also don't break compatibility with Python 2.5.
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r--wsgitools/middlewares.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py
index 297e646..38e2e67 100644
--- a/wsgitools/middlewares.py
+++ b/wsgitools/middlewares.py
@@ -6,9 +6,17 @@ import cgitb
import binascii
from wsgitools.filters import CloseableList, CloseableIterator
try:
- import cStringIO as StringIO
+ import io
except ImportError:
- import StringIO
+ try:
+ import cStringIO as io
+ except ImportError:
+ import StringIO as io
+try:
+ next
+except NameError:
+ def next(it):
+ return it.next()
__all__.append("SubdirMiddleware")
class SubdirMiddleware:
@@ -66,7 +74,7 @@ class NoWriteCallableMiddleware:
todo.append(None)
return start_response(status, headers, exc_info)
else:
- sio = StringIO.StringIO()
+ sio = io.StringIO()
todo.append((status, headers, sio))
return sio.write
@@ -92,7 +100,7 @@ class NoWriteCallableMiddleware:
ret = iter(ret)
stopped = False
try:
- first = ret.next()
+ first = next(ret)
except StopIteration:
stopped = True
@@ -156,7 +164,7 @@ class ContentLengthMiddleware:
data = CloseableList(getattr(ret, "close", None))
length = 0
try:
- data.append(ret.next()) # fills todo
+ data.append(next(ret)) # fills todo
length += len(data[-1])
except StopIteration:
stopped = True
@@ -165,7 +173,7 @@ class ContentLengthMiddleware:
while (not stopped) and length < self.maxstore:
try:
- data.append(ret.next())
+ data.append(next(ret))
length += len(data[-1])
except StopIteration:
stopped = True
@@ -354,7 +362,7 @@ class TracebackMiddleware:
# exception there.
ret = iter(ret)
try:
- first = ret.next()
+ first = next(ret)
except StopIteration:
return CloseableList(getattr(ret, "close", None), [])
return CloseableIterator(getattr(ret, "close", None), [first], ret)