mango.messages package

mango.messages.acl_message_pb2 module

Generated protocol buffer code.

class mango.messages.acl_message_pb2.ACLMessage

Bases: Message, Message

DESCRIPTOR = <google._upb._message.Descriptor object>

mango.messages.codecs module

This package imports the codecs that can be used for de- and encoding incoming and outgoing messages:

All codecs should implement the base class Codec.

Most of this code is taken and adapted from Stefan Scherfkes aiomas: https://gitlab.com/sscherfke/aiomas/

class mango.messages.codecs.Codec

Bases: object

Base class for all Codecs.

Subclasses must implement encode() and decode().

add_serializer(otype, serialize, deserialize)

Add methods to serialize and deserialize objects typed otype.

This can be used to de-/encode objects that the codec otherwise couldn’t encode.

serialize will receive the unencoded object and needs to return an encodable serialization of it.

deserialize will receive an objects representation and should return an instance of the original object.

decode(data)

Decode data from bytes to the original data structure.

deserialize_obj(obj_repr)

Deserialize the original object from obj_repr.

encode(data)

Encode the given data and return a bytes object.

serialize_obj(obj)

Serialize obj to something that the codec can encode.

exception mango.messages.codecs.DecodeError

Bases: Exception

Raised when an object representation can not be decoded.

class mango.messages.codecs.FastJSON

Bases: Codec

decode(data)

Decode data from bytes to the original data structure.

encode(data)

Encode the given data and return a bytes object.

class mango.messages.codecs.JSON

Bases: Codec

A Codec that uses JSON to encode and decode messages.

decode(data)

Decode data from bytes to the original data structure.

encode(data)

Encode the given data and return a bytes object.

class mango.messages.codecs.PROTOBUF

Bases: Codec

decode(data)

Decode data from bytes to the original data structure.

encode(data)

Encode the given data and return a bytes object.

register_proto_type(proto_class)
serialize_obj(obj)

Serialize obj to something that the codec can encode.

exception mango.messages.codecs.SerializationError

Bases: Exception

Raised when an object cannot be serialized.

mango.messages.codecs.json_serializable(cls=None, repr=True)

This is a direct copy from aiomas: https://gitlab.com/sscherfke/aiomas/-/blob/master/src/aiomas/codecs.py

Class decorator that makes the decorated class serializable by the json codec (or any codec that can handle python dictionaries).

The decorator tries to extract all arguments to the class’ __init__(). That means, the arguments must be available as attributes with the same name.

The decorator adds the following methods to the decorated class:

  • __asdict__(): Returns a dict with all __init__ parameters

  • __fromdict__(dict): Creates a new class instance from dict

  • __serializer__(): Returns a tuple with args for Codec.add_serializer()

  • __repr__(): Returns a generic instance representation. Adding this method can be deactivated by passing repr=False to the decorator.

mango.messages.message module

This module implements the ACLMessage class. The class is used to implement messages that are based on the FIPA ACL standard. http://www.fipa.org/specs/fipa00061/SC00061G.html#_Toc26669715

It also includes the enum classes for the message Performative and Type

class mango.messages.message.ACLMessage(*, sender_id=None, sender_addr=None, receiver_id=None, receiver_addr=None, reply_to=None, conversation_id=None, performative=None, content=None, protocol=None, language=None, encoding=None, ontology=None, reply_with=None, reply_by=None, in_reply_to=None)

Bases: object

The ACL Message is the standard header used for the communication between mango agents. This class is based on the FIPA ACL standard: http://www.fipa.org/specs/fipa00061/SC00061G.html

extract_meta() Dict[str, Any]
property message_dict
split_content_and_meta()
class mango.messages.message.Performatives(*values)

Bases: Enum

member values (must be unique) could be used as priority values if not replaced by enum.auto. See http://www.fipa.org/specs/fipa00037/SC00037J.html for a description of performatives.

accept_proposal = 1
agree = 2
call_for_proposal = 5
cancel = 3
cfp = 4
confirm = 6
disconfirm = 7
failure = 8
inform = 9
inform_if = 20
not_understood = 10
propagate = 22
propose = 11
proxy = 21
query_if = 12
query_ref = 13
refuse = 14
reject_proposal = 15
request = 16
request_when = 17
request_whenever = 18
subscribe = 19
mango.messages.message.enum_serializer(enum_cls)

mango.messages.other_proto_msgs_pb2 module

Generated protocol buffer code.

class mango.messages.other_proto_msgs_pb2.GenericMsg

Bases: Message, Message

DESCRIPTOR = <google._upb._message.Descriptor object>