/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/registry.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-25 14:36:59 UTC
  • mfrom: (4048 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4049.
  • Revision ID: jelmer@samba.org-20090225143659-vx6cbqtmyicuzfyf
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
129
129
 
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
134
134
                a callable.
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.
153
153
 
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.
157
157
 
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.")
 
234
 
 
235
 
 
236
class FormatRegistry(Registry):
 
237
    """Registry specialised for handling formats."""
 
238
 
 
239
    def __init__(self, other_registry=None):
 
240
        Registry.__init__(self)
 
241
        self._other_registry = other_registry
 
242
 
 
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)
 
253
 
 
254
    def get(self, format_string):
 
255
        r = Registry.get(self, format_string)
 
256
        if callable(r):
 
257
            r = r()
 
258
        return r
 
259
 
 
260