BasicRegistrationFactory#

class sunpy.util.datatype_factory_base.BasicRegistrationFactory(default_widget_type=None, additional_validation_functions=[], registry=None)[source]#

Bases: object

Generalized registerable factory type.

Widgets (classes) can be registered with an instance of this class. Arguments to the factory’s __call__ method are then passed to a function specified by the registered factory, which validates the input and returns a instance of the class that best matches the inputs.

registry#

Dictionary mapping classes (key) to function (value) which validates input.

Type:

dict

default_widget_type#

Class of the default widget.

Type:

type

validation_functions#

List of function names that are valid validation functions.

Type:

list of str

Parameters:
  • default_widget_type (type, optional) – Class of the default widget. Defaults to None.

  • additional_validation_functions (list of str, optional) – List of strings corresponding to additional validation function names. Defaults to list.

  • registry (dict, optional) – Dictionary mapping classes (key) to function (value) which validates input. Defaults to None.

Notes

  • A valid validation function must be a classmethod of the registered widget and it must return a bool.

Methods Summary

__call__(*args, **kwargs)

Method for running the factory.

register(WidgetType[, validation_function, ...])

Register a widget with the factory.

unregister(WidgetType)

Remove a widget from the factory's registry.

Methods Documentation

__call__(*args, **kwargs)[source]#

Method for running the factory.

Arguments args and kwargs are passed through to the validation function and to the constructor for the final type.

register(WidgetType, validation_function=None, is_default=False)[source]#

Register a widget with the factory.

If validation_function is not specified, tests WidgetType for existence of any function in in the list self.validation_functions, which is a list of strings which must be callable class attribute.

Parameters:
  • WidgetType (type) – Widget to register.

  • validation_function (function, optional) – Function to validate against. Defaults to None, which indicates that a classmethod in validation_functions is used. Defaults to None.

  • is_default (bool, optional) – Sets WidgetType to be the default widget. Defaults to False.

unregister(WidgetType)[source]#

Remove a widget from the factory’s registry.