Package nss :: Module io :: Class AddrInfo
[hide private]
[frames] | no frames]

Class AddrInfo

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

Instance Methods [hide private]
 
__getitem__(x, y)
x[y]
 
__init__(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__len__(x)
len(x)
a new object with type S, a subtype of T

__new__(T, S, ...)
 
__repr__(x)
repr(x)
 
__str__(x)
str(x)

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  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

Inherited from object: __class__

Method Details [hide private]

__init__(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__

__new__(T, S, ...)

 


Returns:
a new object with type S, a subtype of T

Overrides: object.__new__

__repr__(x)
(Representation operator)

 
repr(x)

Overrides: object.__repr__

__str__(x)
(Informal representation operator)

 
str(x)

Overrides: object.__str__