diff --git a/melisa/core/gateway.py b/melisa/core/gateway.py index eb0ec26..664781d 100644 --- a/melisa/core/gateway.py +++ b/melisa/core/gateway.py @@ -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 diff --git a/melisa/utils/json.py b/melisa/utils/json.py new file mode 100644 index 0000000..aa0e8d6 --- /dev/null +++ b/melisa/utils/json.py @@ -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 diff --git a/packages/speed.txt b/packages/speed.txt new file mode 100644 index 0000000..d56bbbd --- /dev/null +++ b/packages/speed.txt @@ -0,0 +1 @@ +orjson==3.6.7 \ No newline at end of file