[Twisted-Python] Reliable way to check if Twisted has IPv6 support?
![](https://secure.gravatar.com/avatar/ed6cdd53017b6eae7c345f77b94a856e.jpg?s=120&d=mm&r=g)
Hello, I have a code path similar to: if Twisted has IPv6: # do this else: # do that I came up with this: Using 'getattr' to get a function which wouldn't exist if there was no IPv6 address as follows:
Is there a more reliable way (which works with the Twisted-8.0+) to check this? Thanks, Amit. -- Amit Saha <http://echorand.me>
![](https://secure.gravatar.com/avatar/426d6dbf6554a9b3fca1fd04e6b75f38.jpg?s=120&d=mm&r=g)
On 13/12/13 03:22, Amit Saha wrote:
Is there a more reliable way (which works with the Twisted-8.0+) to check this?
Check the Twisted version. You should also note that IPv6 features have appeared in multiple versions; HostnameEndpoint was added in 13.2.0 for example, whereas basic "connectTCP to IPv6 address" was added in 12.1.0, with listenTCP in 12.0.0 So: import twisted vt = (twisted.version.major, twisted.version.minor) if vt > (13,2): def connectv6name(n): return HostnameEndpoint(...) elif vt > (12,1): def connectv6name(n): d = myGetAddrInfo(...) d.addCallback(reactor.connectTCP, ...) else: def connectv6name(n): raise Exception('twisted too old for IPv6')
![](https://secure.gravatar.com/avatar/ed6cdd53017b6eae7c345f77b94a856e.jpg?s=120&d=mm&r=g)
----- Original Message -----
Thanks a lot, Phil. I think using the version information is a more reliable way. I had a feeling that the various bits and pieces may have been added incrementally. The functionality I need present are listenTCP() and connectTCP() to work with IPv6, so I think checking for 12.1.0 will suit my needs. Best, Amit. -- Amit Saha <http://echorand.me>
![](https://secure.gravatar.com/avatar/426d6dbf6554a9b3fca1fd04e6b75f38.jpg?s=120&d=mm&r=g)
On 13/12/13 03:22, Amit Saha wrote:
Is there a more reliable way (which works with the Twisted-8.0+) to check this?
Check the Twisted version. You should also note that IPv6 features have appeared in multiple versions; HostnameEndpoint was added in 13.2.0 for example, whereas basic "connectTCP to IPv6 address" was added in 12.1.0, with listenTCP in 12.0.0 So: import twisted vt = (twisted.version.major, twisted.version.minor) if vt > (13,2): def connectv6name(n): return HostnameEndpoint(...) elif vt > (12,1): def connectv6name(n): d = myGetAddrInfo(...) d.addCallback(reactor.connectTCP, ...) else: def connectv6name(n): raise Exception('twisted too old for IPv6')
![](https://secure.gravatar.com/avatar/ed6cdd53017b6eae7c345f77b94a856e.jpg?s=120&d=mm&r=g)
----- Original Message -----
Thanks a lot, Phil. I think using the version information is a more reliable way. I had a feeling that the various bits and pieces may have been added incrementally. The functionality I need present are listenTCP() and connectTCP() to work with IPv6, so I think checking for 12.1.0 will suit my needs. Best, Amit. -- Amit Saha <http://echorand.me>
participants (2)
-
Amit Saha
-
Phil Mayers