~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inter.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
16
 
18
17
"""Inter-object utility class."""
19
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from bzrlib.errors import NoCompatibleInter
 
22
 
20
23
 
21
24
class InterObject(object):
22
25
    """This class represents operations taking place between two objects.
23
26
 
24
27
    Its instances have methods like join or copy_content or fetch, and contain
25
 
    references to the source and target objects these operations can be 
 
28
    references to the source and target objects these operations can be
26
29
    carried out between.
27
30
 
28
31
    Often we will provide convenience methods on the objects which carry out
29
32
    operations with another of similar type - they will always forward to
30
 
    a subclass of InterObject - i.e. 
 
33
    a subclass of InterObject - i.e.
31
34
    InterVersionedFile.get(other).method_name(parameters).
32
35
 
33
 
    If the source and target objects implement the locking protocol - 
 
36
    If the source and target objects implement the locking protocol -
34
37
    lock_read, lock_write, unlock, then the InterObject's lock_read,
35
38
    lock_write and unlock methods may be used (optionally in conjunction with
36
39
    the needs_read_lock and needs_write_lock decorators.)
45
48
 
46
49
    def __init__(self, source, target):
47
50
        """Construct a default InterObject instance. Please use 'get'.
48
 
        
49
 
        Only subclasses of InterObject should call 
 
51
 
 
52
        Only subclasses of InterObject should call
50
53
        InterObject.__init__ - clients should call InterFOO.get where FOO
51
54
        is the base type of the objects they are interacting between. I.e.
52
55
        InterVersionedFile or InterRepository.
75
78
                       the InterObject instance.
76
79
        :param target: the object to be the 'target' member of
77
80
                       the InterObject instance.
 
81
 
78
82
        If an optimised worker exists it will be used otherwise
79
83
        a default Inter worker instance will be created.
80
84
        """
81
85
        for provider in reversed(klass._optimisers):
82
86
            if provider.is_compatible(source, target):
83
87
                return provider(source, target)
84
 
        return klass(source, target)
 
88
        raise NoCompatibleInter(source, target)
85
89
 
86
90
    def lock_read(self):
87
91
        """Take out a logical read lock.