Fix json loads bug on Python 3.5
This commit is contained in:
parent
66fcb0cc8f
commit
7cc02e84ed
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user