diff options
author | Helmut Grohne <helmut@subdivi.de> | 2012-06-28 22:38:28 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2012-06-28 22:38:28 +0200 |
commit | 7e2e9173b2afcc2a8dca9e6047d0b82ad70c9dff (patch) | |
tree | a44f625d4621348ae14a63f72aad1594cd794ed8 /wsgitools/middlewares.py | |
parent | b83f5682c9d81cd53b8b45a6baedc844a68b85d2 (diff) | |
download | wsgitools-7e2e9173b2afcc2a8dca9e6047d0b82ad70c9dff.tar.gz |
first part of bytes conversion
Convert the request body data from str to bytes. This replaces all
StringIOs with BytesIOs (removing backwards one more backwards
compatibility). Also all character sequences involved in request bodies
get a b"" prefix. The StaticContent application takes bytes instead of
str (no difference for py2x). The GzipWSGIFilter needs a fixed as a
truncate of a BytesIO does not rewind the stream position.
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index dbf2020..e6ede9d 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -5,12 +5,7 @@ import sys import cgitb import binascii import collections -# Cannot use io module as it is broken in 2.6. -# Writing a str to a io.StringIO results in an exception. -try: - import cStringIO as io -except ImportError: - import StringIO as io +import io if sys.version_info[0] >= 3: def exc_info_for_raise(exc_info): @@ -60,7 +55,7 @@ __all__.append("NoWriteCallableMiddleware") 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{StringIO} and then making it be the first result + writing the data to a C{BytesIO} and then making it be the first result element.""" def __init__(self, app): """Wraps wsgi application app.""" @@ -72,7 +67,7 @@ class NoWriteCallableMiddleware: """ assert isinstance(environ, dict) todo = [None] - sio = io.StringIO() + sio = io.BytesIO() gotiterdata = False def write_calleable(data): assert not gotiterdata |