coarnotify.factory

Factory for producing the correct model based on the type or data within a payload

Classes

COARNotifyFactory

Factory for producing the correct model based on the type or data within a payload

Module Contents

class coarnotify.factory.COARNotifyFactory

Factory for producing the correct model based on the type or data within a payload

classmethod get_by_object(data: dict, *args, **kwargs) coarnotify.core.notify.NotifyPattern

Get an instance of a model based on the data provided.

Internally this calls get_by_types to determine the class to instantiate, and then creates an instance of that Using the supplied args and kwargs.

If a model cannot be found that matches the data, a NotifyException is raised.

Parameters:
  • data – The raw stream data to parse and instantiate around

  • args – any args to pass to the object constructor

  • kwargs – any kwargs to pass to the object constructor

Returns:

A NotifyPattern of the correct type, wrapping the data

classmethod get_by_types(incoming_types: str | List[str]) Callable | None

Get the model class based on the supplied types. The returned callable is the class, not an instance.

This is achieved by inspecting all of the known types in MODELS, and performing the following calculation:

  1. If the supplied types are a subset of the model types, then this is a candidate, keep a reference to it

  2. If the candidate fit is exact (supplied types and model types are the same), return the class

  3. If the class is a better fit than the last candidate, update the candidate. If the fit is exact, return the class

  4. Once we have run out of models to check, return the best candidate (or None if none found)

Parameters:

incoming_types – a single type or list of types. If a list is provided, ALL types must match a candidate

Returns:

A class representing the best fit for the supplied types, or None if no match

classmethod register(model: coarnotify.core.notify.NotifyPattern)
MODELS

The list of model classes recognised by this factory