MCPcopy Index your code
hub / github.com/pyscript/pyscript / _convert_to_idb

Function _convert_to_idb

core/src/stdlib/pyscript/storage.py:57–75  ·  view source on GitHub ↗

Convert a Python `value` to an IndexedDB-compatible format. Values are serialized using Flatted (for circular reference support) with type information to enable proper deserialization. It returns a JSON string representing the serialized value. Will raise a TypeError if the va

(value)

Source from the content-addressed store, hash-verified

55
56
57def _convert_to_idb(value):
58 """
59 Convert a Python `value` to an IndexedDB-compatible format.
60
61 Values are serialized using Flatted (for circular reference support)
62 with type information to enable proper deserialization. It returns a
63 JSON string representing the serialized value.
64
65 Will raise a TypeError if the value type is not supported.
66 """
67 if is_none(value):
68 return _stringify(["null", 0])
69 if isinstance(value, (bool, float, int, str, list, dict, tuple)):
70 return _stringify(["generic", value])
71 if isinstance(value, bytearray):
72 return _stringify(["bytearray", list(value)])
73 if isinstance(value, memoryview):
74 return _stringify(["memoryview", list(value)])
75 raise TypeError(f"Cannot serialize type {type(value).__name__} for storage.")
76
77
78def _convert_from_idb(value):

Callers 1

__setitem__Method · 0.85

Calls 1

is_noneFunction · 0.90

Tested by

no test coverage detected