Package netaddr :: Module address :: Class Addr
[frames] | no frames]

Class Addr

source code

object --+
         |
        Addr
Known Subclasses:

The base class containing common functionality for all subclasses representing various network address types.

It is a fully functioning class (as opposed to a virtual class) with a heuristic constructor that detects the type of address via the first argument if it is a string and sets itself up accordingly. If the first argument is an integer, then a constant must be provided via the second argument indicating the address type explicitly.

Objects of this class behave differently dependent upon the type of address they represent.

Instance Methods
 
__init__(self, addr, addr_type=0)
Constructor.
source code
 
__hash__(self)
Returns: The hash of this address.
source code
 
__int__(self)
Returns: The value of this address as an network byte order integer.
source code
 
__long__(self)
Returns: The value of this address as an network byte order integer.
source code
 
__str__(self)
Returns: The common string representation for this address type.
source code
 
__repr__(self)
Returns: An executable Python statement that can recreate an object with an equivalent state.
source code
 
bits(self)
Returns: A human-readable binary digit string for this address type.
source code
 
__len__(self)
Returns: The size of this address (in bits).
source code
 
__iter__(self)
Returns: An iterator over individual words in this address.
source code
 
__getitem__(self, index)
Returns: The integer value of the word indicated by index.
source code
 
__setitem__(self, index, value)
Sets the value of the word of this address indicated by index.
source code
 
__hex__(self)
Returns: The value of this address as a network byte order hexadecimal number.
source code
 
__iadd__(self, i)
Increments network address by specified value.
source code
 
__isub__(self, i)
Decrements network address by specified value.
source code
 
__eq__(self, other)
Returns: True if this network address instance has the same numerical value as another, False otherwise.
source code
 
__ne__(self, other)
Returns: True if this network address instance does not have the same numerical value as another, False otherwise.
source code
 
__lt__(self, other)
Returns: True if this network address instance has a lower numerical value than another, False otherwise.
source code
 
__le__(self, other)
Returns: True if this network address instance has a lower or equivalent numerical value than another, False otherwise.
source code
 
__gt__(self, other)
Returns: True if this network address instance has a higher numerical value than another, False otherwise.
source code
 
__ge__(self, other)
Returns: True if this network address instance has a higher or equivalent numerical value than another, False otherwise.
source code

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables
  STRATEGIES = (netaddr.address.IPv4StrategyOpt(32, 8, '.', 4, F...
  ADDR_TYPES = (0, 4, 6, 48, 64)
  value = AddrValueDescriptor('value')
  strategy = StrategyDescriptor(STRATEGIES)
  addr_type = AddrTypeDescriptor(ADDR_TYPES)
Properties

Inherited from object: __class__

Method Details

__init__(self, addr, addr_type=0)
(Constructor)

source code 

Constructor.

Parameters:
  • addr - the string form of a network address, or a network byte order integer within the supported range for the address type.
  • addr_type - (optional) the network address type. If addr is an integer, this argument becomes mandatory.
Overrides: object.__init__

__hash__(self)
(Hashing function)

source code 

hash(x)

Returns:
The hash of this address. Allows it to be used in sets and as a key in dictionaries.
Overrides: object.__hash__

__int__(self)

source code 
Returns:
The value of this address as an network byte order integer.

__long__(self)

source code 
Returns:
The value of this address as an network byte order integer.

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns:
The common string representation for this address type.
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns:
An executable Python statement that can recreate an object with an equivalent state.
Overrides: object.__repr__

bits(self)

source code 
Returns:
A human-readable binary digit string for this address type.

__len__(self)
(Length operator)

source code 
Returns:
The size of this address (in bits).

__iter__(self)

source code 
Returns:
An iterator over individual words in this address.

__getitem__(self, index)
(Indexing operator)

source code 
Returns:
The integer value of the word indicated by index. Raises an IndexError if index is wrong size for address type. Full slicing is also supported.

__hex__(self)

source code 
Returns:
The value of this address as a network byte order hexadecimal number.

__iadd__(self, i)

source code 

Increments network address by specified value.

If the result exceeds address type maximum, it rolls around the minimum boundary.

__isub__(self, i)

source code 

Decrements network address by specified value.

If the result exceeds address type minimum, it rolls around the maximum boundary.

__eq__(self, other)
(Equality operator)

source code 
Returns:
True if this network address instance has the same numerical value as another, False otherwise.

__ne__(self, other)

source code 
Returns:
True if this network address instance does not have the same numerical value as another, False otherwise.

__lt__(self, other)
(Less-than operator)

source code 
Returns:
True if this network address instance has a lower numerical value than another, False otherwise.

__le__(self, other)
(Less-than-or-equals operator)

source code 
Returns:
True if this network address instance has a lower or equivalent numerical value than another, False otherwise.

__gt__(self, other)
(Greater-than operator)

source code 
Returns:
True if this network address instance has a higher numerical value than another, False otherwise.

__ge__(self, other)
(Greater-than-or-equals operator)

source code 
Returns:
True if this network address instance has a higher or equivalent numerical value than another, False otherwise.

Class Variable Details

STRATEGIES

Value:
(netaddr.address.IPv4StrategyOpt(32, 8, '.', 4, False, False),
 netaddr.address.IPv6Strategy(128, 16, ':', 6, True, False),
 netaddr.address.EUI48Strategy(48, 8, '-', 48, True, True),
 netaddr.address.AddrStrategy(64, 8, '-', 64, True, True))