ways.base.factory module

The main class that is used to create and store Context instances.

This setup is what makes ways.api.Context objects into flyweight objects.

Todo

Remove this class. It could just be a list with functions.

class ways.base.factory.AliasAssignmentFactory(class_type)[source]

Bases: ways.base.factory._AssignmentFactory

Extend the _AssignmentFactory object to include Context aliases.

clear()[source]

Remove all the stored aliases in this instance.

get_instance(hierarchy, assignment, follow_alias=False, force=False)[source]

Get an instance of our class if it exists and make it if does not.

Parameters:
  • hierarchy (tuple[str] or str) – The location to look for our instance.
  • assignment (str) – The category/grouping of the instance.
  • follow_alias (bool, optional) – If True, the instance’s hierarchy is assumed to be an alias for another hierarchy and the returned instance will use the “real” hierarchy. If False, the instance will stay as the aliased hierarchy, completely unmodified. Default is False.
  • force (bool, optional) – If False and the Context has no plugins, return None. If True, an empty Context is returned. Default is False.
Returns:

An instance of our preferred class. If the Context that is called does not have any Plugin objects defined for it, it’s considered ‘empty’. To avoid problems in our code later, we return None, by default unless force is True.

Return type:

self._class_type() or NoneType

is_aliased(hierarchy)[source]

bool: If this hierarchy is an alias for another hierarchy.

resolve_alias(hierarchy)[source]

Assuming that the given hierarchy is an alias, follow the alias.

Parameters:hierarchy (tuple[str] or str) – The location to look for our instance. In this method, hierarchy is expected to be an alias for another hierarchy so we look for the real hierarchy, here.
Returns:The base hierarchy that this alias is meant to represent.
Return type:tuple[str]