ways.base.connection module

A module that has a strategies for resolving Context/Plugin conflicts.

Depending on the Context object’s attributes, it may be best to return a compound of all of the Context object’s plugins, or the first-defined one or maybe the last defined Plugin object’s value or even some other, special behavior.

The point is, whatever the strategy is, this module contains all of the different ways that a Context object’s Plugin’s values ‘resolve’ into a single output.

Note

In all cases, the plugins that are given to these functions are assumed to be in ‘ascending’ order. In other words, the 0th index of plugins is the oldest plugin and the -1 index is the latest plugin.

ways.base.connection.generic_iadd(obj, other)[source]

Unify the different ways that built-in Python objects implement iadd.

It’s important to note that this method is very generic and also unfinished. Feel free to add any other others, as needed. As long as they return a non-None value when successful and a None value when unsuccessful, any method is okay to use. (The logic for the non-None/None can be changed, too).

Parameters:
  • obj – Some object to add.
  • other – An object to add into obj.
Returns:

The value that obj removes once other is added into it.

ways.base.connection.get_intersection_priority(plugins, method)[source]

Get only the common elements from all plugin Objects and return them.

Note

Right now this function is only needed for get_groups() but could be abstracted if necessary, later.

Parameters:plugins (list[ways.api.Plugin]) – The plugins to get the the intersected values from.
Returns:The intersected value from all of the given Plugin objects.
ways.base.connection.get_left_right_priority(plugins, method)[source]

Add all values of all plugins going from start to finish (left to right).

Parameters:
  • plugins (list[ways.api.Plugin]) – The plugins to get the the values from.
  • method (callable[ways.api.Plugin]) – The callable function to get some value from a Plugin object.
Returns:

The compound value that was created from all of the plugins.

ways.base.connection.get_right_most_priority(plugins, method)[source]

Get the most-latest value of the given plugins.

Note

If a Plugin runs method() successfully but gives a value that returns False (like ‘’, or dict(), or [], etc), keep searching until an explicit value is found.

Parameters:
  • plugins (list[ways.api.Plugin]) – The plugins to get the the values from.
  • method (callable[ways.api.Plugin]) – The callable function to use to call some value from a Plugin object.
Raises:

NotImplementedError – If the given method has no implementation in all of the given Plugin objects or if the output value would have been None.

Returns:

The output type of the given method.

ways.base.connection.try_and_return(methods)[source]

Try every given method until one of them passes and returns some value.

Parameters:methods (iterable[callable]) – Functions that takes no arguments to run.
Returns:The output of the first method to execute successfully or None.