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
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 |
Parameters | key | This is the key to use to request the object later. |
obj | The object to register. | |
help | Help 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. | |
info | More 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_existing | Raise 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). |
Parameters | key | This is the key to use to request the object later. |
module_name | The python path to the module. Such as 'os.path'. | |
member_name | The member of the module to return. If empty or None, get() will return the module itself. | |
help | Help text for this entry. This may be a string or a callable. | |
info | More 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_existing | If True, replace the existing object with the new one. If False, if there is already something registered with the same key, raise a KeyError |
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.
Parameters | key | The 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. |
Returns | The previously registered object. | |
Raises | ImportError | If the object was registered lazily, and there are problems during import. |
AttributeError | If registered lazily, and the module does not contain the registered member. |
Parameters | key | The key to obtain the module for. |
Returns | The name of the module |
Returns | a tuple of (object, remainder), where the remainder is the portion of the name that did not match the key. | |
Unknown Field: fullname | The name to find a prefix for |
This is mostly for the test suite, but it can be used by others