157
157
return self._combine_paths(self._path, relpath)
159
159
def _call(self, method, *args):
160
resp = self._call2(method, *args)
161
resp = self._call2(method, *args)
162
except errors.ErrorFromSmartServer, err:
163
self._translate_error(err.error_tuple)
161
164
self._translate_error(resp)
163
166
def _call2(self, method, *args):
164
167
"""Call a method on the remote server."""
165
return self._client.call(method, *args)
169
return self._client.call(method, *args)
170
except errors.ErrorFromSmartServer, err:
171
self._translate_error(err.error_tuple)
167
173
def _call_with_body_bytes(self, method, args, body):
168
174
"""Call a method on the remote server with body bytes."""
169
return self._client.call_with_body_bytes(method, args, body)
176
return self._client.call_with_body_bytes(method, args, body)
177
except errors.ErrorFromSmartServer, err:
178
self._translate_error(err.error_tuple)
171
180
def has(self, relpath):
172
181
"""Indicate whether a remote file of the given name exists or not.
191
200
def get_bytes(self, relpath):
192
201
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)
203
resp, response_handler = self._client.call_expecting_body('get', remote)
204
except errors.ErrorFromSmartServer, err:
205
self._translate_error(err.error_tuple, relpath)
197
206
if resp != ('ok', ):
198
207
smart_protocol.cancel_read_body()
199
self._translate_error(resp, relpath)
200
return smart_protocol.read_body_bytes()
208
raise errors.UnexpectedSmartServerResponse(resp)
209
return response_handler.read_body_bytes()
202
211
def _serialise_optional_mode(self, mode):
306
315
limit=self._max_readv_combine,
307
316
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)
319
result = self._client.call_with_body_readv_array(
320
('readv', self._remote_path(relpath),),
321
[(c.start, c.length) for c in coalesced])
322
resp, response_handler = result
323
except errors.ErrorFromSmartServer, err:
324
self._translate_error(err.error_tuple)
316
326
if resp[0] != 'readv':
317
327
# This should raise an exception
318
328
smart_protocol.cancel_read_body()
319
self._translate_error(resp)
329
raise errors.UnexpectedSmartServerResponse(resp)
322
331
# FIXME: this should know how many bytes are needed, for clarity.
323
data = smart_protocol.read_body_bytes()
332
data = response_handler.read_body_bytes()
324
333
# Cache the results, but only until they have been fulfilled
326
335
for c_offset in coalesced: