b.r.Registry(object) : class documentation

Part of bzrlib.registry View In Hierarchy

Known subclasses: bzrlib.bugtracker.TrackerRegistry, bzrlib.commands.CommandRegistry, bzrlib.commands.ProvidersRegistry, bzrlib.config.CredentialStoreRegistry, bzrlib.config.OptionRegistry, bzrlib.controldir.ControlDirFormatRegistry, bzrlib.directory_service.DirectoryServiceRegistry, bzrlib.help_topics.HelpTopicRegistry, bzrlib.hooks.KnownHooksRegistry, bzrlib.log.LogFormatterRegistry, bzrlib.option.MergeTypeRegistry, bzrlib.registry.FormatRegistry, bzrlib.serializer.SerializerRegistry, bzrlib.tests.TestPrefixAliasRegistry, bzrlib.transport.TransportListRegistry

A class that registers objects to a name.

There are many places that want to collect related objects and access them by a key. This class is designed to allow registering the mapping from key to object. It goes one step further, and allows registering a name to a hypothetical object which has not been imported yet. It also supports adding additional information at registration time so that decisions can be made without having to import the object (which may be expensive).

The functions 'get', 'get_info', and 'get_help' also support a 'default_key' (settable through my_registry.default_key = XXX, XXX must already be registered.) Calling my_registry.get() or my_registry.get(None), will return the entry for the default key.

Method __init__ Create a new Registry.
Method register Register a new object to a name.
Method register_lazy Register a new object to be loaded on request.
Method get Return the object register()'ed to the given key.
Method get_prefix Return an object whose key is a prefix of the supplied value.
Method get_help Get the help text associated with the given key
Method get_info Get the extra information associated with the given key
Method remove Remove a registered entry.
Method __contains__ Undocumented
Method keys Get a list of registered entries
Method iteritems Undocumented
Method items Undocumented
Method _add_help_and_info Add the help and information about this key
Method _get_module Return the module the object will be or was loaded from.
Method _get_key_or_default Return either 'key' or the default key if key is None
Method _set_default_key Undocumented
Method _get_default_key Undocumented
def __init__(self):
Create a new Registry.
def register(self, key, obj, help=None, info=None, override_existing=False):
Register a new object to a name.
ParameterskeyThis is the key to use to request the object later.
objThe object to register.
helpHelp text for this entry. This may be a string or a callable. If it is a callable, it should take two parameters (registry, key): this registry and the key that the help was registered under.
infoMore information for this entry. Registry.get_info() can be used to get this information. Registry treats this as an opaque storage location (it is defined by the caller).
override_existingRaise KeyErorr if False and something has already been registered for that key. If True, ignore if there is an existing key (always register the new value).
def register_lazy(self, key, module_name, member_name, help=None, info=None, override_existing=False):
Register a new object to be loaded on request.
ParameterskeyThis is the key to use to request the object later.
module_nameThe python path to the module. Such as 'os.path'.
member_nameThe member of the module to return. If empty or None, get() will return the module itself.
helpHelp text for this entry. This may be a string or a callable.
infoMore information for this entry. Registry.get_info() can be used to get this information. Registry treats this as an opaque storage location (it is defined by the caller).
override_existingIf True, replace the existing object with the new one. If False, if there is already something registered with the same key, raise a KeyError
def _add_help_and_info(self, key, help=None, info=None):
Add the help and information about this key
def get(self, key=None):
Return the object register()'ed to the given key.

May raise ImportError if the object was registered lazily and there are any problems, or AttributeError if the module does not have the supplied member.

ParameterskeyThe key to obtain the object for. If no object has been registered to that key, the object registered for self.default_key will be returned instead, if it exists. Otherwise KeyError will be raised.
ReturnsThe previously registered object.
RaisesImportErrorIf the object was registered lazily, and there are problems during import.
AttributeErrorIf registered lazily, and the module does not contain the registered member.
def _get_module(self, key):
Return the module the object will be or was loaded from.
ParameterskeyThe key to obtain the module for.
ReturnsThe name of the module
def get_prefix(self, fullname):
Return an object whose key is a prefix of the supplied value.
Returnsa tuple of (object, remainder), where the remainder is the portion of the name that did not match the key.
Unknown Field: fullnameThe name to find a prefix for
def _get_key_or_default(self, key=None):
Return either 'key' or the default key if key is None
def get_help(self, key=None):
Get the help text associated with the given key
def get_info(self, key=None):
Get the extra information associated with the given key
def remove(self, key):
Remove a registered entry.

This is mostly for the test suite, but it can be used by others

def __contains__(self, key):
Undocumented
def keys(self):
Get a list of registered entries
def iteritems(self):
Undocumented
def items(self):
Undocumented
def _set_default_key(self, key):
Undocumented
def _get_default_key(self):
Undocumented
API Documentation for Bazaar, generated by pydoctor at 2018-08-19 00:17:14.