[Twisted-Python] Reliable way to check if Twisted has IPv6 support?

Amit Saha asaha at redhat.com
Mon Jan 6 23:06:25 MST 2014



----- Original Message -----
> From: "Phil Mayers" <p.mayers at imperial.ac.uk>
> To: twisted-python at twistedmatrix.com
> Sent: Friday, December 13, 2013 8:41:44 PM
> Subject: Re: [Twisted-Python] Reliable way to check if Twisted has IPv6	support?
> 
> 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')

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>



More information about the Twisted-Python mailing list