eventbus.util package

Submodules

eventbus.util.hashing module

eventbus.util.hashing.hash_object(json_encoder: eventbus.util.transcoding.ObjectJSONEncoder, obj: dict) → str[source]

Calculates SHA-256 hash of JSON encoded ‘obj’.

eventbus.util.topic module

eventbus.util.topic.get_entity(event: TEvent) → TEntity[source]

Get Originator Entity by event.

To support get_entity, event should provice originator_topic and __entity_kwargs__ properties Only Created event supports this protocol out of the box

Parameters:event – Domain event
Returns:Domain entity
eventbus.util.topic.get_topic(domain_class: type) → str[source]

Returns a string describing a class.

Parameters:domain_class – A class.
Returns:A string describing the class.
eventbus.util.topic.resolve_attr(obj: Any, path: str) → Any[source]

A recursive version of getattr for navigating dotted paths.

Parameters:
  • obj – An object for which we want to retrieve a nested attribute.
  • path – A dot separated string containing zero or more attribute names.
Raises:

AttributeError – If there is no such attribute.

Returns:

The attribute referred to by the path.

eventbus.util.topic.resolve_topic(topic: str) → Any[source]

Resolves topic to the object it references.

Parameters:topic – A string describing a code object (e.g. an object class).
Raises:TopicResolutionError – If there is no such class.
Returns:Code object that the topic references.

eventbus.util.transcoding module

class eventbus.util.transcoding.ObjectJSONDecoder(object_hook=None, **kwargs)[source]

Bases: json.decoder.JSONDecoder

class eventbus.util.transcoding.ObjectJSONEncoder(sort_keys=False)[source]

Bases: json.encoder.JSONEncoder

encode(o) → bytes[source]

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
encode_container(o)[source]
encode_deque(o)[source]
encode_dict(o)[source]
encode_dict_state(o)[source]
encode_frozenset(o)[source]
encode_instance(o)[source]
encode_iterable(o)[source]
encode_list(o)[source]
encode_object(o)[source]
encode_set(o)[source]
encode_tuple(o)[source]
eventbus.util.transcoding.b64str_from_bytes(value: bytes) → str[source]
eventbus.util.transcoding.bytes_from_b64str(value)[source]
eventbus.util.transcoding.decode_bytes(d)[source]
eventbus.util.transcoding.decode_date(d)[source]
eventbus.util.transcoding.decode_datetime(d)[source]
eventbus.util.transcoding.decode_decimal(d)[source]
eventbus.util.transcoding.decode_deque(d)[source]
eventbus.util.transcoding.decode_dict(d)[source]
eventbus.util.transcoding.decode_enum(d)[source]
eventbus.util.transcoding.decode_frozenset(d)[source]
eventbus.util.transcoding.decode_object(d)[source]
eventbus.util.transcoding.decode_set(d)[source]
eventbus.util.transcoding.decode_time(d)[source]
eventbus.util.transcoding.decode_tuple(d)[source]
eventbus.util.transcoding.decode_type(d)[source]
eventbus.util.transcoding.decode_uuid(d)[source]
eventbus.util.transcoding.decoder(d)[source]
eventbus.util.transcoding.decoderpolicy(arg=None)[source]

Decorator for decoder policy.

Allows default behaviour to be built up from methods registered for different named keys, rather than chain of “in dict” queries in a long if-else block.

eventbus.util.transcoding.encode_bytes(o)[source]
eventbus.util.transcoding.encode_date(obj)[source]
eventbus.util.transcoding.encode_datetime(obj)[source]
eventbus.util.transcoding.encode_decimal(obj)[source]
eventbus.util.transcoding.encode_enum(obj)[source]
eventbus.util.transcoding.encode_function(o)[source]
eventbus.util.transcoding.encode_method(o)[source]
eventbus.util.transcoding.encode_time(obj)[source]
eventbus.util.transcoding.encode_type(o)[source]
eventbus.util.transcoding.encode_uuid(obj)[source]
eventbus.util.transcoding.encoder(o)[source]
eventbus.util.transcoding.encoderpolicy(arg=None)[source]

Decorator for encoder policy.

Allows default behaviour to be built up from methods registered for different types of things, rather than chain of isinstance() calls in a long if-else block.

Module contents