~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/message.py

  • Committer: Robert Collins
  • Date: 2009-09-30 21:38:49 UTC
  • mto: (4634.52.8 2.0)
  • mto: This revision was merged to the branch mainline in revision 4723.
  • Revision ID: robertc@robertcollins.net-20090930213849-0vyqtge2lfd16nx5
Review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
import collections
20
18
from cStringIO import StringIO
21
19
 
136
134
 
137
135
    def _args_received(self, args):
138
136
        self.expecting = 'body'
139
 
        self.request_handler.args_received(args)
 
137
        self.request_handler.dispatch_command(args[0], args[1:])
140
138
        if self.request_handler.finished_reading:
141
139
            self._response_sent = True
142
140
            self.responder.send_response(self.request_handler.response)
305
303
            mutter('   result:   %r', self.args)
306
304
        if self.status == 'E':
307
305
            self._wait_for_response_end()
308
 
            _raise_smart_server_error(self.args)
 
306
            _translate_error(self.args)
309
307
        return tuple(self.args)
310
308
 
311
309
    def read_body_bytes(self, count=-1):
337
335
                yield bytes_part
338
336
            self._read_more()
339
337
        if self._body_stream_status == 'E':
340
 
            _raise_smart_server_error(self._body_error_args)
 
338
            _translate_error(self._body_error_args)
341
339
 
342
340
    def cancel_read_body(self):
343
341
        self._wait_for_response_end()
344
342
 
345
343
 
346
 
def _raise_smart_server_error(error_tuple):
347
 
    """Raise exception based on tuple received from smart server
348
 
 
349
 
    Specific error translation is handled by bzrlib.remote._translate_error
350
 
    """
351
 
    if error_tuple[0] == 'UnknownMethod':
352
 
        raise errors.UnknownSmartMethod(error_tuple[1])
353
 
    raise errors.ErrorFromSmartServer(error_tuple)
 
344
def _translate_error(error_tuple):
 
345
    # Many exceptions need some state from the requestor to be properly
 
346
    # translated (e.g. they need a branch object).  So this only translates a
 
347
    # few errors, and the rest are turned into a generic ErrorFromSmartServer.
 
348
    error_name = error_tuple[0]
 
349
    error_args = error_tuple[1:]
 
350
    if error_name == 'UnknownMethod':
 
351
        raise errors.UnknownSmartMethod(error_args[0])
 
352
    if error_name == 'LockContention':
 
353
        raise errors.LockContention('(remote lock)')
 
354
    elif error_name == 'LockFailed':
 
355
        raise errors.LockFailed(*error_args[:2])
 
356
    elif error_name == 'FileExists':
 
357
        raise errors.FileExists(error_args[0])
 
358
    elif error_name == 'NoSuchFile':
 
359
        raise errors.NoSuchFile(error_args[0])
 
360
    else:
 
361
        raise errors.ErrorFromSmartServer(error_tuple)