Ticket #5682: patch_django_5682.diff
File patch_django_5682.diff, 9.2 KB (added by , 17 years ago) |
---|
-
django_src/django/http/__init__.py
20 20 class HttpRequest(object): 21 21 "A basic HTTP request" 22 22 23 # The encoding used in GET/POST dicts. None means use default setting.23 # The encoding used in GET/POST/PUT dicts. None means use default setting. 24 24 _encoding = None 25 25 26 26 def __init__(self): 27 self.GET, self.POST, self. COOKIES, self.META, self.FILES ={}, {}, {}, {}, {}27 self.GET, self.POST, self.PUT, self.COOKIES, self.META, self.DATA, self.FILES = {}, {}, {}, {}, {}, {}, {} 28 28 self.path = '' 29 29 self.method = None 30 30 31 31 def __repr__(self): 32 return '<HttpRequest\nGET:%s,\nPOST:%s,\n COOKIES:%s,\nMETA:%s>' % \33 (pformat(self.GET), pformat(self.POST), pformat(self. COOKIES),34 pformat(self. META))32 return '<HttpRequest\nGET:%s,\nPOST:%s,\nPUT:%s,\nCOOKIES:%s,\nMETA:%s>' % \ 33 (pformat(self.GET), pformat(self.POST), pformat(self.PUT), 34 pformat(self.COOKIES), pformat(self.META)) 35 35 36 36 def __getitem__(self, key): 37 for d in (self.POST, self.GET ):37 for d in (self.POST, self.GET, self.PUT): 38 38 if key in d: 39 39 return d[key] 40 raise KeyError, "%s not found in either POST or GET" % key40 raise KeyError, "%s not found in either POST, GET or PUT" % key 41 41 42 42 def has_key(self, key): 43 return key in self.GET or key in self.POST 43 return key in self.GET or key in self.POST or key in self.PUT 44 44 45 45 __contains__ = has_key 46 46 … … 81 81 82 82 def _set_encoding(self, val): 83 83 """ 84 Sets the encoding used for GET/POST accesses. If the GET or POST84 Sets the encoding used for GET/POST/PUT accesses. If the GET, POST or PUT 85 85 dictionary has already been created, it is removed and recreated on the 86 86 next access (so that it is decoded correctly). 87 87 """ … … 90 90 del self._get 91 91 if hasattr(self, '_post'): 92 92 del self._post 93 if hasattr(self, '_put'): 94 del self._put 93 95 94 96 def _get_encoding(self): 95 97 return self._encoding … … 97 99 encoding = property(_get_encoding, _set_encoding) 98 100 99 101 def parse_file_upload(header_dict, post_data): 100 "Returns a tuple of ( POSTQueryDict, FILES MultiValueDict)"102 "Returns a tuple of (DATA QueryDict, FILES MultiValueDict)" 101 103 import email, email.Message 102 104 from cgi import parse_header 103 105 raw_message = '\r\n'.join(['%s:%s' % pair for pair in header_dict.items()]) 104 106 raw_message += '\r\n\r\n' + post_data 105 107 msg = email.message_from_string(raw_message) 106 POST= QueryDict('', mutable=True)108 DATA = QueryDict('', mutable=True) 107 109 FILES = MultiValueDict() 108 110 for submessage in msg.get_payload(): 109 111 if submessage and isinstance(submessage, email.Message.Message): … … 126 128 'content': submessage.get_payload(), 127 129 })) 128 130 else: 129 POST.appendlist(name_dict['name'], submessage.get_payload())130 return POST, FILES131 DATA.appendlist(name_dict['name'], submessage.get_payload()) 132 return DATA, FILES 131 133 132 134 class QueryDict(MultiValueDict): 133 135 """ -
django_src/django/test/client.py
218 218 219 219 return self.request(**r) 220 220 221 def delete(self, path, data={}, **extra): 222 "Request a response from the server using DELETE." 223 r = { 224 'CONTENT_LENGTH': None, 225 'CONTENT_TYPE': 'text/html; charset=utf-8', 226 'PATH_INFO': path, 227 'QUERY_STRING': urlencode(data, doseq=True), 228 'REQUEST_METHOD': 'DELETE', 229 } 230 r.update(extra) 231 232 return self.request(**r) 233 221 234 def post(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): 222 235 "Request a response from the server using POST." 223 236 … … 237 250 238 251 return self.request(**r) 239 252 253 def put(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): 254 "Request a response from the server using PUT." 255 256 if content_type is MULTIPART_CONTENT: 257 put_data = encode_multipart(BOUNDARY, data) 258 else: 259 put_data = data 260 261 r = { 262 'CONTENT_LENGTH': len(put_data), 263 'CONTENT_TYPE': content_type, 264 'PATH_INFO': path, 265 'REQUEST_METHOD': 'PUT', 266 'wsgi.input': StringIO(put_data), 267 } 268 r.update(extra) 269 270 return self.request(**r) 271 240 272 def login(self, **credentials): 241 273 """Set the Client to appear as if it has sucessfully logged into a site. 242 274 -
django_src/django/core/handlers/wsgi.py
91 91 except: 92 92 post = '<could not parse>' 93 93 try: 94 put = pformat(self.PUT) 95 except: 96 put = '<could not parse>' 97 try: 94 98 cookies = pformat(self.COOKIES) 95 99 except: 96 100 cookies = '<could not parse>' … … 98 102 meta = pformat(self.META) 99 103 except: 100 104 meta = '<could not parse>' 101 return '<WSGIRequest\nGET:%s,\nPOST:%s,\n COOKIES:%s,\nMETA:%s>' % \102 (get, post, cookies, meta)105 return '<WSGIRequest\nGET:%s,\nPOST:%s,\nPUT:%s,\nCOOKIES:%s,\nMETA:%s>' % \ 106 (get, post, put, cookies, meta) 103 107 104 108 def get_full_path(self): 105 109 return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '') … … 108 112 return 'wsgi.url_scheme' in self.environ \ 109 113 and self.environ['wsgi.url_scheme'] == 'https' 110 114 111 def _load_ post_and_files(self):112 # Populates self._ postand self._files113 if self.method == 'POST':115 def _load_data_and_files(self): 116 # Populates self._data and self._files 117 if self.method in ('POST', 'PUT'): 114 118 if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): 115 119 header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')]) 116 120 header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '') 117 self._ post, self._files = http.parse_file_upload(header_dict, self.raw_post_data)121 self._data, self._files = http.parse_file_upload(header_dict, self.raw_post_data) 118 122 else: 119 self._ post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()123 self._data, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 120 124 else: 121 self._ post, self._files = http.QueryDict('', encoding=self._encoding), datastructures.MultiValueDict()125 self._data, self._files = http.QueryDict('', encoding=self._encoding), datastructures.MultiValueDict() 122 126 127 def _load_post_and_files(self): 128 # Populates self._post, preserve backward compatibility. 129 if not hasattr(self, '_data'): 130 self._load_data_and_files() 131 self._post = self._data 132 123 133 def _get_request(self): 124 134 if not hasattr(self, '_request'): 125 self._request = datastructures.MergeDict(self.POST, self. GET)135 self._request = datastructures.MergeDict(self.POST, self.PUT, self.GET) 126 136 return self._request 127 137 128 138 def _get_get(self): … … 136 146 137 147 def _get_post(self): 138 148 if not hasattr(self, '_post'): 139 self._ load_post_and_files()149 self._post = self.DATA 140 150 return self._post 141 151 142 152 def _set_post(self, post): 143 153 self._post = post 144 154 155 def _get_put(self): 156 if not hasattr(self, '_put'): 157 self._put = self.DATA 158 return self._put 159 160 def _set_put(self, put): 161 self._put = put 162 145 163 def _get_cookies(self): 146 164 if not hasattr(self, '_cookies'): 147 165 self._cookies = http.parse_cookie(self.environ.get('HTTP_COOKIE', '')) … … 152 170 153 171 def _get_files(self): 154 172 if not hasattr(self, '_files'): 155 self._load_ post_and_files()173 self._load_data_and_files() 156 174 return self._files 157 175 176 def _get_data(self): 177 if not hasattr(self, '_data'): 178 self._load_data_and_files() 179 return self._data 180 158 181 def _get_raw_post_data(self): 159 182 try: 160 183 return self._raw_post_data … … 174 197 175 198 GET = property(_get_get, _set_get) 176 199 POST = property(_get_post, _set_post) 200 PUT = property(_get_put, _set_put) 177 201 COOKIES = property(_get_cookies, _set_cookies) 178 202 FILES = property(_get_files) 203 DATA = property(_get_data) 179 204 REQUEST = property(_get_request) 180 205 raw_post_data = property(_get_raw_post_data) 181 206 207 182 208 class WSGIHandler(BaseHandler): 183 209 initLock = Lock() 184 210 request_class = WSGIRequest