parsers: Pull parse_constant out of try-except block

This commit is contained in:
Sebastian Pipping 2019-10-31 12:24:36 +01:00
parent ab40b80fa6
commit 1b23543ed1

View File

@ -56,12 +56,12 @@ class JSONParser(BaseParser):
""" """
Parses the incoming bytestream as JSON and returns the resulting data. Parses the incoming bytestream as JSON and returns the resulting data.
""" """
parse_constant = json.strict_constant if self.strict else None
parser_context = parser_context or {} parser_context = parser_context or {}
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
try: try:
decoded_stream = codecs.getreader(encoding)(stream) decoded_stream = codecs.getreader(encoding)(stream)
parse_constant = json.strict_constant if self.strict else None
return json.load(decoded_stream, parse_constant=parse_constant) return json.load(decoded_stream, parse_constant=parse_constant)
except ValueError as exc: except ValueError as exc:
raise ParseError('JSON parse error - %s' % str(exc)) raise ParseError('JSON parse error - %s' % str(exc))