/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: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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.
32
46
 
33
47
    If the source and target objects implement the locking protocol -
34
48
    lock_read, lock_write, unlock, then the InterObject's lock_read,
35
 
    lock_write and unlock methods may be used (optionally in conjunction with
36
 
    the needs_read_lock and needs_write_lock decorators.)
 
49
    lock_write and unlock methods may be used.
37
50
 
38
51
    When looking for an inter, the most recently registered types are tested
39
52
    first.  So typically the most generic and slowest InterObjects should be
75
88
                       the InterObject instance.
76
89
        :param target: the object to be the 'target' member of
77
90
                       the InterObject instance.
 
91
 
78
92
        If an optimised worker exists it will be used otherwise
79
93
        a default Inter worker instance will be created.
80
94
        """
81
95
        for provider in reversed(klass._optimisers):
82
96
            if provider.is_compatible(source, target):
83
97
                return provider(source, target)
84
 
        return klass(source, target)
 
98
        raise NoCompatibleInter(source, target)
85
99
 
86
100
    def lock_read(self):
87
101
        """Take out a logical read lock.
90
104
        a read lock and the target a read lock.
91
105
        """
92
106
        self._double_lock(self.source.lock_read, self.target.lock_read)
 
107
        return LogicalLockResult(self.unlock)
93
108
 
94
109
    def lock_write(self):
95
110
        """Take out a logical write lock.
98
113
        a read lock and the target a write lock.
99
114
        """
100
115
        self._double_lock(self.source.lock_read, self.target.lock_write)
 
116
        return LogicalLockResult(self.unlock)
101
117
 
102
118
    @classmethod
103
119
    def register_optimiser(klass, optimiser):