~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/remote.py

Implement version 3 of the network protocol. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
__all__ = ['RemoteTransport', 'RemoteTCPTransport', 'RemoteSSHTransport']
24
24
 
25
25
from cStringIO import StringIO
26
 
import urllib
27
 
import urlparse
28
26
 
29
27
from bzrlib import (
30
28
    config,
34
32
    transport,
35
33
    urlutils,
36
34
    )
37
 
from bzrlib.smart import client, medium, protocol
 
35
from bzrlib.smart import client, medium
38
36
from bzrlib.symbol_versioning import (deprecated_method, one_four)
39
37
 
40
38
 
157
155
        return self._combine_paths(self._path, relpath)
158
156
 
159
157
    def _call(self, method, *args):
160
 
        resp = self._call2(method, *args)
 
158
        try:
 
159
            resp = self._call2(method, *args)
 
160
        except errors.ErrorFromSmartServer, err:
 
161
            self._translate_error(err.error_tuple)
161
162
        self._translate_error(resp)
162
163
 
163
164
    def _call2(self, method, *args):
164
165
        """Call a method on the remote server."""
165
 
        return self._client.call(method, *args)
 
166
        try:
 
167
            return self._client.call(method, *args)
 
168
        except errors.ErrorFromSmartServer, err:
 
169
            self._translate_error(err.error_tuple)
166
170
 
167
171
    def _call_with_body_bytes(self, method, args, body):
168
172
        """Call a method on the remote server with body bytes."""
169
 
        return self._client.call_with_body_bytes(method, args, body)
 
173
        try:
 
174
            return self._client.call_with_body_bytes(method, args, body)
 
175
        except errors.ErrorFromSmartServer, err:
 
176
            self._translate_error(err.error_tuple)
170
177
 
171
178
    def has(self, relpath):
172
179
        """Indicate whether a remote file of the given name exists or not.
190
197
 
191
198
    def get_bytes(self, relpath):
192
199
        remote = self._remote_path(relpath)
193
 
        request = self.get_smart_medium().get_request()
194
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
195
 
        smart_protocol.call('get', remote)
196
 
        resp = smart_protocol.read_response_tuple(True)
 
200
        try:
 
201
            resp, response_handler = self._client.call_expecting_body('get', remote)
 
202
        except errors.ErrorFromSmartServer, err:
 
203
            self._translate_error(err.error_tuple, relpath)
197
204
        if resp != ('ok', ):
198
 
            smart_protocol.cancel_read_body()
199
 
            self._translate_error(resp, relpath)
200
 
        return smart_protocol.read_body_bytes()
 
205
            response_handler.cancel_read_body()
 
206
            raise errors.UnexpectedSmartServerResponse(resp)
 
207
        return response_handler.read_body_bytes()
201
208
 
202
209
    def _serialise_optional_mode(self, mode):
203
210
        if mode is None:
306
313
                               limit=self._max_readv_combine,
307
314
                               fudge_factor=self._bytes_to_read_before_seek))
308
315
 
309
 
        request = self.get_smart_medium().get_request()
310
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
311
 
        smart_protocol.call_with_body_readv_array(
312
 
            ('readv', self._remote_path(relpath)),
313
 
            [(c.start, c.length) for c in coalesced])
314
 
        resp = smart_protocol.read_response_tuple(True)
 
316
        try:
 
317
            result = self._client.call_with_body_readv_array(
 
318
                ('readv', self._remote_path(relpath),),
 
319
                [(c.start, c.length) for c in coalesced])
 
320
            resp, response_handler = result
 
321
        except errors.ErrorFromSmartServer, err:
 
322
            self._translate_error(err.error_tuple)
315
323
 
316
324
        if resp[0] != 'readv':
317
325
            # This should raise an exception
318
 
            smart_protocol.cancel_read_body()
319
 
            self._translate_error(resp)
320
 
            return
 
326
            response_handler.cancel_read_body()
 
327
            raise errors.UnexpectedSmartServerResponse(resp)
321
328
 
322
329
        # FIXME: this should know how many bytes are needed, for clarity.
323
 
        data = smart_protocol.read_body_bytes()
 
330
        data = response_handler.read_body_bytes()
324
331
        # Cache the results, but only until they have been fulfilled
325
332
        data_map = {}
326
333
        for c_offset in coalesced: