~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

  • Committer: Andrew Bennetts
  • Date: 2008-02-28 08:39:32 UTC
  • mto: (3245.4.1 Version 3 implementation.)
  • mto: This revision was merged to the branch mainline in revision 3428.
  • Revision ID: andrew.bennetts@canonical.com-20080228083932-t8ev1e9ze82gc5xz
Improve the error handling, fixing more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
997
997
        # XXX: warn if expect_body doesn't match the response?
998
998
        self._wait_for_request_end()
999
999
        if self.response_handler.error_args is not None:
1000
 
            xxx_translate_error()
 
1000
            self._translate_error()
 
1001
            return self.response_handler.error_args
1001
1002
        return self.response_handler.args
1002
1003
 
1003
1004
    def read_body_bytes(self, count=-1):
1010
1011
        self._wait_for_request_end()
1011
1012
        return self.response_handler.prefixed_body.read(count)
1012
1013
 
 
1014
    def _translate_error(self, error_tuple):
 
1015
        # XXX: Hmm!  Need state from the request.  Hmm.
 
1016
        error_name = error_tuple[0]
 
1017
        error_args = error_tuple[1:]
 
1018
        if error_name == 'LockContention':
 
1019
            raise errors.LockContention('(remote lock)')
 
1020
        elif error_name == 'LockFailed':
 
1021
            raise errors.LockContention(*error_args[:2])
 
1022
        else:
 
1023
            return # XXX
 
1024
            raise errors.UnexpectedSmartServerResponse('Sucktitude: %r' %
 
1025
                    (error_tuple,))
 
1026
 
1013
1027
 
1014
1028
class _ProtocolThreeEncoder(object):
1015
1029
 
1035
1049
 
1036
1050
    def _write_structure(self, args):
1037
1051
        self._write_func('s')
1038
 
        self._write_prefixed_bencode(args)
 
1052
        utf8_args = []
 
1053
        for arg in args:
 
1054
            if type(arg) is unicode:
 
1055
                utf8_args.append(arg.encode('utf8'))
 
1056
            else:
 
1057
                utf8_args.append(arg)
 
1058
        self._write_prefixed_bencode(utf8_args)
1039
1059
 
1040
1060
    def _write_end(self):
1041
1061
        self._write_func('e')