Allow to disable ujson

This commit is contained in:
Alex Root Junior 2017-10-20 11:11:01 +03:00
parent 00400ea88b
commit f3c39ed9f1
2 changed files with 17 additions and 6 deletions

View file

@ -1,16 +1,27 @@
import json
try:
import ujson as json
import ujson
IS_UJSON = True
_UJSON_IS_AVAILABLE = True
except ImportError:
import json
_UJSON_IS_AVAILABLE = False
IS_UJSON = False
_use_ujson = _UJSON_IS_AVAILABLE
def disable_ujson():
global _use_ujson
_use_ujson = False
def dumps(data):
if _use_ujson:
return ujson.dumps(data)
return json.dumps(data)
def loads(data):
if _use_ujson:
return ujson.loads(data)
return json.loads(data)