multipart

Module Contents

Classes

BadContentDispositionHeader()
BadContentDispositionParam()
MultipartResponseWrapper(self,resp,stream) Wrapper around the MultipartBodyReader.
BodyPartReader(self,boundary,headers,content) Multipart reader for single body part.
BodyPartReaderPayload(self,value,*args,**kwargs)
MultipartReader(self,headers,content) Multipart body reader.
MultipartWriter(self,subtype=”mixed”,boundary=None) Multipart body writer.
MultipartPayloadWriter(self,writer)

Functions

parse_content_disposition(header)
content_disposition_filename(params,name=”filename”)
class BadContentDispositionHeader
class BadContentDispositionParam
parse_content_disposition(header)
content_disposition_filename(params, name="filename")
class MultipartResponseWrapper(resp, stream)

Wrapper around the MultipartBodyReader.

It takes care about underlying connection and close it when it needs in.

__init__(resp, stream)
__aiter__()
__anext__()
at_eof()

Returns True when all response data had been read.

next()

Emits next multipart reader object.

release()

Releases the connection gracefully, reading all the content to the void.

class BodyPartReader(boundary, headers, content)

Multipart reader for single body part.

__init__(boundary, headers, content)
__aiter__()
__anext__()
next()
read()

Reads body part data.

decode: Decodes data following by encoding
method from Content-Encoding header. If it missed data remains untouched
read_chunk(size=chunk_size)

Reads body part content chunk of the specified size.

size: chunk size

_read_chunk_from_length(size)
_read_chunk_from_stream(size)
readline()

Reads body part by line by line.

release()

Like read(), but reads all the data to the void.

text()

Like read(), but assumes that body part contains text data.

json()

Like read(), but assumes that body parts contains JSON data.

form()

Like read(), but assumes that body parts contains form urlencoded data.

at_eof()

Returns True if the boundary was reached or False otherwise.

decode(data)

Decodes data according the specified Content-Encoding or Content-Transfer-Encoding headers value.

_decode_content(data)
_decode_content_transfer(data)
get_charset(default=None)

Returns charset parameter from Content-Type header or default.

name()

Returns name specified in Content-Disposition header or None if missed or header is malformed.

filename()

Returns filename specified in Content-Disposition header or None if missed or header is malformed.

class BodyPartReaderPayload(value, *args, **kwargs)
__init__(value, *args, **kwargs)
write(writer)
class MultipartReader(headers, content)

Multipart body reader.

__init__(headers, content)
__aiter__()
__anext__()
from_response(response)

Constructs reader instance from HTTP response.

Parameters:responseClientResponse instance
at_eof()

Returns True if the final boundary was reached or False otherwise.

next()

Emits the next multipart body part.

release()

Reads all the body parts to the void till the final boundary.

fetch_next_part()

Returns the next body part reader.

_get_part_reader(headers)

Dispatches the response by the Content-Type header, returning suitable reader instance.

Parameters:headers (dict) – Response headers
_get_boundary()
_readline()
_read_until_first_boundary()
_read_boundary()
_read_headers()
_maybe_release_last_part()

Ensures that the last read body part is read completely.

class MultipartWriter(subtype="mixed", boundary=None)

Multipart body writer.

__init__(subtype="mixed", boundary=None)
__enter__()
__exit__(exc_type, exc_val, exc_tb)
__iter__()
__len__()
_boundary_value()

Wrap boundary parameter value in quotes, if necessary.

Reads self.boundary and returns a unicode sting.

boundary()
append(obj, headers=None)
append_payload(payload)

Adds a new body part to multipart writer.

append_json(obj, headers=None)

Helper to append JSON part.

append_form(obj, headers=None)

Helper to append form urlencoded part.

size()

Size of the payload.

write(writer)

Write body.

class MultipartPayloadWriter(writer)
__init__(writer)
enable_encoding(encoding)
enable_compression(encoding="deflate")
write_eof()
write(chunk)