diff -uprN django.orig/core/handlers/modpython.py django/core/handlers/modpython.py
old
|
new
|
import os
|
11 | 11 | # settings) until after ModPythonHandler has been called; otherwise os.environ |
12 | 12 | # won't be set up correctly (with respect to settings). |
13 | 13 | |
| 14 | # NOTE: Use only has_key() and keys() methods of Table objects to be compatible |
| 15 | # with mod_python2 |
| 16 | |
14 | 17 | class ModPythonRequest(http.HttpRequest): |
15 | 18 | def __init__(self, req): |
16 | 19 | self._req = req |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
43 | 46 | |
44 | 47 | def is_secure(self): |
45 | 48 | # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions |
46 | | return 'HTTPS' in self._req.subprocess_env and self._req.subprocess_env['HTTPS'] == 'on' |
| 49 | return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on' |
47 | 50 | |
48 | 51 | def _load_post_and_files(self): |
49 | 52 | "Populates self._post and self._files" |
50 | | if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): |
| 53 | if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'): |
51 | 54 | self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) |
52 | 55 | else: |
53 | 56 | self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
75 | 78 | |
76 | 79 | def _get_cookies(self): |
77 | 80 | if not hasattr(self, '_cookies'): |
78 | | self._cookies = http.parse_cookie(self._req.headers_in.get('cookie', '')) |
| 81 | # In mod_python2 Table object does not have get() method |
| 82 | if not self._req.headers_in.has_key('cookie'): |
| 83 | self._req.headers_in['cookie'] = '' |
| 84 | self._cookies = http.parse_cookie(self._req.headers_in['cookie']) |
79 | 85 | return self._cookies |
80 | 86 | |
81 | 87 | def _set_cookies(self, cookies): |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
89 | 95 | def _get_meta(self): |
90 | 96 | "Lazy loader that returns self.META dictionary" |
91 | 97 | if not hasattr(self, '_meta'): |
| 98 | # ap_uath_type and user are members of request object in |
| 99 | # mod_python3, but members of request.connection in mod_python2 |
| 100 | if hasattr(self._req, 'ap_auth_type'): |
| 101 | auth_type = self._req.ap_auth_type |
| 102 | elif hasattr(self._req.connection, 'ap_auth_type'): |
| 103 | auth_type = self._req.connection.ap_auth_type |
| 104 | else: |
| 105 | auth_type = None |
| 106 | if hasattr(self._req, 'user'): |
| 107 | user = self._req.user |
| 108 | elif hasattr(self._req.connection, 'user'): |
| 109 | user = self._req.connection.user |
| 110 | else: |
| 111 | user = None |
92 | 112 | self._meta = { |
93 | | 'AUTH_TYPE': self._req.ap_auth_type, |
| 113 | 'AUTH_TYPE': auth_type, |
94 | 114 | 'CONTENT_LENGTH': self._req.clength, # This may be wrong |
95 | 115 | 'CONTENT_TYPE': self._req.content_type, # This may be wrong |
96 | 116 | 'GATEWAY_INTERFACE': 'CGI/1.1', |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
100 | 120 | 'REMOTE_ADDR': self._req.connection.remote_ip, |
101 | 121 | 'REMOTE_HOST': None, # DNS lookups not supported |
102 | 122 | 'REMOTE_IDENT': self._req.connection.remote_logname, |
103 | | 'REMOTE_USER': self._req.user, |
| 123 | 'REMOTE_USER': user, |
104 | 124 | 'REQUEST_METHOD': self._req.method, |
105 | 125 | 'SCRIPT_NAME': None, # Not supported |
106 | 126 | 'SERVER_NAME': self._req.server.server_hostname, |
… |
… |
class ModPythonRequest(http.HttpRequest)
|
108 | 128 | 'SERVER_PROTOCOL': self._req.protocol, |
109 | 129 | 'SERVER_SOFTWARE': 'mod_python' |
110 | 130 | } |
111 | | for key, value in self._req.headers_in.items(): |
112 | | key = 'HTTP_' + key.upper().replace('-', '_') |
113 | | self._meta[key] = value |
| 131 | for key in self._req.headers_in.keys(): |
| 132 | meta_key = 'HTTP_' + key.upper().replace('-', '_') |
| 133 | self._meta[meta_key] = self._req.headers_in[key] |
114 | 134 | return self._meta |
115 | 135 | |
116 | 136 | def _get_raw_post_data(self): |
… |
… |
class ModPythonHandler(BaseHandler):
|
166 | 186 | req.headers_out.add('Set-Cookie', c.output(header='')) |
167 | 187 | req.status = response.status_code |
168 | 188 | try: |
| 189 | if hasattr(req, 'send_http_header'): |
| 190 | # This method exists only in mod_python2 and must be called |
| 191 | # before any data transfer |
| 192 | req.send_http_header() |
169 | 193 | for chunk in response: |
170 | 194 | req.write(chunk) |
171 | 195 | finally: |