mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
add orjson support
This commit is contained in:
parent
00947ea562
commit
dbe2a9bb66
3 changed files with 28 additions and 2 deletions
|
@ -1,7 +1,6 @@
|
||||||
# Copyright MelisaDev 2022 - Present
|
# Copyright MelisaDev 2022 - Present
|
||||||
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||||
|
|
||||||
import json
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
import zlib
|
import zlib
|
||||||
|
@ -15,7 +14,7 @@ import aiohttp
|
||||||
from ..exceptions import GatewayError, PrivilegedIntentsRequired, LoginFailure
|
from ..exceptions import GatewayError, PrivilegedIntentsRequired, LoginFailure
|
||||||
from ..listeners import listeners
|
from ..listeners import listeners
|
||||||
from ..models.user import BotActivity
|
from ..models.user import BotActivity
|
||||||
from ..utils import APIModelBase
|
from ..utils import APIModelBase, json
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
26
melisa/utils/json.py
Normal file
26
melisa/utils/json.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Copyright MelisaDev 2022 - Present
|
||||||
|
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
try:
|
||||||
|
import orjson
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
import json
|
||||||
|
|
||||||
|
HAS_ORJSON = False
|
||||||
|
else:
|
||||||
|
HAS_ORJSON = True
|
||||||
|
|
||||||
|
if HAS_ORJSON:
|
||||||
|
def dumps(obj: Any) -> str:
|
||||||
|
return orjson.dumps(obj).decode('utf-8')
|
||||||
|
|
||||||
|
loads = orjson.loads
|
||||||
|
else:
|
||||||
|
def dumps(obj: Any) -> str:
|
||||||
|
return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
|
||||||
|
|
||||||
|
loads = json.loads
|
1
packages/speed.txt
Normal file
1
packages/speed.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
orjson==3.6.7
|
Loading…
Reference in a new issue