Ticket #6558: pass-whole-buffer.patch

File pass-whole-buffer.patch, 2.7 KB (added by zooko, 6 years ago)
  • twisted/protocols/basic.py

     
    449449                # the one that told it to close.
    450450                return
    451451            if len(line) > self.MAX_LENGTH:
    452                 return self.lineLengthExceeded(line)
     452                lines.append(self._buffer)
     453                buf = self.delimiter.join(lines)
     454                self._buffer = ''
     455                return self.lineLengthExceeded(buf)
    453456            else:
    454457                self.lineReceived(line)
    455458        if len(self._buffer) > self.MAX_LENGTH:
    456             return self.lineLengthExceeded(self._buffer)
     459            buf, self._buffer = self._buffer, ''
     460            return self.lineLengthExceeded(buf)
    457461
    458462
    459463    def lineReceived(self, line):
  • twisted/protocols/test/test_basic.py

     
    401401        self.assertRaises(NotImplementedError, proto.lineReceived, 'foo')
    402402
    403403
     404    def test_lineLengthExceeded(self):
     405        """
     406        C{LineOnlyReceiver} calls C{lineLengthExceeded} with the
     407        entire remaining contents of its buffer.
     408        """
     409        caught_line = []
     410        class ExcessivelyLargeLineCatcher(LineOnlyTester):
     411            def lineReceived(self, line):
     412                pass
     413            def lineLengthExceeded(self, line):
     414                caught_line.append(line)
    404415
     416        proto = ExcessivelyLargeLineCatcher()
     417        proto.MAX_LENGTH=6
     418        transport = proto_helpers.StringTransport()
     419        proto.makeConnection(transport)
     420        excessive_input = b'y' * (proto.MAX_LENGTH * 2 + 2)
     421        proto.dataReceived(excessive_input)
     422        self.assertEqual(caught_line and caught_line[0], excessive_input)
     423        del caught_line[:]
     424
     425        excessive_input = b'u' * (proto.MAX_LENGTH * 2 + 2)
     426        proto.dataReceived(b'z'+proto.delimiter + excessive_input)
     427        self.assertEqual(caught_line[0], excessive_input)
     428        del caught_line[:]
     429
     430        excessive_input = b'q' * (proto.MAX_LENGTH * 2 + 2) + proto.delimiter + b't' * (proto.MAX_LENGTH * 2 + 2)
     431        proto.dataReceived(excessive_input)
     432        self.assertEqual(caught_line[0], excessive_input)
     433        del caught_line[:]
     434
     435        excessive_input = b'r' * (proto.MAX_LENGTH * 2 + 2) + proto.delimiter + b'v' * (proto.MAX_LENGTH * 2 + 2) + proto.delimiter
     436        proto.dataReceived(excessive_input)
     437        self.assertEqual(caught_line[0], excessive_input)
     438        del caught_line[:]
     439
     440
     441
    405442class TestMixin:
    406443
    407444    def connectionMade(self):