Ticket #8622: file_upload_error_handling.diff
File file_upload_error_handling.diff, 4.2 KB (added by , 16 years ago) |
---|
-
django/core/handlers/wsgi.py
92 92 self.META['PATH_INFO'] = path_info 93 93 self.META['SCRIPT_NAME'] = script_name 94 94 self.method = environ['REQUEST_METHOD'].upper() 95 self._post_parse_error = False 95 96 96 97 def __repr__(self): 97 98 # Since this is called as part of error handling, we need to be very … … 100 101 get = pformat(self.GET) 101 102 except: 102 103 get = '<could not parse>' 104 if self._post_parse_error: 105 post = '<POST data unavailable>' 106 else: 107 try: 108 post = pformat(self.POST) 109 except: 110 post = '<could not parse>' 103 111 try: 104 post = pformat(self.POST)105 except:106 post = '<could not parse>'107 try:108 112 cookies = pformat(self.COOKIES) 109 113 except: 110 114 cookies = '<could not parse>' … … 127 131 if self.method == 'POST': 128 132 if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): 129 133 self._raw_post_data = '' 130 self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input']) 134 try: 135 self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input']) 136 except: 137 # An error occured while parsing POST data. Since when 138 # formatting the error the request handler might access 139 # self.POST, set self._post and self._file to prevent 140 # attempts to parse POST data again. 141 self._post = http.QueryDict('') 142 self._files = datastructures.MultiValueDict() 143 # Mark that an error occured. This allows self.__repr__ to 144 # be explicit about it instead of simply representing an 145 # empty POST 146 self._post_parse_error = True 147 raise 131 148 else: 132 149 self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 133 150 else: -
django/core/handlers/modpython.py
35 35 # a common start character for URL patterns. So this is a little 36 36 # naughty, but also pretty harmless. 37 37 self.path_info = u'/' 38 self._post_parse_error = False 38 39 39 40 def __repr__(self): 40 41 # Since this is called as part of error handling, we need to be very … … 43 44 get = pformat(self.GET) 44 45 except: 45 46 get = '<could not parse>' 47 if self._post_parse_error: 48 post = '<POST data unavailable>' 49 else: 50 try: 51 post = pformat(self.POST) 52 except: 53 post = '<could not parse>' 46 54 try: 47 post = pformat(self.POST)48 except:49 post = '<could not parse>'50 try:51 55 cookies = pformat(self.COOKIES) 52 56 except: 53 57 cookies = '<could not parse>' … … 73 77 "Populates self._post and self._files" 74 78 if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): 75 79 self._raw_post_data = '' 76 self._post, self._files = self.parse_file_upload(self.META, self._req) 80 try: 81 self._post, self._files = self.parse_file_upload(self.META, self._req) 82 except: 83 # This is the same situation found in 84 # django.core.handlers.wsgi.WSGIHandler 85 self._post = http.QueryDict('') 86 self._files = datastructures.MultiValueDict() 87 self._post_parse_error = True 88 raise 77 89 else: 78 90 self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 79 91