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

type NetworkAddress

object --+
         |
        NetworkAddress

NetworkAddress(addr, port=0, family=PR_AF_INET)

If addr argument is a string it may be either a numeric address or a DNS host name and is passed to the AddrInfo constructor along with the family parameter. The first address in the AddrInfo object is selected. If you need more fine grained control over which address is selected from the AddrInfo object then invoke AddrInfo and select one of the NetworkAddress it provides.

If the addr argument is an integer it may be one of the following constants:

PR_IpAddrNull
Do not set the IP address, only set the port. NetworkAddress(PR_IpAddrNull, 123) is equivalent to NetworkAddress(port=123)
PR_IpAddrAny
Assign logical PR_INADDR_ANY to IP address. This wildcard value is typically used to establish a socket on which to listen for incoming connection requests.
PR_IpAddrLoopback
Assign logical PR_INADDR_LOOPBACK. A client can use this value to connect to itself without knowing the host's network address.
PR_IpAddrV4Mapped
Use IPv4 mapped address

The optional port argument sets the port number in the NetworkAddress object. The port number may be modfied later by assigning to the port attribute.

Example:

netaddr = nss.io.NetworkAddress('www.python.org')
print '%s %s' % (netaddr, netaddr.hostname)
netaddr = nss.io.NetworkAddress('82.94.237.218')
print '%s %s' % (netaddr, netaddr.hostname)

Output:
82.94.237.218:0 www.python.org
82.94.237.218:0 dinsdale.python.org

WARNING: NetworkAddress initialization from a string only works with IPv4 and its use should be considered deprecated. Use AddrInfo instead.

Instance Methods [hide private]
 
__init__(addr, port=0, family=PR_AF_INET)
x.__init__(...) initializes x; see help(type(x)) for signature
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__str__(x)
str(x)
 
set_from_string(addr, family=PR_AF_INET)
Reinitializes the NetworkAddress object given a string.
Properties [hide private]
  address
address as string
  family
address family (e.g.
  hostentry
HostEntry object representing this NetworkAddress (Warning: Deprecated, use AddrInfo instead)
  hostname
If an address string was used to construct this NetworkAddress then return the canonical hostname if available, otherwise the original address string
  port
network address port
Method Details [hide private]

__init__(addr, port=0, family=PR_AF_INET)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Parameters:
  • addr (string or integer) - may be an int or a string.
  • port (integer) - port number
  • family (integer) -
    one of:
    • PR_AF_INET
    • PR_AF_INET6
Overrides: object.__init__

__new__(T, S, ...)

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

__str__(x)
(Informal representation operator)

 
str(x)
Overrides: object.__str__

set_from_string(addr, family=PR_AF_INET)

 

Reinitializes the NetworkAddress object given a string. Identical to constructing nss.io.NetworkAddress() with a string value (see NetworkAddress constructor for documentation).

WARNING: NetworkAddress initialization from a string only works with IPv4 and its use should be considered deprecated. Use AddrInfo instead.

Parameters:
  • addr (string) - the address string to convert
  • family (integer) -
    one of:
    • PR_AF_INET
    • PR_AF_INET6
    • PR_AF_UNSPEC

Property Details [hide private]

family

address family (e.g. PR_AF_INET, etc.)