add orjson support

This commit is contained in:
grey-cat-1908 2022-03-22 16:47:06 +03:00
parent 00947ea562
commit dbe2a9bb66
3 changed files with 28 additions and 2 deletions

View file

@ -1,7 +1,6 @@
# Copyright MelisaDev 2022 - Present
# Full MIT License can be found in `LICENSE.txt` at the project root.
import json
import asyncio
import sys
import zlib
@ -15,7 +14,7 @@ import aiohttp
from ..exceptions import GatewayError, PrivilegedIntentsRequired, LoginFailure
from ..listeners import listeners
from ..models.user import BotActivity
from ..utils import APIModelBase
from ..utils import APIModelBase, json
@dataclass

26
melisa/utils/json.py Normal file
View 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
View file

@ -0,0 +1 @@
orjson==3.6.7