aiobtclientapi.response

API Response

Classes

class aiobtclientapi.response.Response(*, success, warnings=(), errors=(), tasks=(), **kwargs)[source]

Bases: SimpleNamespace

Response to API call

API methods of APIBase subclasses return an instance of this class.

Parameters:
  • success (bool) – Whether the API call was successfull

  • warnings – Sequence of Warning exceptions

  • errors – Sequence of Error exceptions

  • tasks – Sequence of Task instances

Any other keyword arguments are made available as attributes. Custom reponse attributes should be documented by the relevant API methods.

property as_dict

Provide attributes as dictionary

async classmethod from_call(call, attributes=None, types=None, exception=None)[source]

Create Response instance from asynchronous call

Parameters:
  • call

    Coroutine or asynchronous generator

    call may return, yield or raise:

    (attribute, value)

    attribute must be a valid attribute name and value is assigned/appended to that attribute.

    Error instance

    Errors are appended to the errors attribute. success is set to False.

    Warning instance

    Warnings are appended to the warnings attribute. success is kept as it is.

    Task

    Background tasks initiated by call are appended to tasks so they can be awaited if needed.

    NotImplementedError instance

    Indicates an unimplemented feature. The exception is wrapped in NotImplementedError and appended to errors.

    BaseException instance

    All exceptions not documented above are re-raised.

  • attributes

    Mapping of custom attributes to default values

    If the default value is a list, values from call for that attribute are appended to that list instead of replacing it.

  • types

    Mapping of custom attributes to classes

    If an attribute’s value is not an instance of its class, it is instantiated as its class.

    For sequence attributes, each item is handled as described above.

    Attributes that don’t have a type are taken as they are.

  • exception – Exception class that wraps every item in errors or None