Commit 91727c76 authored by Claude Paroz's avatar Claude Paroz
Browse files

Cleaned up WSGIRequestHandler get_environ to be Python 3 compatible

headers.type/typeheader attributes are gone in Python 3. Thanks
Vinay Sajip for the inspiration of his Python 3 branch.
parent 02eca6c0
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -146,25 +146,23 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
        env['PATH_INFO'] = urllib.unquote(path)
        env['QUERY_STRING'] = query
        env['REMOTE_ADDR'] = self.client_address[0]
        env['CONTENT_TYPE'] = self.headers.get('content-type', 'text/plain')

        if self.headers.typeheader is None:
            env['CONTENT_TYPE'] = self.headers.type
        else:
            env['CONTENT_TYPE'] = self.headers.typeheader

        length = self.headers.getheader('content-length')
        length = self.headers.get('content-length')
        if length:
            env['CONTENT_LENGTH'] = length

        for h in self.headers.headers:
            k,v = h.split(':',1)
            k=k.replace('-','_').upper(); v=v.strip()
            if k in env:
                continue                    # skip content length, type,etc.
            if 'HTTP_'+k in env:
                env['HTTP_'+k] += ','+v     # comma-separate multiple headers
        for key, value in self.headers.items():
            key = key.replace('-','_').upper()
            value = value.strip()
            if key in env:
                # Skip content length, type, etc.
                continue
            if 'HTTP_' + key in env:
                # Comma-separate multiple headers
                env['HTTP_' + key] += ',' + value
            else:
                env['HTTP_'+k] = v
                env['HTTP_' + key] = value
        return env

    def log_message(self, format, *args):