~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/registry.py

  • Committer: Martin Pool
  • Date: 2011-01-20 23:07:25 UTC
  • mfrom: (5626 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5630.
  • Revision ID: mbp@canonical.com-20110120230725-12l7ltnko5x3fgnz
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
42
38
    def get_obj(self):
43
39
        """Get the object that was saved at creation time"""
44
40
        return self._obj
58
54
        self._imported = False
59
55
        super(_LazyObjectGetter, self).__init__(None)
60
56
 
61
 
    def get_module(self):
62
 
        """Get the module the referenced object will be loaded from.
63
 
        """
64
 
        return self._module_name
65
 
 
66
57
    def get_obj(self):
67
58
        """Get the referenced object.
68
59
 
132
123
                      override_existing=False):
133
124
        """Register a new object to be loaded on request.
134
125
 
135
 
        :param key: This is the key to use to request the object later.
136
126
        :param module_name: The python path to the module. Such as 'os.path'.
137
127
        :param member_name: The member of the module to return.  If empty or
138
128
                None, get() will return the module itself.
139
129
        :param help: Help text for this entry. This may be a string or
140
130
                a callable.
141
 
        :param info: More information for this entry. Registry.get_info()
142
 
                can be used to get this information. Registry treats this as an
143
 
                opaque storage location (it is defined by the caller).
 
131
        :param info: More information for this entry. Registry
144
132
        :param override_existing: If True, replace the existing object
145
133
                with the new one. If False, if there is already something
146
134
                registered with the same key, raise a KeyError
175
163
        """
176
164
        return self._dict[self._get_key_or_default(key)].get_obj()
177
165
 
178
 
    def _get_module(self, key):
179
 
        """Return the module the object will be or was loaded from.
180
 
 
181
 
        :param key: The key to obtain the module for.
182
 
        :return: The name of the module
183
 
        """
184
 
        return self._dict[key].get_module()
185
 
 
186
166
    def get_prefix(self, fullname):
187
167
        """Return an object whose key is a prefix of the supplied value.
188
168
 
259
239
        Registry.__init__(self)
260
240
        self._other_registry = other_registry
261
241
 
262
 
    def register(self, key, obj, help=None, info=None,
263
 
                 override_existing=False):
264
 
        Registry.register(self, key, obj, help=help, info=info,
265
 
            override_existing=override_existing)
266
 
        if self._other_registry is not None:
267
 
            self._other_registry.register(key, obj, help=help,
268
 
                info=info, override_existing=override_existing)
269
 
 
270
242
    def register_lazy(self, key, module_name, member_name,
271
243
                      help=None, info=None,
272
244
                      override_existing=False):
278
250
            self._other_registry.register_lazy(key, module_name, member_name,
279
251
                help=help, info=info, override_existing=override_existing)
280
252
 
281
 
    def remove(self, key):
282
 
        Registry.remove(self, key)
283
 
        if self._other_registry is not None:
284
 
            self._other_registry.remove(key)
285
 
 
286
253
    def get(self, format_string):
287
254
        r = Registry.get(self, format_string)
288
255
        if callable(r):
289
256
            r = r()
290
257
        return r
 
258
 
 
259