Fix json loads bug on Python 3.5

This commit is contained in:
messense 2017-05-15 10:11:25 +08:00
parent 66fcb0cc8f
commit 7cc02e84ed
No known key found for this signature in database
GPG Key ID: BB41A8A2C716CCA9

View File

@ -1,3 +1,5 @@
import sys
import json
from cgi import parse_header from cgi import parse_header
from collections import namedtuple from collections import namedtuple
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
@ -7,7 +9,12 @@ from urllib.parse import parse_qs, urlunparse
try: try:
from ujson import loads as json_loads from ujson import loads as json_loads
except ImportError: except ImportError:
from json import loads as json_loads if sys.version_info[:2] == (3, 5):
def json_loads(data):
# on Python 3.5 json.loads only supports str not bytes
return json.loads(data.decode())
else:
json_loads = json.loads
from sanic.exceptions import InvalidUsage from sanic.exceptions import InvalidUsage
from sanic.log import log from sanic.log import log