mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Allow to disable ujson
This commit is contained in:
parent
00400ea88b
commit
f3c39ed9f1
2 changed files with 17 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue