/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: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

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
 
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
 
123
132
                      override_existing=False):
124
133
        """Register a new object to be loaded on request.
125
134
 
 
135
        :param key: This is the key to use to request the object later.
126
136
        :param module_name: The python path to the module. Such as 'os.path'.
127
137
        :param member_name: The member of the module to return.  If empty or
128
138
                None, get() will return the module itself.
129
139
        :param help: Help text for this entry. This may be a string or
130
140
                a callable.
131
 
        :param info: More information for this entry. Registry
 
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).
132
144
        :param override_existing: If True, replace the existing object
133
145
                with the new one. If False, if there is already something
134
146
                registered with the same key, raise a KeyError
163
175
        """
164
176
        return self._dict[self._get_key_or_default(key)].get_obj()
165
177
 
 
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
 
166
186
    def get_prefix(self, fullname):
167
187
        """Return an object whose key is a prefix of the supplied value.
168
188
 
239
259
        Registry.__init__(self)
240
260
        self._other_registry = other_registry
241
261
 
 
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
 
242
270
    def register_lazy(self, key, module_name, member_name,
243
271
                      help=None, info=None,
244
272
                      override_existing=False):
250
278
            self._other_registry.register_lazy(key, module_name, member_name,
251
279
                help=help, info=info, override_existing=override_existing)
252
280
 
 
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
 
253
286
    def get(self, format_string):
254
287
        r = Registry.get(self, format_string)
255
288
        if callable(r):
256
289
            r = r()
257
290
        return r
258
 
 
259