107
107
:param obj: The object to register.
108
108
:param help: Help text for this entry. This may be a string or
109
109
a callable. If it is a callable, it should take two
110
parameters (registry, key): this registry and the key that
110
parameters (registry, key): this registry and the key that
111
111
the help was registered under.
112
112
:param info: More information for this entry. Registry.get_info()
113
113
can be used to get this information. Registry treats this as an
128
128
"""Register a new object to be loaded on request.
130
130
:param module_name: The python path to the module. Such as 'os.path'.
131
:param member_name: The member of the module to return. If empty or
131
:param member_name: The member of the module to return. If empty or
132
132
None, get() will return the module itself.
133
133
:param help: Help text for this entry. This may be a string or
135
:param info: More information for this entry. Registry
135
:param info: More information for this entry. Registry
136
136
:param override_existing: If True, replace the existing object
137
137
with the new one. If False, if there is already something
138
138
registered with the same key, raise a KeyError
152
152
"""Return the object register()'ed to the given key.
154
154
May raise ImportError if the object was registered lazily and
155
there are any problems, or AttributeError if the module does not
155
there are any problems, or AttributeError if the module does not
156
156
have the supplied member.
158
158
:param key: The key to obtain the object for. If no object has been
231
231
default_key = property(_get_default_key, _set_default_key,
232
232
doc="Current value of the default key."
233
233
" Can be set to any existing key.")
236
class FormatRegistry(Registry):
237
"""Registry specialised for handling formats."""
239
def __init__(self, other_registry=None):
240
Registry.__init__(self)
241
self._other_registry = other_registry
243
def register_lazy(self, key, module_name, member_name,
244
help=None, info=None,
245
override_existing=False):
246
# Overridden to allow capturing registrations to two seperate
247
# registries in a single call.
248
Registry.register_lazy(self, key, module_name, member_name,
249
help=help, info=info, override_existing=override_existing)
250
if self._other_registry is not None:
251
self._other_registry.register_lazy(key, module_name, member_name,
252
help=help, info=info, override_existing=override_existing)
254
def get(self, format_string):
255
r = Registry.get(self, format_string)