Ticket #4817: 4817-1.patch

File 4817-1.patch, 3.6 KB (added by Adam, 11 years ago)
  • twisted/test/test_udp.py

     
    119119        p = reactor.listenUDP(0, server, interface="127.0.0.1")
    120120        def cbStarted(ignored):
    121121            addr = p.getHost()
    122             self.assertEquals(addr, ('INET_UDP', addr.host, addr.port))
     122            self.assertEquals(addr.type, 'UDP')
    123123            return p.stopListening()
    124124        return d.addCallback(cbStarted)
    125125    testOldAddress.suppress = [
  • twisted/internet/address.py

     
    99from zope.interface import implements
    1010
    1111from twisted.internet.interfaces import IAddress
     12from twisted.python import util
    1213
    1314
    14 class IPv4Address(object):
     15class IPv4Address(object, util.FancyEqMixin):
    1516    """
    1617    Object representing an IPv4 socket endpoint.
    1718
     
    2930
    3031    implements(IAddress)
    3132
     33    compareAttributes = ('type', 'host', 'port')
     34
    3235    def __init__(self, type, host, port, _bwHack = None):
    3336        assert type in ('TCP', 'UDP')
    3437        self.type = type
     
    4649                      category=DeprecationWarning, stacklevel=2)
    4750        return (self._bwHack or self.type, self.host, self.port)[start:stop]
    4851
    49     def __eq__(self, other):
    50         if isinstance(other, tuple):
    51             return tuple(self) == other
    52         elif isinstance(other, IPv4Address):
    53             a = (self.type, self.host, self.port)
    54             b = (other.type, other.host, other.port)
    55             return a == b
    56         return False
    57 
    5852    def __repr__(self):
    5953        return 'IPv4Address(%s, %r, %d)' % (self.type, self.host, self.port)
    6054
    6155
    6256
    63 class UNIXAddress(object):
     57class UNIXAddress(object, util.FancyEqMixin):
    6458    """
    6559    Object representing a UNIX socket endpoint.
    6660
     
    7064
    7165    implements(IAddress)
    7266
     67    compareAttributes = ('name', )
     68
    7369    def __init__(self, name, _bwHack='UNIX'):
    7470        self.name = name
    7571        self._bwHack = _bwHack
     
    8480                      category=DeprecationWarning, stacklevel=2)
    8581        return (self._bwHack, self.name)[start:stop]
    8682
    87     def __eq__(self, other):
    88         if isinstance(other, tuple):
    89             return tuple(self) == other
    90         elif isinstance(other, UNIXAddress):
    91             # First do the simple thing and check to see if the names are the
    92             # same. If not, and the paths exist, check to see if they point to
    93             # the same file.
    94             if self.name == other.name:
    95                 return True
    96             else:
    97                 try:
    98                     return os.path.samefile(self.name, other.name)
    99                 except OSError:
    100                     pass
    101         return False
    102 
    10383    def __repr__(self):
    10484        return 'UNIXAddress(%r)' % (self.name,)
    10585
  • twisted/internet/test/test_address.py

     
    1010    def test_addressComparison(self):
    1111        """
    1212        Test that two different address instances, sharing the same
    13         properties are considered equal.
     13        properties are considered equal, testing both __eq__ and __ne__ methods
    1414        """
    1515        self.assertEquals(self.buildAddress(), self.buildAddress())
     16        self.assertFalse(self.buildAddress() != self.buildAddress())
    1617
    1718
    1819    def _stringRepresentation(self, stringFunction):