| Home | Trees | Indices | Help |
|---|
|
|
object --+
|
AddrInfo
AddrInfo(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
:Parameters:
hostname : str or unicode object
Either a hostname or an address string (dotted-decimal for IPv4
or a hex string for IPv6.
family : int
May be:
- PR_AF_UNSPEC
- PR_AF_INET.
flags : int
May be either:
- PR_AI_ADDRCONFIG
- PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME
Include PR_AI_NOCANONNAME to suppress the determination of
the canonical name corresponding to hostname.
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
|
|||
|
|||
|
|||
|
|||
a new object with type S, a subtype of T |
|
||
|
|||
|
|||
|
Inherited from |
|||
|
|||
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
|
|
repr(x)
|
str(x)
|
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Oct 27 13:05:34 2012 | http://epydoc.sourceforge.net |