mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-23 03:33:35 +00:00
a01247d48f
Python 3.11 ships with latest Debian Bookworm. pypy is not that widely used with this library based on statistics. It could be added back when pypy supports python 3.11.
35 lines
849 B
Python
Executable File
35 lines
849 B
Python
Executable File
"""JSON abstraction."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
try:
|
|
import orjson
|
|
|
|
def dumps(obj: Any, *, default: Callable | None = None) -> str:
|
|
"""Dump JSON."""
|
|
return orjson.dumps(obj).decode()
|
|
|
|
loads = orjson.loads
|
|
except ImportError:
|
|
import json
|
|
|
|
def dumps(obj: Any, *, default: Callable | None = None) -> str:
|
|
"""Dump JSON."""
|
|
# Separators specified for consistency with orjson
|
|
return json.dumps(obj, separators=(",", ":"))
|
|
|
|
loads = json.loads
|
|
|
|
|
|
try:
|
|
from mashumaro.mixins.orjson import DataClassORJSONMixin
|
|
|
|
DataClassJSONMixin = DataClassORJSONMixin
|
|
except ImportError:
|
|
from mashumaro.mixins.json import DataClassJSONMixin as JSONMixin
|
|
|
|
DataClassJSONMixin = JSONMixin # type: ignore[assignment, misc]
|