~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/registry.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-18 04:55:00 UTC
  • mfrom: (5784.2.1 754188-apport-test)
  • Revision ID: pqm@pqm.ubuntu.com-20110418045500-ce6lkgyiq7f47q43
(mbp) Rewrite test_report_bug_legacy away from using doctest (see bug
 764188) (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
35
35
    def __init__(self, obj):
36
36
        self._obj = obj
37
37
 
 
38
    def get_module(self):
 
39
        """Get the module the object was loaded from."""
 
40
        return self._obj.__module__
 
41
 
38
42
    def get_obj(self):
39
43
        """Get the object that was saved at creation time"""
40
44
        return self._obj
54
58
        self._imported = False
55
59
        super(_LazyObjectGetter, self).__init__(None)
56
60
 
 
61
    def get_module(self):
 
62
        """Get the module the referenced object will be loaded from.
 
63
        """
 
64
        return self._module_name
 
65
 
57
66
    def get_obj(self):
58
67
        """Get the referenced object.
59
68
 
163
172
        """
164
173
        return self._dict[self._get_key_or_default(key)].get_obj()
165
174
 
 
175
    def _get_module(self, key):
 
176
        """Return the module the object will be or was loaded from.
 
177
 
 
178
        :param key: The key to obtain the module for.
 
179
        :return: The name of the module
 
180
        """
 
181
        return self._dict[key].get_module()
 
182
 
166
183
    def get_prefix(self, fullname):
167
184
        """Return an object whose key is a prefix of the supplied value.
168
185
 
239
256
        Registry.__init__(self)
240
257
        self._other_registry = other_registry
241
258
 
 
259
    def register(self, key, obj, help=None, info=None,
 
260
                 override_existing=False):
 
261
        Registry.register(self, key, obj, help=help, info=info,
 
262
            override_existing=override_existing)
 
263
        if self._other_registry is not None:
 
264
            self._other_registry.register(key, obj, help=help,
 
265
                info=info, override_existing=override_existing)
 
266
 
242
267
    def register_lazy(self, key, module_name, member_name,
243
268
                      help=None, info=None,
244
269
                      override_existing=False):
250
275
            self._other_registry.register_lazy(key, module_name, member_name,
251
276
                help=help, info=info, override_existing=override_existing)
252
277
 
 
278
    def remove(self, key):
 
279
        Registry.remove(self, key)
 
280
        if self._other_registry is not None:
 
281
            self._other_registry.remove(key)
 
282
 
253
283
    def get(self, format_string):
254
284
        r = Registry.get(self, format_string)
255
285
        if callable(r):
256
286
            r = r()
257
287
        return r
258
 
 
259