mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #21189: Cleaned up usage of bare except clauses.
Thanks to berkerpeksag for the report and to claudep for the review.
This commit is contained in:
@@ -7,6 +7,7 @@ file upload handlers for processing.
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
import cgi
|
||||
import sys
|
||||
|
||||
@@ -33,6 +34,8 @@ RAW = "raw"
|
||||
FILE = "file"
|
||||
FIELD = "field"
|
||||
|
||||
_BASE64_DECODE_ERROR = TypeError if six.PY2 else binascii.Error
|
||||
|
||||
class MultiPartParser(object):
|
||||
"""
|
||||
A rfc2388 multipart/form-data parser.
|
||||
@@ -161,8 +164,8 @@ class MultiPartParser(object):
|
||||
if transfer_encoding == 'base64':
|
||||
raw_data = field_stream.read()
|
||||
try:
|
||||
data = str(raw_data).decode('base64')
|
||||
except:
|
||||
data = base64.b64decode(raw_data)
|
||||
except _BASE64_DECODE_ERROR:
|
||||
data = raw_data
|
||||
else:
|
||||
data = field_stream.read()
|
||||
@@ -546,7 +549,7 @@ def parse_boundary_stream(stream, max_header_size):
|
||||
main_value_pair, params = parse_header(line)
|
||||
try:
|
||||
name, value = main_value_pair.split(':', 1)
|
||||
except:
|
||||
except ValueError:
|
||||
raise ValueError("Invalid header: %r" % line)
|
||||
return name, (value, params)
|
||||
|
||||
@@ -571,7 +574,7 @@ def parse_boundary_stream(stream, max_header_size):
|
||||
# parameters") is from the Python docs.
|
||||
try:
|
||||
name, (value, params) = _parse_header(line)
|
||||
except:
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
if name == 'content-disposition':
|
||||
|
||||
@@ -16,7 +16,7 @@ from django.conf import settings
|
||||
from django.core import signing
|
||||
from django.core.exceptions import DisallowedHost, ImproperlyConfigured
|
||||
from django.core.files import uploadhandler
|
||||
from django.http.multipartparser import MultiPartParser
|
||||
from django.http.multipartparser import MultiPartParser, MultiPartParserError
|
||||
from django.utils import six
|
||||
from django.utils.datastructures import MultiValueDict, ImmutableList
|
||||
from django.utils.encoding import force_bytes, force_text, force_str, iri_to_uri
|
||||
@@ -222,7 +222,7 @@ class HttpRequest(object):
|
||||
data = self
|
||||
try:
|
||||
self._post, self._files = self.parse_file_upload(self.META, data)
|
||||
except:
|
||||
except MultiPartParserError:
|
||||
# An error occured while parsing POST data. Since when
|
||||
# formatting the error the request handler might access
|
||||
# self.POST, set self._post and self._file to prevent
|
||||
@@ -230,7 +230,7 @@ class HttpRequest(object):
|
||||
# Mark that an error occured. This allows self.__repr__ to
|
||||
# be explicit about it instead of simply representing an
|
||||
# empty POST
|
||||
self._mark_post_parse_error()
|
||||
# self._mark_post_parse_error()
|
||||
raise
|
||||
elif self.META.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
|
||||
self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict()
|
||||
|
||||
Reference in New Issue
Block a user