changeset 83:32cc618c009a

Actually, environ keys and values must be strings.
author Allan Saddi <allan@saddi.com>
date Thu, 04 Dec 2008 13:47:17 -0800
parents 189e7ca3fbe2
children 71ddbf14ae2b
files flup/server/ajp.py flup/server/ajp_base.py
diffstat 2 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/flup/server/ajp.py	Thu Dec 04 13:37:09 2008 -0800
     1.2 +++ b/flup/server/ajp.py	Thu Dec 04 13:47:17 2008 -0800
     1.3 @@ -100,7 +100,7 @@
     1.4      Of course you will need an AJP1.3 connector for your webserver (e.g.
     1.5      mod_jk) - see <http://jakarta.apache.org/tomcat/connectors-doc/>.
     1.6      """
     1.7 -    def __init__(self, application, scriptName=b'', environ=None,
     1.8 +    def __init__(self, application, scriptName='', environ=None,
     1.9                   multithreaded=True, multiprocess=False,
    1.10                   bindAddress=('localhost', 8009), allowedServers=None,
    1.11                   loggingLevel=logging.INFO, debug=True, **kw):
     2.1 --- a/flup/server/ajp_base.py	Thu Dec 04 13:37:09 2008 -0800
     2.2 +++ b/flup/server/ajp_base.py	Thu Dec 04 13:47:17 2008 -0800
     2.3 @@ -390,7 +390,7 @@
     2.4                  self._buf += b''.join(self._bufList)
     2.5                  self._bufList = []
     2.6              # Find newline.
     2.7 -            i = self._buf.find('\n', self._pos)
     2.8 +            i = self._buf.find(b'\n', self._pos)
     2.9              if i < 0:
    2.10                  # Not found?
    2.11                  if not self.bytesAvailForAdd():
    2.12 @@ -445,6 +445,7 @@
    2.13          the server for data beyond the Content-Length, so the server should
    2.14          never send us an EOF (empty string argument).
    2.15          """
    2.16 +        assert type(data) is bytes
    2.17          if not data:
    2.18              raise ProtocolError('short data')
    2.19          self._bufList.append(data)
    2.20 @@ -508,25 +509,25 @@
    2.21      # Request.
    2.22  
    2.23      def setMethod(self, value):
    2.24 -        self.environ['REQUEST_METHOD'] = value
    2.25 +        self.environ['REQUEST_METHOD'] = value.decode('latin-1')
    2.26  
    2.27      def setProtocol(self, value):
    2.28 -        self.environ['SERVER_PROTOCOL'] = value
    2.29 +        self.environ['SERVER_PROTOCOL'] = value.decode('latin-1')
    2.30  
    2.31      def setRequestURI(self, value):
    2.32 -        self.environ['REQUEST_URI'] = value
    2.33 +        self.environ['REQUEST_URI'] = value.decode('latin-1')
    2.34  
    2.35      def setRemoteAddr(self, value):
    2.36 -        self.environ['REMOTE_ADDR'] = value
    2.37 +        self.environ['REMOTE_ADDR'] = value.decode('latin-1')
    2.38  
    2.39      def setRemoteHost(self, value):
    2.40 -        self.environ['REMOTE_HOST'] = value
    2.41 +        self.environ['REMOTE_HOST'] = value.decode('latin-1')
    2.42  
    2.43      def setServerName(self, value):
    2.44 -        self.environ['SERVER_NAME'] = value
    2.45 +        self.environ['SERVER_NAME'] = value.decode('latin-1')
    2.46  
    2.47      def setServerPort(self, value):
    2.48 -        self.environ['SERVER_PORT'] = str(value).encode('latin-1')
    2.49 +        self.environ['SERVER_PORT'] = str(value)
    2.50  
    2.51      def setIsSSL(self, value):
    2.52          if value:
    2.53 @@ -535,15 +536,15 @@
    2.54      def addHeader(self, name, value):
    2.55          name = name.replace(b'-', b'_').upper()
    2.56          if name in (b'CONTENT_TYPE', b'CONTENT_LENGTH'):
    2.57 -            self.environ[name.decode('latin-1')] = value
    2.58 +            self.environ[name.decode('latin-1')] = value.decode('latin-1')
    2.59              if name == b'CONTENT_LENGTH':
    2.60                  length = int(value)
    2.61                  self.input.setDataLength(length)
    2.62          else:
    2.63 -            self.environ[(b'HTTP_'+name).decode('latin-1')] = value
    2.64 +            self.environ[(b'HTTP_'+name).decode('latin-1')] = value.decode('latin-1')
    2.65  
    2.66      def addAttribute(self, name, value):
    2.67 -        self.environ[name] = value
    2.68 +        self.environ[name.decode('latin-1')] = value.decode('latin-1')
    2.69  
    2.70      # The only two methods that should be called from the handler.
    2.71  
    2.72 @@ -749,7 +750,7 @@
    2.73      # it is the maximum size of new data added per chunk.)
    2.74      inputStreamShrinkThreshold = 102400 - 8192
    2.75  
    2.76 -    def __init__(self, application, scriptName=b'', environ=None,
    2.77 +    def __init__(self, application, scriptName='', environ=None,
    2.78                   multithreaded=True, multiprocess=False,
    2.79                   bindAddress=('localhost', 8009), allowedServers=NoDefault,
    2.80                   loggingLevel=logging.INFO, debug=True):
    2.81 @@ -834,9 +835,9 @@
    2.82          environ['wsgi.run_once'] = False
    2.83  
    2.84          if environ.get('HTTPS', 'off') in ('on', '1'):
    2.85 -            environ['wsgi.url_scheme'] = b'https'
    2.86 +            environ['wsgi.url_scheme'] = 'https'
    2.87          else:
    2.88 -            environ['wsgi.url_scheme'] = b'http'
    2.89 +            environ['wsgi.url_scheme'] = 'http'
    2.90  
    2.91          self._sanitizeEnv(environ)
    2.92  
    2.93 @@ -926,13 +927,13 @@
    2.94  
    2.95          reqUri = None
    2.96          if 'REQUEST_URI' in environ:
    2.97 -            reqUri = environ['REQUEST_URI'].split(b'?', 1)
    2.98 +            reqUri = environ['REQUEST_URI'].split('?', 1)
    2.99  
   2.100          if 'QUERY_STRING' not in environ or not environ['QUERY_STRING']:
   2.101              if reqUri is not None and len(reqUri) > 1:
   2.102                  environ['QUERY_STRING'] = reqUri[1]
   2.103              else:
   2.104 -                environ['QUERY_STRING'] = b''
   2.105 +                environ['QUERY_STRING'] = ''
   2.106  
   2.107      def error(self, request):
   2.108          """