Ticket #3277: issue-3277.patch

File issue-3277.patch, 5.1 KB (added by spiv, 13 years ago)

Fix for #3277

  • twisted/protocols/basic.py

    # Bazaar merge directive format 2 (Bazaar 0.90)
    # revision_id: andrew@puzzling.org-20080713084019-hhqgv5d6pye8hgyw
    # target_branch: file:///home/andrew/code/twisted-import-trunk/trunk/
    # testament_sha1: fc3a7dd341a3112db7c3e18ec38b730c387bce95
    # timestamp: 2008-07-13 18:40:41 +1000
    # base_revision_id: svn-v3-trunk0:bbbe8e31-12d6-0310-92fd-\
    #   ac37d47ddeeb:trunk:24262
    # 
    # Begin patch
    === modified file 'twisted/protocols/basic.py'
     
    225225            else:
    226226                linelength = len(line)
    227227                if linelength > self.MAX_LENGTH:
    228                     exceeded = line + self.__buffer
     228                    exceeded = line + self.delimiter + self.__buffer
    229229                    self.__buffer = ''
    230230                    return self.lineLengthExceeded(exceeded)
    231231                why = self.lineReceived(line)
  • twisted/test/test_protocols.py

    === modified file 'twisted/test/test_protocols.py'
     
    279279        self.assertEquals(a.received,
    280280                          ['produce', 'hello world', 'unproduce', 'goodbye'])
    281281
     282    def testLongLineWithDelimiter(self):
     283        """
     284        When MAX_LENGTH is exceeded *and* a delimiter has been received,
     285        lineLengthExceeded is called with the right bytes.
     286
     287        See http://twistedmatrix.com/trac/ticket/3277
     288        """
     289        # Set up a line receiver with a short MAX_LENGTH that logs
     290        # lineLengthExceeded events.
     291        class LineReceiverThatRecords(basic.LineReceiver):
     292            MAX_LENGTH = 10
     293            def connectionMade(self):
     294                self.calls = []
     295            def lineReceived(self, line):
     296                self.calls.append(('lineReceived', line))
     297            def lineLengthExceeded(self, line):
     298                self.calls.append(('lineLengthExceeded', line))
     299        lineReceiver = LineReceiverThatRecords()
     300        t = StringIOWithoutClosing()
     301        lineReceiver.makeConnection(protocol.FileWrapper(t))
     302        # Call dataReceived with two lines, the first longer than MAX_LENGTH.
     303        longLine = ('x' * 11) + '\r\n'
     304        nextLine = 'next line\r\n'
     305        lineReceiver.dataReceived(longLine + nextLine)
     306        # We expect lineLengthExceeded to be called with exactly what we just
     307        # passed dataReceived.  lineReceived is not called.
     308        expectedCalls = [('lineLengthExceeded', longLine + nextLine)]
     309        self.assertEqual(expectedCalls, lineReceiver.calls)
     310
    282311
    283312class LineOnlyReceiverTestCase(unittest.TestCase):
    284313    """