MCPcopy Create free account
hub / github.com/piccolo-orm/piccolo / convert_complex_array_out

Function convert_complex_array_out

piccolo/engine/sqlite.py:260–285  ·  view source on GitHub ↗

This is used to handle arrays of things like timestamps, which we can't just load from JSON without doing additional work to convert the elements back into Python objects.

(value: bytes, converter: Callable)

Source from the content-addressed store, hash-verified

258
259
260def convert_complex_array_out(value: bytes, converter: Callable):
261 """
262 This is used to handle arrays of things like timestamps, which we can't
263 just load from JSON without doing additional work to convert the elements
264 back into Python objects.
265 """
266 parsed = load_json(value.decode("utf8"))
267
268 def convert_list(list_value: list):
269 output = []
270
271 for value in list_value:
272 if isinstance(value, list):
273 # For nested arrays
274 output.append(convert_list(value))
275 elif isinstance(value, str):
276 output.append(converter(value))
277 else:
278 output.append(value)
279
280 return output
281
282 if isinstance(parsed, list):
283 return convert_list(parsed)
284 else:
285 return parsed
286
287
288@decode_to_string

Callers

nothing calls this directly

Calls 2

load_jsonFunction · 0.90
convert_listFunction · 0.85

Tested by

no test coverage detected