~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
469
469
        self._request = request
470
470
        self._body_buffer = None
471
471
        self._request_start_time = None
 
472
        self._last_verb = None
472
473
 
473
474
    def call(self, *args):
474
475
        if 'hpss' in debug.debug_flags:
478
479
            self._request_start_time = time.time()
479
480
        self._write_args(args)
480
481
        self._request.finished_writing()
 
482
        self._last_verb = args[0]
481
483
 
482
484
    def call_with_body_bytes(self, args, body):
483
485
        """Make a remote call of args with body bytes 'body'.
496
498
        bytes = self._encode_bulk_data(body)
497
499
        self._request.accept_bytes(bytes)
498
500
        self._request.finished_writing()
 
501
        self._last_verb = args[0]
499
502
 
500
503
    def call_with_body_readv_array(self, args, body):
501
504
        """Make a remote call with a readv array.
515
518
        self._request.finished_writing()
516
519
        if 'hpss' in debug.debug_flags:
517
520
            mutter('              %d bytes in readv request', len(readv_bytes))
 
521
        self._last_verb = args[0]
518
522
 
519
523
    def cancel_read_body(self):
520
524
        """After expecting a body, a response code may indicate one otherwise.
539
543
                self._request_start_time = None
540
544
            else:
541
545
                mutter('   result:   %s', repr(result)[1:-1])
 
546
        self._response_is_unknown_method(result)
542
547
        if not expect_body:
543
548
            self._request.finished_reading()
544
549
        return result
545
550
 
 
551
    def _response_is_unknown_method(self, result_tuple):
 
552
        """Raise UnexpectedSmartServerResponse if the response is an 'unknonwn
 
553
        method' response to the request.
 
554
        
 
555
        :param response: The response from a smart client call_expecting_body
 
556
            call.
 
557
        :param verb: The verb used in that call.
 
558
        :raises: UnexpectedSmartServerResponse
 
559
        """
 
560
        if (result_tuple == ('error', "Generic bzr smart protocol error: "
 
561
                "bad request '%s'" % self._last_verb) or
 
562
              result_tuple == ('error', "Generic bzr smart protocol error: "
 
563
                "bad request u'%s'" % self._last_verb)):
 
564
            # The response will have no body, so we've finished reading.
 
565
            self._request.finished_reading()
 
566
            raise errors.UnknownSmartMethod(self._last_verb)
 
567
        
546
568
    def read_body_bytes(self, count=-1):
547
569
        """Read bytes from the body, decoding into a byte stream.
548
570