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)
157
155
return self._combine_paths(self._path, relpath)
159
157
def _call(self, method, *args):
160
resp = self._call2(method, *args)
159
resp = self._call2(method, *args)
160
except errors.ErrorFromSmartServer, err:
161
self._translate_error(err.error_tuple)
161
162
self._translate_error(resp)
163
164
def _call2(self, method, *args):
164
165
"""Call a method on the remote server."""
165
return self._client.call(method, *args)
167
return self._client.call(method, *args)
168
except errors.ErrorFromSmartServer, err:
169
self._translate_error(err.error_tuple)
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)
174
return self._client.call_with_body_bytes(method, args, body)
175
except errors.ErrorFromSmartServer, err:
176
self._translate_error(err.error_tuple)
171
178
def has(self, relpath):
172
179
"""Indicate whether a remote file of the given name exists or not.
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)
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()
202
209
def _serialise_optional_mode(self, mode):
306
313
limit=self._max_readv_combine,
307
314
fudge_factor=self._bytes_to_read_before_seek))
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)
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)
316
324
if resp[0] != 'readv':
317
325
# This should raise an exception
318
smart_protocol.cancel_read_body()
319
self._translate_error(resp)
326
response_handler.cancel_read_body()
327
raise errors.UnexpectedSmartServerResponse(resp)
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
326
333
for c_offset in coalesced: