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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
17
"""Inter-object utility class."""
19
from __future__ import absolute_import
21
from bzrlib.errors import NoCompatibleInter
21
24
class InterObject(object):
22
25
"""This class represents operations taking place between two objects.
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.
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).
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.)
46
49
def __init__(self, source, target):
47
50
"""Construct a default InterObject instance. Please use 'get'.
49
Only subclasses of InterObject should call
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.
78
82
If an optimised worker exists it will be used otherwise
79
83
a default Inter worker instance will be created.
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)
86
90
def lock_read(self):
87
91
"""Take out a logical read lock.