alexapy.aiohttp.multipart

Functions

alexapy.aiohttp.multipart.parse_content_disposition(header: Optional[str]) Tuple[Optional[str], Dict[str, str]]
alexapy.aiohttp.multipart.content_disposition_filename(params: Mapping[str, str], name: str = 'filename') Optional[str]

Classes

class alexapy.aiohttp.multipart.MultipartReader(headers: Mapping[str, str], content: alexapy.aiohttp.streams.StreamReader)

Multipart body reader.

Inheritance

Inheritance diagram of MultipartReader

at_eof() bool

Returns True if the final boundary was reached, false otherwise.

async fetch_next_part() Union[alexapy.aiohttp.multipart.MultipartReader, alexapy.aiohttp.multipart.BodyPartReader]

Returns the next body part reader.

classmethod from_response(response: ClientResponse) alexapy.aiohttp.multipart.MultipartResponseWrapper

Constructs reader instance from HTTP response.

Parameters

responseClientResponse instance

multipart_reader_cls = None

Multipart reader class, used to handle multipart/* body parts. None points to type(self)

async next() Optional[Union[alexapy.aiohttp.multipart.MultipartReader, alexapy.aiohttp.multipart.BodyPartReader]]

Emits the next multipart body part.

part_reader_cls

Body part reader class for non multipart/* content types.

alias of alexapy.aiohttp.multipart.BodyPartReader

async release() None

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

response_wrapper_cls

Response wrapper, used when multipart readers constructs from response.

alias of alexapy.aiohttp.multipart.MultipartResponseWrapper

class alexapy.aiohttp.multipart.MultipartWriter(subtype: str = 'mixed', boundary: Optional[str] = None)

Multipart body writer.

Inheritance

Inheritance diagram of MultipartWriter

append_form(obj: Union[Sequence[Tuple[str, str]], Mapping[str, str]], headers: Optional[multidict._abc.MultiMapping] = None) alexapy.aiohttp.payload.Payload

Helper to append form urlencoded part.

append_json(obj: Any, headers: Optional[multidict._abc.MultiMapping] = None) alexapy.aiohttp.payload.Payload

Helper to append JSON part.

append_payload(payload: alexapy.aiohttp.payload.Payload) alexapy.aiohttp.payload.Payload

Adds a new body part to multipart writer.

property size: Optional[int]

Size of the payload.

async write(writer: Any, close_boundary: bool = True) None

Write body.

class alexapy.aiohttp.multipart.BodyPartReader(boundary: bytes, headers: multidict._multidict.CIMultiDictProxy, content: alexapy.aiohttp.streams.StreamReader)

Multipart reader for single body part.

Inheritance

Inheritance diagram of BodyPartReader

at_eof() bool

Returns True if the boundary was reached or False otherwise.

decode(data: bytes) bytes

Decodes data.

Decoding is done according the specified Content-Encoding or Content-Transfer-Encoding headers value.

filename

Returns filename specified in Content-Disposition header.

Returns None if the header is missing or malformed.

async form(*, encoding: Optional[str] = None) List[Tuple[str, str]]

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

get_charset(default: str) str

Returns charset parameter from Content-Type header or default.

async json(*, encoding: Optional[str] = None) Optional[Dict[str, Any]]

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

name

Returns name specified in Content-Disposition header.

If the header is missing or malformed, returns None.

async read(*, decode: bool = False) bytes

Reads body part data.

decode: Decodes data following by encoding

method from Content-Encoding header. If it missed data remains untouched

async read_chunk(size: int = 8192) bytes

Reads body part content chunk of the specified size.

size: chunk size

async readline() bytes

Reads body part by line by line.

async release() None

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

async text(*, encoding: Optional[str] = None) str

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

Exceptions

exception alexapy.aiohttp.multipart.BadContentDispositionHeader

Inheritance

Inheritance diagram of BadContentDispositionHeader

exception alexapy.aiohttp.multipart.BadContentDispositionParam

Inheritance

Inheritance diagram of BadContentDispositionParam