~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Robert Collins
  • Date: 2009-02-20 08:26:50 UTC
  • mto: This revision was merged to the branch mainline in revision 4028.
  • Revision ID: robertc@robertcollins.net-20090220082650-wmzch4en338bymkm
Cherrypick and polish the RemoteSink for streaming push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import bzrlib
18
18
from bzrlib.smart import message, protocol
36
36
        else:
37
37
            self._headers = dict(headers)
38
38
 
39
 
    def __repr__(self):
40
 
        return '%s(%r)' % (self.__class__.__name__, self._medium)
41
 
 
42
39
    def _send_request(self, protocol_version, method, args, body=None,
43
40
                      readv_body=None, body_stream=None):
44
41
        encoder, response_handler = self._construct_protocol(
69
66
        params = CallHookParams(method, args, body, readv_body, self._medium)
70
67
        for hook in _SmartClient.hooks['call']:
71
68
            hook(params)
72
 
 
 
69
            
73
70
    def _call_and_read_response(self, method, args, body=None, readv_body=None,
74
71
            body_stream=None, expect_response_body=True):
75
72
        self._run_call_hooks(method, args, body, readv_body)
135
132
 
136
133
    def call_expecting_body(self, method, *args):
137
134
        """Call a method and return the result and the protocol object.
138
 
 
 
135
        
139
136
        The body can be read like so::
140
137
 
141
138
            result, smart_protocol = smart_client.call_expecting_body(...)
183
180
 
184
181
    def remote_path_from_transport(self, transport):
185
182
        """Convert transport into a path suitable for using in a request.
186
 
 
 
183
        
187
184
        Note that the resulting remote path doesn't encode the host name or
188
185
        anything but path, so it is only safe to use it in requests sent over
189
186
        the medium from the matching transport.
195
192
 
196
193
    def __init__(self):
197
194
        hooks.Hooks.__init__(self)
198
 
        self.create_hook(hooks.HookPoint('call',
199
 
            "Called when the smart client is submitting a request to the "
200
 
            "smart server. Called with a bzrlib.smart.client.CallHookParams "
201
 
            "object. Streaming request bodies, and responses, are not "
202
 
            "accessible.", None, None))
203
 
 
204
 
 
 
195
        self['call'] = []
 
196
 
 
197
        
205
198
_SmartClient.hooks = SmartClientHooks()
206
199
 
207
200
 
208
201
class CallHookParams(object):
209
 
 
 
202
    
210
203
    def __init__(self, method, args, body, readv_body, medium):
211
204
        self.method = method
212
205
        self.args = args