usse/scrape/venv/lib/python3.10/site-packages/sphinxcontrib/serializinghtml/jsonimpl.py

34 lines
842 B
Python
Raw Normal View History

2023-12-22 14:26:01 +00:00
"""JSON serializer implementation wrapper."""
from __future__ import annotations
import json
from collections import UserString
from typing import Any, IO
class SphinxJSONEncoder(json.JSONEncoder):
"""JSONEncoder subclass that forces translation proxies."""
def default(self, obj: Any) -> str:
if isinstance(obj, UserString):
return str(obj)
return super().default(obj)
def dump(obj: Any, fp: IO, *args: Any, **kwds: Any) -> None:
kwds['cls'] = SphinxJSONEncoder
json.dump(obj, fp, *args, **kwds)
def dumps(obj: Any, *args: Any, **kwds: Any) -> str:
kwds['cls'] = SphinxJSONEncoder
return json.dumps(obj, *args, **kwds)
def load(*args: Any, **kwds: Any) -> Any:
return json.load(*args, **kwds)
def loads(*args: Any, **kwds: Any) -> Any:
return json.loads(*args, **kwds)