if address_less is NotImplemented:
return NotImplemented
try:
- return self.network < other.network
+ return (self.network < other.network or
+ self.network == other.network and address_less)
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
if address_less is NotImplemented:
return NotImplemented
try:
- return self.network < other.network
+ return (self.network < other.network or
+ self.network == other.network and address_less)
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
ipaddress.ip_address('::2'))
def testInterfaceComparison(self):
- self.assertTrue(ipaddress.ip_interface('1.1.1.1') <=
- ipaddress.ip_interface('1.1.1.1'))
- self.assertTrue(ipaddress.ip_interface('1.1.1.1') <=
- ipaddress.ip_interface('1.1.1.2'))
- self.assertTrue(ipaddress.ip_interface('::1') <=
- ipaddress.ip_interface('::1'))
- self.assertTrue(ipaddress.ip_interface('::1') <=
- ipaddress.ip_interface('::2'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') ==
+ ipaddress.ip_interface('1.1.1.1/24'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.1/16') <
+ ipaddress.ip_interface('1.1.1.1/24'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') <
+ ipaddress.ip_interface('1.1.1.2/24'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.2/16') <
+ ipaddress.ip_interface('1.1.1.1/24'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
+ ipaddress.ip_interface('1.1.1.1/16'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.2/24') >
+ ipaddress.ip_interface('1.1.1.1/24'))
+ self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
+ ipaddress.ip_interface('1.1.1.2/16'))
+
+ self.assertTrue(ipaddress.ip_interface('::1/64') ==
+ ipaddress.ip_interface('::1/64'))
+ self.assertTrue(ipaddress.ip_interface('::1/64') <
+ ipaddress.ip_interface('::1/80'))
+ self.assertTrue(ipaddress.ip_interface('::1/64') <
+ ipaddress.ip_interface('::2/64'))
+ self.assertTrue(ipaddress.ip_interface('::2/48') <
+ ipaddress.ip_interface('::1/64'))
+ self.assertTrue(ipaddress.ip_interface('::1/80') >
+ ipaddress.ip_interface('::1/64'))
+ self.assertTrue(ipaddress.ip_interface('::2/64') >
+ ipaddress.ip_interface('::1/64'))
+ self.assertTrue(ipaddress.ip_interface('::1/64') >
+ ipaddress.ip_interface('::2/48'))
def testNetworkComparison(self):
# ip1 and ip2 have the same network address