Add RequestDataIter for normalizing streams, iterators#123
Add RequestDataIter for normalizing streams, iterators#123sethmlarson wants to merge 4 commits intoencode:masterfrom sethmlarson:request-data-iter
Conversation
|
Another bigger question is if we move towards having |
|
Something along these lines seems like a good tack, yup. A thought... perhaps rather than a custom interface, our wrapper class should be an implementation of Ie. class ByteStream(io.IOBase):
"""
Wraps various text/bytes data types up into a single standard byte stream interface.
"""
def __init__(self, content: typing.Union[
str,
bytes,
typing.Iterator[typing.AnyStr],
typing.IO[typing.AnyStr],
]):
...(We'd also end up needing an equivelent async alternative.) |
|
I started off on the |
|
Ah okay, that's a shame. I'd figured there'd be a fair bit of functionality that's covered by the built-in mixin implementations. (Also, I think we should probably roll a |
|
I implemented via |
| return b"" | ||
| return request.content.rewind() | ||
| if request.content.seekable: | ||
| request.content.seek(0, 0) |
There was a problem hiding this comment.
Presumably we need an else error case here?
|
Okay, so this is quite large ATM. There's also a few bits that I think we could seperate out more cleanly. Eg. I don't think So that we can get nice clean PRs onto all this I'd probably suggest:
|
| raise ValueError( | ||
| "RequestDataStream doesn't support seek() except " | ||
| "the beginning or end of the stream" | ||
| ) |
There was a problem hiding this comment.
We could support this if we wanted, by reading and throwing away the data.
Makes it so you can pass iterators, async iterators, open files and file-like objects, and raw strings as
data. Do we needRequest.is_streaminganymore?