/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 breezy/inter.py

  • Committer: Jelmer Vernooij
  • Date: 2017-09-01 07:15:43 UTC
  • mfrom: (6770.3.2 py3_test_cleanup)
  • Revision ID: jelmer@jelmer.uk-20170901071543-1t83321xkog9qrxh
Merge lp:~gz/brz/py3_test_cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Inter-object utility class."""
19
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from .errors import BzrError
 
22
from .lock import LogicalLockResult
 
23
 
 
24
 
 
25
class NoCompatibleInter(BzrError):
 
26
 
 
27
    _fmt = ('No compatible object available for operations from %(source)r '
 
28
            'to %(target)r.')
 
29
 
 
30
    def __init__(self, source, target):
 
31
        self.source = source
 
32
        self.target = target
 
33
 
20
34
 
21
35
class InterObject(object):
22
36
    """This class represents operations taking place between two objects.
75
89
                       the InterObject instance.
76
90
        :param target: the object to be the 'target' member of
77
91
                       the InterObject instance.
 
92
 
78
93
        If an optimised worker exists it will be used otherwise
79
94
        a default Inter worker instance will be created.
80
95
        """
81
96
        for provider in reversed(klass._optimisers):
82
97
            if provider.is_compatible(source, target):
83
98
                return provider(source, target)
84
 
        return klass(source, target)
 
99
        raise NoCompatibleInter(source, target)
85
100
 
86
101
    def lock_read(self):
87
102
        """Take out a logical read lock.
90
105
        a read lock and the target a read lock.
91
106
        """
92
107
        self._double_lock(self.source.lock_read, self.target.lock_read)
 
108
        return LogicalLockResult(self.unlock)
93
109
 
94
110
    def lock_write(self):
95
111
        """Take out a logical write lock.
98
114
        a read lock and the target a write lock.
99
115
        """
100
116
        self._double_lock(self.source.lock_read, self.target.lock_write)
 
117
        return LogicalLockResult(self.unlock)
101
118
 
102
119
    @classmethod
103
120
    def register_optimiser(klass, optimiser):