~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/message.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-22 17:11:20 UTC
  • mfrom: (4398.8.10 1.16-commit-fulltext)
  • Revision ID: pqm@pqm.ubuntu.com-20090622171120-fuxez9ylfqpxynqn
(jam) Add VF._add_text and reduce memory overhead during commit (see
        bug #109114)

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
 
135
135
    def _args_received(self, args):
136
136
        self.expecting = 'body'
137
 
        self.request_handler.args_received(args)
 
137
        self.request_handler.dispatch_command(args[0], args[1:])
138
138
        if self.request_handler.finished_reading:
139
139
            self._response_sent = True
140
140
            self.responder.send_response(self.request_handler.response)
283
283
                    self._protocol_decoder._get_in_buffer()[:10],
284
284
                    self._protocol_decoder.state_accept.__name__)
285
285
            raise errors.ConnectionReset(
286
 
                "Unexpected end of message. "
287
 
                "Please check connectivity and permissions, and report a bug "
288
 
                "if problems persist.")
 
286
                "please check connectivity and permissions")
289
287
        self._protocol_decoder.accept_bytes(bytes)
290
288
 
291
289
    def protocol_error(self, exception):
303
301
            mutter('   result:   %r', self.args)
304
302
        if self.status == 'E':
305
303
            self._wait_for_response_end()
306
 
            _raise_smart_server_error(self.args)
 
304
            _translate_error(self.args)
307
305
        return tuple(self.args)
308
306
 
309
307
    def read_body_bytes(self, count=-1):
330
328
        while not self.finished_reading:
331
329
            while self._bytes_parts:
332
330
                bytes_part = self._bytes_parts.popleft()
333
 
                if 'hpssdetail' in debug.debug_flags:
 
331
                if 'hpss' in debug.debug_flags:
334
332
                    mutter('              %d byte part read', len(bytes_part))
335
333
                yield bytes_part
336
334
            self._read_more()
337
335
        if self._body_stream_status == 'E':
338
 
            _raise_smart_server_error(self._body_error_args)
 
336
            _translate_error(self._body_error_args)
339
337
 
340
338
    def cancel_read_body(self):
341
339
        self._wait_for_response_end()
342
340
 
343
341
 
344
 
def _raise_smart_server_error(error_tuple):
345
 
    """Raise exception based on tuple received from smart server
346
 
 
347
 
    Specific error translation is handled by bzrlib.remote._translate_error
348
 
    """
349
 
    if error_tuple[0] == 'UnknownMethod':
350
 
        raise errors.UnknownSmartMethod(error_tuple[1])
351
 
    raise errors.ErrorFromSmartServer(error_tuple)
 
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])
 
358
    else:
 
359
        raise errors.ErrorFromSmartServer(error_tuple)