Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 91727c76cda3f8bf286ee69652bc3625f150f6e7 1 parent 02eca6c
Claude Paroz authored May 17, 2012

Showing 1 changed file with 12 additions and 14 deletions. Show diff stats Hide diff stats

  1. 26  django/core/servers/basehttp.py
26  django/core/servers/basehttp.py
@@ -146,25 +146,23 @@ def get_environ(self):
146 146
         env['PATH_INFO'] = urllib.unquote(path)
147 147
         env['QUERY_STRING'] = query
148 148
         env['REMOTE_ADDR'] = self.client_address[0]
  149
+        env['CONTENT_TYPE'] = self.headers.get('content-type', 'text/plain')
149 150
 
150  
-        if self.headers.typeheader is None:
151  
-            env['CONTENT_TYPE'] = self.headers.type
152  
-        else:
153  
-            env['CONTENT_TYPE'] = self.headers.typeheader
154  
-
155  
-        length = self.headers.getheader('content-length')
  151
+        length = self.headers.get('content-length')
156 152
         if length:
157 153
             env['CONTENT_LENGTH'] = length
158 154
 
159  
-        for h in self.headers.headers:
160  
-            k,v = h.split(':',1)
161  
-            k=k.replace('-','_').upper(); v=v.strip()
162  
-            if k in env:
163  
-                continue                    # skip content length, type,etc.
164  
-            if 'HTTP_'+k in env:
165  
-                env['HTTP_'+k] += ','+v     # comma-separate multiple headers
  155
+        for key, value in self.headers.items():
  156
+            key = key.replace('-','_').upper()
  157
+            value = value.strip()
  158
+            if key in env:
  159
+                # Skip content length, type, etc.
  160
+                continue
  161
+            if 'HTTP_' + key in env:
  162
+                # Comma-separate multiple headers
  163
+                env['HTTP_' + key] += ',' + value
166 164
             else:
167  
-                env['HTTP_'+k] = v
  165
+                env['HTTP_' + key] = value
168 166
         return env
169 167
 
170 168
     def log_message(self, format, *args):

0 notes on commit 91727c7

Please sign in to comment.
Something went wrong with that request. Please try again.