/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/multiparent.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-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
76
76
class MultiParent(object):
77
77
    """A multi-parent diff"""
78
78
 
 
79
    __slots__ = ['hunks']
 
80
 
79
81
    def __init__(self, hunks=None):
80
82
        if hunks is not None:
81
83
            self.hunks = hunks
258
260
class NewText(object):
259
261
    """The contents of text that is introduced by this text"""
260
262
 
 
263
    __slots__ = ['lines']
 
264
 
261
265
    def __init__(self, lines):
262
266
        self.lines = lines
263
267
 
279
283
class ParentText(object):
280
284
    """A reference to text present in a parent text"""
281
285
 
 
286
    __slots__ = ['parent', 'parent_pos', 'child_pos', 'num_lines']
 
287
 
282
288
    def __init__(self, parent, parent_pos, child_pos, num_lines):
283
289
        self.parent = parent
284
290
        self.parent_pos = parent_pos
285
291
        self.child_pos = child_pos
286
292
        self.num_lines = num_lines
287
293
 
 
294
    def _as_dict(self):
 
295
        return dict(parent=self.parent, parent_pos=self.parent_pos,
 
296
                    child_pos=self.child_pos, num_lines=self.num_lines)
 
297
 
288
298
    def __repr__(self):
289
 
        return 'ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'\
290
 
            ' %(num_lines)r)' % self.__dict__
 
299
        return ('ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'
 
300
                ' %(num_lines)r)' % self._as_dict())
291
301
 
292
302
    def __eq__(self, other):
293
303
        if self.__class__ is not other.__class__:
294
304
            return False
295
 
        return (self.__dict__ == other.__dict__)
 
305
        return self._as_dict() == other._as_dict()
296
306
 
297
307
    def to_patch(self):
298
 
        yield 'c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'\
299
 
            % self.__dict__
 
308
        yield ('c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
 
309
               % self._as_dict())
300
310
 
301
311
 
302
312
class BaseVersionedFile(object):