~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/registry.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-23 15:29:35 UTC
  • mfrom: (3943.7.7 bzr.code_style_cleanup)
  • mto: This revision was merged to the branch mainline in revision 4033.
  • Revision ID: john@arbash-meinel.com-20090223152935-oel9m92mwcc6nb4h
Merge the removal of all trailing whitespace, and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Classes to provide name-to-object registry-like support."""
18
18
 
62
62
        return super(_LazyObjectGetter, self).get_obj()
63
63
 
64
64
    def _do_import(self):
65
 
        if self._member_name:
66
 
            segments = self._member_name.split('.')
67
 
            names = segments[0:1]
68
 
        else:
69
 
            names = [self._member_name]
70
 
        obj = __import__(self._module_name, globals(), locals(), names)
71
 
        if self._member_name:
72
 
            for segment in segments:
73
 
                obj = getattr(obj, segment)
 
65
        obj = __import__(self._module_name, globals(), locals(),
 
66
                         [self._member_name])
 
67
        if self._member_name:
 
68
            obj = getattr(obj, self._member_name)
74
69
        self._obj = obj
75
70
        self._imported = True
76
71
 
222
217
            yield key, getter.get_obj()
223
218
 
224
219
    def items(self):
225
 
        # We should not use the iteritems() implementation below (see bug
226
 
        # #430510)
227
 
        return sorted([(key, getter.get_obj())
228
 
                       for key, getter in self._dict.items()])
 
220
        return sorted(self.iteritems())
229
221
 
230
222
    def _set_default_key(self, key):
231
223
        if not self._dict.has_key(key):
239
231
    default_key = property(_get_default_key, _set_default_key,
240
232
                            doc="Current value of the default key."
241
233
                                " Can be set to any existing key.")
242
 
 
243
 
 
244
 
class FormatRegistry(Registry):
245
 
    """Registry specialised for handling formats."""
246
 
 
247
 
    def __init__(self, other_registry=None):
248
 
        Registry.__init__(self)
249
 
        self._other_registry = other_registry
250
 
 
251
 
    def register_lazy(self, key, module_name, member_name,
252
 
                      help=None, info=None,
253
 
                      override_existing=False):
254
 
        # Overridden to allow capturing registrations to two seperate
255
 
        # registries in a single call.
256
 
        Registry.register_lazy(self, key, module_name, member_name,
257
 
                help=help, info=info, override_existing=override_existing)
258
 
        if self._other_registry is not None:
259
 
            self._other_registry.register_lazy(key, module_name, member_name,
260
 
                help=help, info=info, override_existing=override_existing)
261
 
 
262
 
    def get(self, format_string):
263
 
        r = Registry.get(self, format_string)
264
 
        if callable(r):
265
 
            r = r()
266
 
        return r
267
 
 
268