diff options
author | Baptiste Mispelon <bmispelon@gmail.com> | 2013-09-30 17:55:14 +0200 |
---|---|---|
committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-10-05 11:50:03 +0200 |
commit | 20472aa827669d2b83b74e521504e88e18d086a1 (patch) | |
tree | b5d6f49c10e746ecae227b33352ac29ec85fed79 /django/http/multipartparser.py | |
parent | 948d209adac566d89f44f073fdd77a371c18e269 (diff) | |
download | django-20472aa827669d2b83b74e521504e88e18d086a1.tar.gz |
Fixed #21189: Cleaned up usage of bare except clauses.
Thanks to berkerpeksag for the report and to claudep
for the review.
Diffstat (limited to 'django/http/multipartparser.py')
-rw-r--r-- | django/http/multipartparser.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index 9a5193e49b..af0222b423 100644 --- a/django/http/multipartparser.py +++ b/django/http/multipartparser.py @@ -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': |