~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-05 04:05:05 UTC
  • mfrom: (3473.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080605040505-i9kqxg2fps2qjdi0
Add the 'alias' command (Tim Penhey)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import bzrlib
18
18
from bzrlib.smart import message, protocol
19
19
from bzrlib.trace import warning
20
 
from bzrlib import (
21
 
    errors,
22
 
    hooks,
23
 
    )
 
20
from bzrlib import errors
24
21
 
25
22
 
26
23
class _SmartClient(object):
53
50
            encoder.call(method, *args)
54
51
        return response_handler
55
52
 
56
 
    def _run_call_hooks(self, method, args, body, readv_body):
57
 
        if not _SmartClient.hooks['call']:
58
 
            return
59
 
        params = CallHookParams(method, args, body, readv_body, self._medium)
60
 
        for hook in _SmartClient.hooks['call']:
61
 
            hook(params)
62
 
            
63
53
    def _call_and_read_response(self, method, args, body=None, readv_body=None,
64
54
            expect_response_body=True):
65
 
        self._run_call_hooks(method, args, body, readv_body)
66
55
        if self._medium._protocol_version is not None:
67
56
            response_handler = self._send_request(
68
57
                self._medium._protocol_version, method, args, body=body,
72
61
                    response_handler)
73
62
        else:
74
63
            for protocol_version in [3, 2]:
75
 
                if protocol_version == 2:
76
 
                    # If v3 doesn't work, the remote side is older than 1.6.
77
 
                    self._medium._remember_remote_is_before((1, 6))
78
64
                response_handler = self._send_request(
79
65
                    protocol_version, method, args, body=body,
80
66
                    readv_body=readv_body)
174
160
        """
175
161
        return self._medium.remote_path_from_transport(transport)
176
162
 
177
 
 
178
 
class SmartClientHooks(hooks.Hooks):
179
 
 
180
 
    def __init__(self):
181
 
        hooks.Hooks.__init__(self)
182
 
        self['call'] = []
183
 
 
184
 
        
185
 
_SmartClient.hooks = SmartClientHooks()
186
 
 
187
 
 
188
 
class CallHookParams(object):
189
 
    
190
 
    def __init__(self, method, args, body, readv_body, medium):
191
 
        self.method = method
192
 
        self.args = args
193
 
        self.body = body
194
 
        self.readv_body = readv_body
195
 
        self.medium = medium
196
 
 
197
 
    def __repr__(self):
198
 
        attrs = dict((k, v) for (k, v) in self.__dict__.iteritems()
199
 
                     if v is not None)
200
 
        return '<%s %r>' % (self.__class__.__name__, attrs)
201
 
 
202
 
    def __eq__(self, other):
203
 
        if type(other) is not type(self):
204
 
            return NotImplemented
205
 
        return self.__dict__ == other.__dict__
206
 
 
207
 
    def __ne__(self, other):
208
 
        return not self == other