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

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

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