clan-cli: clan_cli.jsonrpc -> clan_lib.jsonrpc
This commit is contained in:
15
pkgs/clan-cli/clan_lib/jsonrpc/__init__.py
Normal file
15
pkgs/clan-cli/clan_lib/jsonrpc/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import dataclasses
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ClanJSONEncoder(json.JSONEncoder):
|
||||
def default(self, o: Any) -> Any:
|
||||
# Check if the object has a to_json method
|
||||
if hasattr(o, "to_json") and callable(o.to_json):
|
||||
return o.to_json()
|
||||
# Check if the object is a dataclass
|
||||
if dataclasses.is_dataclass(o):
|
||||
return dataclasses.asdict(o) # type: ignore
|
||||
# Otherwise, use the default serialization
|
||||
return super().default(o)
|
||||
@@ -5,9 +5,8 @@ from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from clan_cli.jsonrpc import ClanJSONEncoder
|
||||
|
||||
from clan_lib.dirs import user_history_file
|
||||
from clan_lib.jsonrpc import ClanJSONEncoder
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
Reference in New Issue
Block a user