14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
18
20
from cStringIO import StringIO
135
137
def _args_received(self, args):
136
138
self.expecting = 'body'
137
self.request_handler.dispatch_command(args[0], args[1:])
139
self.request_handler.args_received(args)
138
140
if self.request_handler.finished_reading:
139
141
self._response_sent = True
140
142
self.responder.send_response(self.request_handler.response)
283
285
self._protocol_decoder._get_in_buffer()[:10],
284
286
self._protocol_decoder.state_accept.__name__)
285
287
raise errors.ConnectionReset(
286
"please check connectivity and permissions")
288
"Unexpected end of message. "
289
"Please check connectivity and permissions, and report a bug "
290
"if problems persist.")
287
291
self._protocol_decoder.accept_bytes(bytes)
289
293
def protocol_error(self, exception):
301
305
mutter(' result: %r', self.args)
302
306
if self.status == 'E':
303
307
self._wait_for_response_end()
304
_translate_error(self.args)
308
_raise_smart_server_error(self.args)
305
309
return tuple(self.args)
307
311
def read_body_bytes(self, count=-1):
328
332
while not self.finished_reading:
329
333
while self._bytes_parts:
330
334
bytes_part = self._bytes_parts.popleft()
331
if 'hpss' in debug.debug_flags:
335
if 'hpssdetail' in debug.debug_flags:
332
336
mutter(' %d byte part read', len(bytes_part))
334
338
self._read_more()
335
339
if self._body_stream_status == 'E':
336
_translate_error(self._body_error_args)
340
_raise_smart_server_error(self._body_error_args)
338
342
def cancel_read_body(self):
339
343
self._wait_for_response_end()
342
def _translate_error(error_tuple):
343
# Many exceptions need some state from the requestor to be properly
344
# translated (e.g. they need a branch object). So this only translates a
345
# few errors, and the rest are turned into a generic ErrorFromSmartServer.
346
error_name = error_tuple[0]
347
error_args = error_tuple[1:]
348
if error_name == 'UnknownMethod':
349
raise errors.UnknownSmartMethod(error_args[0])
350
if error_name == 'LockContention':
351
raise errors.LockContention('(remote lock)')
352
elif error_name == 'LockFailed':
353
raise errors.LockFailed(*error_args[:2])
354
elif error_name == 'FileExists':
355
raise errors.FileExists(error_args[0])
356
elif error_name == 'NoSuchFile':
357
raise errors.NoSuchFile(error_args[0])
359
raise errors.ErrorFromSmartServer(error_tuple)
346
def _raise_smart_server_error(error_tuple):
347
"""Raise exception based on tuple received from smart server
349
Specific error translation is handled by bzrlib.remote._translate_error
351
if error_tuple[0] == 'UnknownMethod':
352
raise errors.UnknownSmartMethod(error_tuple[1])
353
raise errors.ErrorFromSmartServer(error_tuple)