aiocoap.blockwise module

Helpers for the implementation of RFC7959 blockwise transfers

exception aiocoap.blockwise.ContinueException(block1)

Bases: aiocoap.error.ConstructionRenderableError

Not an error in the CoAP sense, but an error in the processing sense, indicating that no complete request message is available for processing.

It reflects back the request’s block1 option when rendered.

to_message()

Create a CoAP message that should be sent when this exception is rendered

code = <Successful Response Code 95 "2.31 Continue">
exception aiocoap.blockwise.IncompleteException(message=None)

Bases: aiocoap.error.ConstructionRenderableError

code = <Response Code 136 "4.08 Request Entity Incomplete">
class aiocoap.blockwise.Block1Spool

Bases: object

feed_and_take(req: aiocoap.message.Message) → aiocoap.message.Message

Assemble the request into the spool. This either produces a reassembled request message, or raises either a Continue or a Request Entity Incomplete exception.

Requests without block1 are simply passed through.

class aiocoap.blockwise.Block2Cache

Bases: object

A cache of responses to a give block key.

Use this when result rendering is expensive, not idempotent or has varying output – otherwise it’s often better to calculate the full response again and serve chunks.

extract_or_insert(req: aiocoap.message.Message, response_builder: coroutine)

Given a request message,

  • if it is querying a particular block, look it up in the cache or raise Request Entity Incomplete.
  • otherwise, * await the response builder * return the response if it doesn’t need chunking, or * return the first chunk and store it for later use