Given a stream of bytes or text, if any of the items in the stream are bytes convert them to text. This function can be removed once we return text streams instead of byte streams.
(stream)
| 7 | |
| 8 | |
| 9 | def stream_as_text(stream): |
| 10 | """ |
| 11 | Given a stream of bytes or text, if any of the items in the stream |
| 12 | are bytes convert them to text. |
| 13 | This function can be removed once we return text streams |
| 14 | instead of byte streams. |
| 15 | """ |
| 16 | for data in stream: |
| 17 | if not isinstance(data, str): |
| 18 | data = data.decode('utf-8', 'replace') |
| 19 | yield data |
| 20 | |
| 21 | |
| 22 | def json_splitter(buffer): |
no outgoing calls