~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-12 04:36:04 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-20080212043604-ukkk06e0ithdmd02
Use _NeedMoreBytes to improve earlier protocol implementations a little, and make test_errors_are_logged pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
        if pos == -1:
328
328
            # We haven't read a complete length prefix yet, so there's nothing
329
329
            # to do.
330
 
            return None
 
330
            raise _NeedMoreBytes()
331
331
        line = self._in_buffer[:pos]
332
332
        # Trim the prefix (including '\n' delimiter) from the _in_buffer.
333
333
        self._in_buffer = self._in_buffer[pos+1:]
346
346
    def _state_accept_expecting_header(self, bytes):
347
347
        self._in_buffer += bytes
348
348
        prefix = self._extract_line()
349
 
        if prefix is None:
350
 
            # We haven't read a complete length prefix yet, so there's nothing
351
 
            # to do.
352
 
            return
353
 
        elif prefix == 'chunked':
 
349
        if prefix == 'chunked':
354
350
            self.state_accept = self._state_accept_expecting_length
355
351
        else:
356
352
            raise errors.SmartProtocolError(
359
355
    def _state_accept_expecting_length(self, bytes):
360
356
        self._in_buffer += bytes
361
357
        prefix = self._extract_line()
362
 
        if prefix is None:
363
 
            # We haven't read a complete length prefix yet, so there's nothing
364
 
            # to do.
365
 
            return
366
 
        elif prefix == 'ERR':
 
358
        if prefix == 'ERR':
367
359
            self.error = True
368
360
            self.error_in_progress = []
369
361
            self._state_accept_expecting_length('')
696
688
#        self.has_dispatched = False
697
689
#        self._body_decoder = None
698
690
 
 
691
    def accept_bytes(self, bytes):
 
692
        try:
 
693
            _StatefulDecoder.accept_bytes(self, bytes)
 
694
        except KeyboardInterrupt:
 
695
            raise
 
696
        except Exception, exception:
 
697
            log_exception_quietly()
 
698
            # XXX
 
699
            #self._send_response(request.FailedSmartServerResponse(
 
700
            #    ('error', str(exception))))
 
701
 
699
702
    def _extract_length_prefixed_bytes(self):
700
703
        if len(self._in_buffer) < 4:
701
704
            # A length prefix by itself is 4 bytes, and we don't even have that