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
MultipartInputStreamthat wraps theInputStreamobtained by sending theMessage.Reads should not be done directly through this object, use the input streams returned by
next_partor its async counterpart instead.- Parameters:
msg – the
Messagethe response is related to.base_stream – the
InputStreamreturned by sending the request.
Methods#
- class MultipartInputStream
- get_headers() MessageHeaders | None#
Obtains the headers for the part currently being processed.
Note that the
MessageHeadersthat are returned are owned by theMultipartInputStreamand will be replaced when a call is made tonext_partor 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
MessageHeaderswill 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
MultipartInputStreamand this function or its async counterpart need to be called to obtain the first part for reading.After calling this function,
get_headerscan 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.errorwill only be set if an error happens during a read,Noneis a valid return value otherwise.- Parameters:
cancellable – a
Cancellable
- async next_part_async(self, io_priority: int) InputStream | None#
This is the awaitable version of
next_part_async().- Parameters:
io_priority – the I/O priority for the request.
- 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
InputStreamfor the next request.See
next_partfor 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.