Ticket #2491: 2491.patch

File 2491.patch, 3.4 KB (added by Michael, 6 years ago)
  • twisted/internet/tcp.py

    diff --git twisted/internet/tcp.py twisted/internet/tcp.py
    index 222ae9b..9fefe6b 100644
    import types 
    1717import socket
    1818import sys
    1919import operator
     20import warnings
    2021
    2122from zope.interface import implements, classImplements
    2223
    except ImportError: 
    2627    SSL = None
    2728
    2829from twisted.python.runtime import platformType
    29 
     30from twisted.python import versions, deprecate
    3031
    3132if platformType == 'win32':
    3233    # no such thing as WSAEPERM or error code 10001 according to winsock.h or MSDN
    class Connection(abstract.FileDescriptor, _SocketCloser): 
    457458                return main.CONNECTION_LOST
    458459        if not data:
    459460            return main.CONNECTION_DONE
    460         return self.protocol.dataReceived(data)
    461 
     461        rval = self.protocol.dataReceived(data)
     462        if rval:
     463            warningFormat = 'Returning a value other than None from %(fqpn)s was deprecated in %(version)s'
     464            warningString = deprecate.getDeprecationWarningString(self.protocol.dataReceived,
     465                                                                  versions.Version('twisted', 11, 0, 0),
     466                                                                  format = warningFormat)
     467            warnings.warn(warningString, category=DeprecationWarning, stacklevel=2)
     468        return rval
    462469
    463470    def writeSomeData(self, data):
    464471        """
  • new file twisted/internet/test/test_tcpconnection.py

    diff --git twisted/internet/test/test_tcpconnection.py twisted/internet/test/test_tcpconnection.py
    new file mode 100644
    index 0000000..422986a
    - +  
     1# Copyright (c) 20011 Twisted Matrix Laboratories.
     2# See LICENSE for details.
     3
     4"""
     5Tests for TCP Connection.
     6"""
     7
     8
     9from twisted.internet.tcp import Connection
     10from twisted.internet.protocol import Protocol
     11from twisted.trial.unittest import TestCase
     12
     13
     14class FakeSocket(object):
     15    """
     16    A Fake Socket object
     17    """
     18    fileno = 1
     19   
     20    def __init__(self, data='someData'):
     21        self.data = data
     22
     23    def setblocking(self, blocking):
     24        self.blocking = blocking
     25
     26    def recv(self, size):
     27        return self.data
     28
     29
     30
     31class TestFakeSocket(TestCase):
     32
     33    def test_blocking(self):
     34        skt = FakeSocket()
     35        skt.setblocking(0)
     36        self.assertEquals(skt.blocking, 0)
     37
     38
     39    def test_recv(self):
     40        skt = FakeSocket()
     41        self.assertEquals(skt.recv(10), "someData")
     42
     43
     44
     45class FakeProtocol(object):
     46    def dataReceived(self, data):
     47        return "Returning something I shouldn't"
     48
     49
     50
     51class TestTCPConnection(TestCase):
     52    """
     53    """
     54    def test_doread(self):
     55        skt = FakeSocket()
     56        protocol = FakeProtocol()
     57        conn = Connection(skt, protocol)
     58        conn.doRead()
     59        warnings = self.flushWarnings([self.test_doread])
     60        self.assertEquals(warnings[0]['category'], DeprecationWarning)
     61        self.assertEquals(
     62            warnings[0]['message'],
     63            "Returning a value other than None from twisted.internet.test.test_tcpconnection.FakeProtocol.dataReceived was deprecated in twisted 11.0.0")
     64        self.assertEquals(len(warnings), 1)
  • new file twisted/topfiles/2491.removal

    diff --git twisted/topfiles/2491.removal twisted/topfiles/2491.removal
    new file mode 100644
    index 0000000..cee4baf
    - +  
     1returning a value other than None from IProtocol.dataReceived was deprecated