MultipartInputStream#
Superclasses: FilterInputStream
, InputStream
, Object
Implemented Interfaces: PollableInputStream
Handles streams of multipart messages.
This adds support for the multipart responses. For handling the
multiple parts the user needs to wrap the InputStream
obtained by
sending the request with a MultipartInputStream
and use
next_part
before reading. Responses
which are not wrapped will be treated like non-multipart responses.
Note that although MultipartInputStream
is a InputStream
,
you should not read directly from it, and the results are undefined
if you do.
Constructors#
- class MultipartInputStream
- classmethod new(msg: Message, base_stream: InputStream) MultipartInputStream #
Creates a new
MultipartInputStream
that wraps theInputStream
obtained by sending theMessage
.Reads should not be done directly through this object, use the input streams returned by
next_part
or its async counterpart instead.- Parameters:
msg – the
Message
the response is related to.base_stream – the
InputStream
returned by sending the request.
Methods#
- class MultipartInputStream
- get_headers() MessageHeaders | None #
Obtains the headers for the part currently being processed.
Note that the
MessageHeaders
that are returned are owned by theMultipartInputStream
and will be replaced when a call is made tonext_part
or its async counterpart, so if keeping the headers is required, a copy must be made.Note that if a part had no headers at all an empty
MessageHeaders
will be returned.
- next_part(cancellable: Cancellable | None = None) InputStream | None #
Obtains an input stream for the next part.
When dealing with a multipart response the input stream needs to be wrapped in a
MultipartInputStream
and this function or its async counterpart need to be called to obtain the first part for reading.After calling this function,
get_headers
can be used to obtain the headers for the first part. A read of 0 bytes indicates the end of the part; a new call to this function should be done at that point, to obtain the next part.error
will only be set if an error happens during a read,None
is a valid return value otherwise.- Parameters:
cancellable – a
Cancellable
- next_part_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, data: Any = None) None #
Obtains a
InputStream
for the next request.See
next_part
for details on the workflow.- Parameters:
io_priority – the I/O priority for the request.
cancellable – a
Cancellable
.callback – callback to call when request is satisfied.
data – data for
callback
- next_part_finish(result: AsyncResult) InputStream | None #
Finishes an asynchronous request for the next part.
- Parameters:
result – a
AsyncResult
.