53 """Parse a chunked NDJSON HTTP response body into a stream of dicts.
55 Each element of *byte_iter* may contain zero, one, or multiple
56 ``\\n``-terminated JSON lines, or a partial line that continues in
60 byte_iter: Raw HTTP body chunk iterator (e.g. an iterated
61 ``http.client.HTTPResponse``).
64 Parsed dicts, one per complete, valid JSON line.
66 func =
"parse_ndjson_stream"
69 for chunk
in byte_iter:
72 line_bytes, buf = buf.split(b
"\n", 1)
73 line = line_bytes.strip()
77 yield json.loads(line)
78 except json.JSONDecodeError
as exc:
79 _dbg(
"OC_CHAT.CLIENT", func,
80 f
"malformed JSON line ({exc}): {line[:80]!r}", 2)
86 yield json.loads(line)
87 except json.JSONDecodeError
as exc:
88 _dbg(
"OC_CHAT.CLIENT", func,
89 f
"malformed final line ({exc}): {line[:80]!r}", 2)