ways.parsing.registry module

Responsible for giving users the ability to swap Assets with other objects.

ASSET_FACTORY (dict[tuple[str]

dict[str]]: This dict should not be changed directly. You should use the functions in this module, instead.

It is a global dictionary that stores classes that are meant to swap for an Asset object. ASSET_FACTORY’s key is the hierarchy of the Context and its value is another dict, which looks like this:

‘class’: The class to swap for. ‘init’: A custom inititialization function for the class (if needed). ‘children’: If True, the class is used for all hierarchies that build off of the given hierarchy. If False, the class is only added to the given hierarchy.

ways.parsing.registry.get_asset_class(hierarchy)[source]

Get the class that is registered for a Context hierarchy.

ways.parsing.registry.get_asset_info(hierarchy)[source]

Get the class and initialization function for a Context hierarchy.

Parameters:hierarchy (tuple[str] or str) – The hierarchy to get the asset information of.
Returns:The class type and the function that is used to instantiate it.
Return type:tuple[classobj, callable]
ways.parsing.registry.make_default_init(class_type, *args, **kwargs)[source]

Just make the class type, normally.

ways.parsing.registry.register_asset_class(class_type, context, init=None, children=False)[source]

Change get_asset to return a different class, instead of an Asset.

The Asset class is useful but it may be too basic for some people’s purposes. If you have an existing class that you’d like to use with Ways,

Parameters:
  • class_type (classobj) – The new class to use, instead. context (str or ways.api.Context): The Context to apply our new class to.
  • init (callable, optional) – A function that will be used to create an instance of class_type. This variable is useful if you need to customize your class_type’s __init__ in a way that isn’t normal (A common example: If you want to create a class_type that does not pass context into its __init__, you can use this variable to catch and handle that).
  • children (bool, optional) – If True, this new class_type will be applied to child hierarchies as well as the given Context’s hierarchy. If False, it will only be applied for this Context. Default is False.
ways.parsing.registry.reset_asset_classes(hierarchies=())[source]

Clear out the class(es) that is registered under a given hierarchy.

Parameters:hierarchies (iter[tuple[str]]) – All of the hierarchies to remove custom Asset classes for. If nothing is given, all hierarchies will be cleared.