~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

Merge bzr.dev.

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 errors
 
20
from bzrlib import (
 
21
    errors,
 
22
    hooks,
 
23
    )
21
24
 
22
25
 
23
26
class _SmartClient(object):
50
53
            encoder.call(method, *args)
51
54
        return response_handler
52
55
 
 
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)
 
60
        for hook in _SmartClient.hooks['call']:
 
61
            hook(params)
 
62
            
53
63
    def _call_and_read_response(self, method, args, body=None, readv_body=None,
54
64
            expect_response_body=True):
 
65
        self._run_call_hooks(method, args, body, readv_body)
55
66
        if self._medium._protocol_version is not None:
56
67
            response_handler = self._send_request(
57
68
                self._medium._protocol_version, method, args, body=body,
163
174
        """
164
175
        return self._medium.remote_path_from_transport(transport)
165
176
 
 
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):
 
191
        self.method = method
 
192
        self.args = args
 
193
        self.body = body
 
194
        self.readv_body = readv_body
 
195
 
 
196
    def __repr__(self):
 
197
        attrs = dict((k, v) for (k, v) in self.__dict__.iteritems()
 
198
                     if v is not None)
 
199
        return '<%s %r>' % (self.__class__.__name__, attrs)
 
200
 
 
201
    def __eq__(self, other):
 
202
        if type(other) is not type(self):
 
203
            return NotImplemented
 
204
        return self.__dict__ == other.__dict__
 
205
 
 
206
    def __ne__(self, other):
 
207
        return not self == other