type AddrInfo
object --+
|
AddrInfo
AddrInfo(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
An object used to encapsulate network address information for a
specific host.
After successful initialization the AddrInfo object will contain
an ordered sequence of NetworkAddress objects which may be
accessed via iteration or indexing. It is suggested you try connecting
with the each NetworkAddress object in sequential order until
one succeeds.
Example Usage:
try:
addr_info = io.AddrInfo(hostname)
except Exception, e:
print "ERROR: could not resolve address for %s" % hostname
return
for net_addr in addr_info:
net_addr.port = port
sock = io.Socket(net_addr.family)
try:
sock.connect(net_addr, timeout=io.seconds_to_interval(1))
return
except Exception, e:
pass
print "ERROR: could not connect to %s at port %d" % (hostname, port)
Note, the NSPR interface to getaddrinfo() does not provide a way to
select just IPv6 addresses. The solution is filter them yourself, e.g.:
for net_addr in addr_info:
if net_addr.family != io.PR_AF_INET6: continue
|
|
|
__init__(hostname,
family=PR_AF_UNSPEC,
flags=PR_AI_ADDRCONFIG)
x.__init__(...) initializes x; see help(type(x)) for signature |
|
|
|
|
a new object with type S, a subtype of T
|
|
|
|
|
canonical_name
Returns the canonical name associated with the IP address or None if not known
|
|
hostname
Returns the hostname this object was initialized from
|
__init__(hostname,
family=PR_AF_UNSPEC,
flags=PR_AI_ADDRCONFIG)
(Constructor)
|
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Parameters:
- Overrides:
object.__init__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|
__str__(x)
(Informal representation operator)
|
|
str(x)
- Overrides:
object.__str__
|