MappingFactory

class lsst.daf.butler.MappingFactory(refType)

Bases: object

Register the mapping of some key to a python type and retrieve instances.

Enables instances of these classes to be retrieved from the factory later. The class can be specified as an object, class or string. If the key is an object it is converted to a string by accessing a name attribute.

Parameters
refTypetype

Python reference type to use to ensure that items stored in the registry create instance objects of the correct class. Subclasses of this type are allowed. Using None disables the check.

Methods Summary

getClassFromRegistry(targetClasses, *args, …)

Get the matching class stored in the registry.

getClassFromRegistryWithMatch(targetClasses)

Get the class stored in the registry along with the matching key.

getFromRegistry(targetClasses, *args, **kwargs)

Get a new instance of the object stored in the registry.

getFromRegistryWithMatch(targetClasses, …)

Get a new instance of the object stored in the registry along with the matching key.

getLookupKeys()

Retrieve the look up keys for all the registry entries.

placeInRegistry(registryKey, typeName)

Register a class name with the associated type.

Methods Documentation

getClassFromRegistry(targetClasses, *args, **kwargs)

Get the matching class stored in the registry.

Parameters
targetClassesLookupKey, str or objects with name attribute

Each item is tested in turn until a match is found in the registry. Items with None value are skipped.

Returns
clstype

Class stored in registry associated with the first matching target class.

Raises
KeyError

Raised if none of the supplied target classes match an item in the registry.

getClassFromRegistryWithMatch(targetClasses)

Get the class stored in the registry along with the matching key.

Parameters
targetClassesLookupKey, str or objects with name attribute

Each item is tested in turn until a match is found in the registry. Items with None value are skipped.

Returns
matchKeyLookupKey

The key that resulted in the successful match.

clstype

Class stored in registry associated with the first matching target class.

Raises
KeyError

Raised if none of the supplied target classes match an item in the registry.

getFromRegistry(targetClasses, *args, **kwargs)

Get a new instance of the object stored in the registry.

Parameters
targetClassesLookupKey, str or objects with name attribute

Each item is tested in turn until a match is found in the registry. Items with None value are skipped.

argstuple

Positional arguments to use pass to the object constructor.

kwargsdict

Keyword arguments to pass to object constructor.

Returns
instanceobject

Instance of class stored in registry associated with the first matching target class.

Raises
KeyError

Raised if none of the supplied target classes match an item in the registry.

getFromRegistryWithMatch(targetClasses, *args, **kwargs)

Get a new instance of the object stored in the registry along with the matching key.

Parameters
targetClassesLookupKey, str or objects with name attribute

Each item is tested in turn until a match is found in the registry. Items with None value are skipped.

argstuple

Positional arguments to use pass to the object constructor.

kwargsdict

Keyword arguments to pass to object constructor.

Returns
matchKeyLookupKey

The key that resulted in the successful match.

instanceobject

Instance of class stored in registry associated with the first matching target class.

Raises
KeyError

Raised if none of the supplied target classes match an item in the registry.

getLookupKeys()

Retrieve the look up keys for all the registry entries.

Returns
keysset of LookupKey

The keys available for matching in the registry.

placeInRegistry(registryKey, typeName)

Register a class name with the associated type.

Parameters
registryKeyLookupKey, str or object with name attribute.

Item to associate with the provided type.

typeNamestr or Python type

Identifies a class to associate with the provided key.

Raises
KeyError

Raised if item is already registered and has different value.