Ticket #4817: 4817-3.patch

File 4817-3.patch, 5.2 KB (added by Adam, 11 years ago)

1st patch against address-not-equal-comparison-4817

  • twisted/topfiles/4817.removal

     
    1 __getitem__ __getslice__ and __eq__ (tuple comparison, indexing) removed from twisted.internet.IPv4Address and twisted.internet.UNIXAddress classes
     1__getitem__ __getslice__ and __eq__ (tuple comparison, indexing) removed from twisted.internet.address.IPv4Address and twisted.internet.address.UNIXAddress classes
     2UNIXAddress and IPv4Address properties _bwHack are now deprecated in twisted.internet.address
  • twisted/internet/address.py

     
    2121    @ivar port: An integer representing the port number.
    2222    """
    2323
    24     # _bwHack is given to old users who think we are a tuple. They expected
    25     # addr[0] to define the socket type rather than the address family, so
    26     # the value comes from a different namespace than the new .type value:
    27 
    28     #  type = map[_bwHack]
    29     # map = { 'SSL': 'TCP', 'INET': 'TCP', 'INET_UDP': 'UDP' }
    30 
    3124    implements(IAddress)
    3225
    3326    compareAttributes = ('type', 'host', 'port')
     
    3730        self.type = type
    3831        self.host = host
    3932        self.port = port
    40         self._bwHack = _bwHack
     33        if _bwHack is not None:
     34            warnings.warn("twisted.internet.address.IPv4Address._bwHack is deprecated since Twisted 11.0",
     35                    DeprecationWarning, stacklevel=2)
    4136
    4237    def __repr__(self):
    4338        return 'IPv4Address(%s, %r, %d)' % (self.type, self.host, self.port)
     
    5651
    5752    compareAttributes = ('name', )
    5853
    59     def __init__(self, name, _bwHack='UNIX'):
     54    def __init__(self, name, _bwHack = None):
    6055        self.name = name
    61         self._bwHack = _bwHack
     56        if _bwHack is not None:
     57            warnings.warn("twisted.internet.address.UNIXAddress._bwHack is deprecated since Twisted 11.0",
     58                    DeprecationWarning, stacklevel=2)
    6259
    6360    def __eq__(self, other):
    6461        """
  • twisted/internet/test/test_address.py

     
    6363        self._stringRepresentation(repr)
    6464
    6565
     66    def test_differentNamesComparison(self):
     67        """
     68        Check that comparison operators work correctly on address objects
     69        when a different name is passed in
     70        """
     71        self.assertFalse(self.buildAddress() == self.buildDifferentAddress())
     72        self.assertTrue(self.buildAddress() != self.buildDifferentAddress())
    6673
     74    def assertDeprecations(self, testMethod, message):
     75        warnings = self.flushWarnings([testMethod])
     76        self.assertEquals(warnings[0]['category'], DeprecationWarning)
     77        self.assertEquals(warnings[0]['message'], message)
     78        self.assertEquals(len(warnings),1)
     79
     80
    6781class IPv4AddressTestCaseMixin(AddressTestCaseMixin):
    6882    addressArgSpec = (("type", "%s"), ("host", "%r"), ("port", "%d"))
    6983
    7084
    71 
    7285class IPv4AddressTCPTestCase(unittest.TestCase, IPv4AddressTestCaseMixin):
    7386    def buildAddress(self):
    7487        return IPv4Address("TCP", "127.0.0.1", 0)
    7588
     89    def buildDifferentAddress(self):
     90        return IPv4Address("TCP", "127.0.0.2", 0)
    7691
     92    def test_bwHackDeprecation(self):
     93        message = "twisted.internet.address.IPv4Address._bwHack is deprecated since Twisted 11.0"
     94        address = IPv4Address("TCP", "127.0.0.3", 0, _bwHack="TCP")
     95        return self.assertDeprecations(self.test_bwHackDeprecation, message)
    7796
     97
    7898class IPv4AddressUDPTestCase(unittest.TestCase, IPv4AddressTestCaseMixin):
    7999    def buildAddress(self):
    80100        return IPv4Address("UDP", "127.0.0.1", 0)
    81101
     102    def buildDifferentAddress(self):
     103        return IPv4Address("UDP", "127.0.0.2", 0)
    82104
     105    def test_bwHackDeprecation(self):
     106        message = "twisted.internet.address.IPv4Address._bwHack is deprecated since Twisted 11.0"
     107        address = IPv4Address("UDP", "127.0.0.3", 0, _bwHack="UDP")
     108        return self.assertDeprecations(self.test_bwHackDeprecation, message)
    83109
     110
    84111class UNIXAddressTestCase(unittest.TestCase, AddressTestCaseMixin):
    85112    addressArgSpec = (("name", "%r"),)
    86113
    87114    def setUp(self):
    88115        self._socketAddress = self.mktemp()
    89116
    90 
    91117    def buildAddress(self):
    92118        return UNIXAddress(self._socketAddress)
    93119
    94     def test_differentNamesComparison(self):
    95         """
    96         Check that comparison operators work correctly on UNIXAddress objects
    97         when a different name is passed in
    98         """
    99         self.assertFalse(UNIXAddress(self.mktemp()) ==
    100                 UNIXAddress(self.mktemp()))
    101         self.assertTrue(UNIXAddress(self.mktemp()) !=
    102                 UNIXAddress(self.mktemp()))
     120    def buildDifferentAddress(self):
     121        return UNIXAddress(self.mktemp())
     122
     123    def test_bwHackDeprecation(self):
     124        message = "twisted.internet.address.UNIXAddress._bwHack is deprecated since Twisted 11.0"
     125        address = UNIXAddress(self.mktemp(), _bwHack='UNIX')
     126        return self.assertDeprecations(self.test_bwHackDeprecation, message)