[Twisted-Python] IPv6 comparison handling
Hello, In my UDP Twisted based library there is a problem with IPv6 addresses representation. Addresses are compared as simple strings, and it sometimes causes mismatches: "fe80::aaaa:bbff:fecc:dddd" should be equal to "fe80:0000:0000:0000:aaaa:bbff:fecc:dddd" I've noticed that Python 3 has nice new module "ipaddress" exactly for this kind of problems, and it has been backported to Python 2.7. Before I add it as a new dependency I wanted to ask if maybe Twisted has some other suggested solution for this problem? Best Regards Maciej Wasilak
On Apr 24, 2016, at 12:21 PM, Maciej Wasilak <wasilak@gmail.com> wrote:
Hello,
In my UDP Twisted based library there is a problem with IPv6 addresses representation. Addresses are compared as simple strings, and it sometimes causes mismatches:
"fe80::aaaa:bbff:fecc:dddd" should be equal to "fe80:0000:0000:0000:aaaa:bbff:fecc:dddd"
I've noticed that Python 3 has nice new module "ipaddress" exactly for this kind of problems, and it has been backported to Python 2.7. Before I add it as a new dependency I wanted to ask if maybe Twisted has some other suggested solution for this problem?
You should probably use ipaddress. Twisted's facilities in this area are somewhat primitive, and should be improved; particularly, you _should_ be able to do: a = IPv6Address("UDP", "fe80::", 0) b = IPv6Address("UDP", "fe80::00:00", 0) a == b but right now that doesn't work. A patch that fixes it would be much appreciated though! -glyph
participants (2)
-
Glyph
-
Maciej Wasilak