Refs #27857 -- Replaced json.loads() ValueError exception catching with JSONDecodeError.

This commit is contained in:
Tim Graham 2017-06-20 15:16:37 -04:00
parent cfff2af02b
commit 98706bb35e
6 changed files with 9 additions and 9 deletions

View File

@ -95,7 +95,7 @@ class LogEntry(models.Model):
if self.change_message and self.change_message[0] == '[':
try:
change_message = json.loads(self.change_message)
except ValueError:
except json.JSONDecodeError:
return self.change_message
messages = []
for sub_message in change_message:

View File

@ -157,7 +157,7 @@ class CookieStorage(BaseStorage):
# If we get here (and the JSON decode works), everything is
# good. In any other case, drop back and return None.
return json.loads(value, cls=MessageDecoder)
except ValueError:
except json.JSONDecodeError:
pass
# Mark the data as used (so it gets removed) since something was wrong
# with the data.

View File

@ -28,7 +28,7 @@ class HStoreField(forms.CharField):
if not isinstance(value, dict):
try:
value = json.loads(value)
except ValueError:
except json.JSONDecodeError:
raise ValidationError(
self.error_messages['invalid_json'],
code='invalid_json',

View File

@ -29,7 +29,7 @@ class JSONField(forms.CharField):
return value
try:
converted = json.loads(value)
except ValueError:
except json.JSONDecodeError:
raise forms.ValidationError(
self.error_messages['invalid'],
code='invalid',
@ -45,7 +45,7 @@ class JSONField(forms.CharField):
return initial
try:
return json.loads(data)
except ValueError:
except json.JSONDecodeError:
return InvalidJSONInput(data)
def prepare_value(self, value):

View File

@ -391,7 +391,7 @@ class ManifestFilesMixin(HashedFilesMixin):
return OrderedDict()
try:
stored = json.loads(content, object_pairs_hook=OrderedDict)
except ValueError:
except json.JSONDecodeError:
pass
else:
version = stored.get('version')

View File

@ -708,7 +708,7 @@ class SimpleTestCase(unittest.TestCase):
"""
try:
data = json.loads(raw)
except ValueError:
except json.JSONDecodeError:
self.fail("First argument is not valid JSON: %r" % raw)
if isinstance(expected_data, str):
try:
@ -725,12 +725,12 @@ class SimpleTestCase(unittest.TestCase):
"""
try:
data = json.loads(raw)
except ValueError:
except json.JSONDecodeError:
self.fail("First argument is not valid JSON: %r" % raw)
if isinstance(expected_data, str):
try:
expected_data = json.loads(expected_data)
except ValueError:
except json.JSONDecodeError:
self.fail("Second argument is not valid JSON: %r" % expected_data)
self.assertNotEqual(data, expected_data, msg=msg)