summaryrefslogtreecommitdiff
path: root/wsgitools
diff options
context:
space:
mode:
Diffstat (limited to 'wsgitools')
-rw-r--r--wsgitools/applications.py6
-rw-r--r--wsgitools/authentication.py4
-rw-r--r--wsgitools/filters.py21
-rw-r--r--wsgitools/middlewares.py11
-rw-r--r--wsgitools/scgi/asynchronous.py9
5 files changed, 18 insertions, 33 deletions
diff --git a/wsgitools/applications.py b/wsgitools/applications.py
index 8a02fe8..cdaf0ae 100644
--- a/wsgitools/applications.py
+++ b/wsgitools/applications.py
@@ -21,7 +21,7 @@ class StaticContent:
@type headers: list
@param headers: is a list of C{(header, value)} pairs being delivered as
HTTP headers
- @type content: basestring
+ @type content: bytes
@param content: contains the data to be delivered to the client. It is
either a string or some kind of iterable yielding strings.
@type anymethod: boolean
@@ -30,12 +30,12 @@ class StaticContent:
"""
assert isinstance(status, str)
assert isinstance(headers, list)
- assert isinstance(content, basestring) or hasattr(content, "__iter__")
+ assert isinstance(content, bytes) or hasattr(content, "__iter__")
self.status = status
self.headers = headers
self.anymethod = anymethod
length = -1
- if isinstance(content, basestring):
+ if isinstance(content, bytes):
self.content = [content]
length = len(content)
else:
diff --git a/wsgitools/authentication.py b/wsgitools/authentication.py
index 963dc00..c076d7f 100644
--- a/wsgitools/authentication.py
+++ b/wsgitools/authentication.py
@@ -97,8 +97,8 @@ class AuthenticationMiddleware:
@param exception: reason for the authentication failure
"""
status = "401 Authorization required"
- html = "<html><head><title>401 Authorization required</title></head>" \
- "<body><h1>401 Authorization required</h1></body></html>"
+ html = b"<html><head><title>401 Authorization required</title></head>" \
+ b"<body><h1>401 Authorization required</h1></body></html>"
headers = [("Content-Type", "text/html"),
self.www_authenticate(exception),
("Content-Length", str(len(html)))]
diff --git a/wsgitools/filters.py b/wsgitools/filters.py
index 4305c9d..6f90903 100644
--- a/wsgitools/filters.py
+++ b/wsgitools/filters.py
@@ -10,13 +10,7 @@ __all__ = []
import sys
import time
import gzip
-# 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
__all__.append("CloseableIterator")
class CloseableIterator:
@@ -397,7 +391,7 @@ class GzipWSGIFilter(BaseWSGIFilter):
acceptenc = map(str.strip, acceptenc)
if "gzip" in acceptenc:
self.compress = True
- self.sio = io.StringIO()
+ self.sio = io.BytesIO()
self.gzip = gzip.GzipFile(fileobj=self.sio, mode="w")
return environ
def filter_header(self, headername, headervalue):
@@ -431,6 +425,7 @@ class GzipWSGIFilter(BaseWSGIFilter):
self.gzip.flush()
data = self.sio.getvalue()
self.sio.truncate(0)
+ self.sio.seek(0)
return data
def append_data(self):
"""BaseWSGIFilter interface
@@ -446,7 +441,7 @@ class ReusableWSGIInputFilter(BaseWSGIFilter):
"""Make C{environ["wsgi.input"]} readable multiple times. Although this is
not required by the standard it is sometimes desirable to read C{wsgi.input}
multiple times. This filter will therefore replace that variable with a
- C{StringIO} instance which provides a C{seek} method.
+ C{BytesIO} instance which provides a C{seek} method.
"""
@classmethod
def creator(cls, maxrequestsize):
@@ -457,14 +452,14 @@ class ReusableWSGIInputFilter(BaseWSGIFilter):
adapter to eat this data.)
@type maxrequestsize: int
@param maxrequestsize: is the maximum number of bytes to store in the
- C{StringIO}
+ C{BytesIO}
"""
return lambda:cls(maxrequestsize)
def __init__(self, maxrequestsize=65536):
"""ReusableWSGIInputFilters constructor.
@type maxrequestsize: int
@param maxrequestsize: is the maximum number of bytes to store in the
- C{StringIO}, see L{creator}
+ C{BytesIO}, see L{creator}
"""
BaseWSGIFilter.__init__(self)
self.maxrequestsize = maxrequestsize
@@ -474,12 +469,12 @@ class ReusableWSGIInputFilter(BaseWSGIFilter):
@type environ: {str: str}
"""
- if isinstance(environ["wsgi.input"], io.StringIO):
+ if isinstance(environ["wsgi.input"], io.BytesIO):
return environ # nothing to be done
# XXX: is this really a good idea? use with care
environ["wsgitools.oldinput"] = environ["wsgi.input"]
- data = io.StringIO(environ["wsgi.input"].read(self.maxrequestsize))
+ data = io.BytesIO(environ["wsgi.input"].read(self.maxrequestsize))
environ["wsgi.input"] = data
return environ
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
diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py
index 1dee283..7eb1a30 100644
--- a/wsgitools/scgi/asynchronous.py
+++ b/wsgitools/scgi/asynchronous.py
@@ -1,14 +1,9 @@
__all__ = []
import asyncore
+import io
import socket
import sys
-# 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 errno
from wsgitools.scgi import _convert_environ, FileWrapper
@@ -48,7 +43,7 @@ class SCGIConnection(asyncore.dispatcher):
self.wsgiiterator = None # wsgi application iterator
self.outheaders = () # headers to be sent
# () -> unset, (..,..) -> set, True -> sent
- self.body = io.StringIO() # request body
+ self.body = io.BytesIO() # request body
def _try_send_headers(self):
if self.outheaders != True: