MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / json_safe

Function json_safe

tests/fake_server.py:23–36  ·  view source on GitHub ↗
(string, content_type="application/octet-stream")

Source from the content-addressed store, hash-verified

21
22
23def json_safe(string, content_type="application/octet-stream") -> str:
24 try:
25 string = string.decode("utf-8")
26 json.dumps(string)
27 return string
28 except (ValueError, TypeError):
29 return b"".join(
30 [
31 b"data:",
32 content_type.encode("utf-8"),
33 b";base64,",
34 base64.b64encode(string),
35 ]
36 ).decode("utf-8")
37
38
39def flattern(d: "MultiDict[K, V]") -> dict[K, V | list[V]]:

Callers 1

http_echoFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected