/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

Consistently raise errors from the server as ErrorFromSmartServer exceptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
544
544
        """
545
545
        self._request.finished_reading()
546
546
 
547
 
    def read_response_tuple(self, expect_body=False):
548
 
        """Read a response tuple from the wire.
549
 
 
550
 
        This should only be called once.
551
 
        """
 
547
    def _read_response_tuple(self):
552
548
        result = self._recv_tuple()
553
549
        if 'hpss' in debug.debug_flags:
554
550
            if self._request_start_time is not None:
558
554
                self._request_start_time = None
559
555
            else:
560
556
                mutter('   result:   %s', repr(result)[1:-1])
 
557
        return result
 
558
 
 
559
    def read_response_tuple(self, expect_body=False):
 
560
        """Read a response tuple from the wire.
 
561
 
 
562
        This should only be called once.
 
563
        """
 
564
        result = self._read_response_tuple()
561
565
        self._response_is_unknown_method(result)
 
566
        self._raise_args_if_error(result)
562
567
        if not expect_body:
563
568
            self._request.finished_reading()
564
569
        return result
565
570
 
 
571
    def _raise_args_if_error(self, result_tuple):
 
572
        v1_error_codes = [
 
573
            'norepository',
 
574
            'NoSuchFile',
 
575
            'FileExists',
 
576
            'DirectoryNotEmpty',
 
577
            'ShortReadvError',
 
578
            'UnicodeEncodeError',
 
579
            'UnicodeDecodeError',
 
580
            'ReadOnlyError',
 
581
            'nobranch',
 
582
            'NoSuchRevision',
 
583
            'nosuchrevision',
 
584
            'LockContention',
 
585
            'UnlockableTransport',
 
586
            'LockFailed',
 
587
            'TokenMismatch',
 
588
            'ReadError',
 
589
            'PermissionDenied',
 
590
            ]
 
591
        if result_tuple[0] in v1_error_codes:
 
592
            self._request.finished_reading()
 
593
            raise errors.ErrorFromSmartServer(result_tuple)
 
594
 
566
595
    def _response_is_unknown_method(self, result_tuple):
567
596
        """Raise UnexpectedSmartServerResponse if the response is an 'unknonwn
568
597
        method' response to the request.
666
695
        if version != self.response_marker:
667
696
            raise errors.SmartProtocolError('bad protocol marker %r' % version)
668
697
        response_status = self._recv_line()
669
 
        if response_status not in ('success\n', 'failed\n'):
 
698
        result = SmartClientRequestProtocolOne._read_response_tuple(self)
 
699
        if response_status == 'success\n':
 
700
            self.response_status = True
 
701
            if not expect_body:
 
702
                self._request.finished_reading()
 
703
            return result
 
704
        elif response_status == 'failed\n':
 
705
            self.response_status = False
 
706
            self._request.finished_reading()
 
707
            raise errors.ErrorFromSmartServer(result)
 
708
        else:
670
709
            raise errors.SmartProtocolError(
671
710
                'bad protocol status %r' % response_status)
672
 
        self.response_status = response_status == 'success\n'
673
 
        return SmartClientRequestProtocolOne.read_response_tuple(self, expect_body)
674
711
 
675
712
    def _write_protocol_version(self):
676
713
        """Write any prefixes this protocol requires.
973
1010
        self._write_headers(headers)
974
1011
        self._write_structure(args)
975
1012
        readv_bytes = self._serialise_offsets(body)
 
1013
        if 'hpss' in debug.debug_flags:
 
1014
            mutter('              %d bytes in readv request', len(readv_bytes))
976
1015
        self._write_prefixed_body(readv_bytes)
977
 
        self._request.finished_writing()
978
 
        if 'hpss' in debug.debug_flags:
979
 
            mutter('              %d bytes in readv request', len(readv_bytes))
 
1016
        self._write_end()
 
1017
        self._medium_request.finished_writing()
980
1018