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

Class Addr

source code

object --+
         |
        Addr
Known Subclasses:

A class whose objects represent network addresses of different types based on arguments passed to the constructor.

The address type can either be auto-detected from the string form of the address or specified explicitly via the second argument.

The behaviour of this class varies depending on the type of address that it represents.

Instance Methods
 
__init__(self, addr, addr_type=0)
Constructor.
source code
 
setvalue(self, addr)
Sets the value of this address.
source code
 
__int__(self)
Returns the value of this address as an network byte order int, if possible.
source code
 
__long__(self)
Returns the value of this address as a network byte order long int.
source code
 
__str__(self)
Return the string representation for this address.
source code
 
bits(self)
Return a human-readable binary digit string representation of this address.
source code
 
__len__(self)
Return the size of this address (in bits).
source code
 
__iter__(self)
Provide an iterator over words (based on word_size) in this address.
source code
 
__getitem__(self, index)
Return the integer value of the word indicated by index.
source code
 
__setitem__(self, index, value)
Set 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 string.
source code
 
__iadd__(self, increment)
Increment the value of this network address by the specified value.
source code
 
__isub__(self, decrement)
Decrement the value of this network address by specified value.
source code
 
__eq__(self, other)
True if this network address instance has the same numerical value as another, False otherwise.
source code
 
__lt__(self, other)
True if this network address instance has a lower numerical value than another, False otherwise.
source code
 
__le__(self, other)
True if this network address instance has a lower or equivalent numerical value than another, False otherwise.
source code
 
__gt__(self, other)
True if this network address instance has a higher numerical value than another, False otherwise.
source code
 
__ge__(self, other)
True if this network address instance has a higher or equivalent numerical value than another, False otherwise.
source code

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

Properties

Inherited from object: __class__

Method Details

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

source code 

Constructor.

addr - the string form of a network address, or a network byte order int/long value within the supported range for the address type.

addr_type - (optional) the network address type. If addr is an int or long, this argument becomes mandatory.

Overrides: object.__init__

setvalue(self, addr)

source code 

Sets the value of this address.

addr - the string form of a network address, or a network byte order int/long value within the supported range for the address type.

Raises a TypeError if addr is of an unsupported type.

Raises an OverflowError if addr is an int/long value that is is out of bounds for the address type this instance represents.

__int__(self)

source code 

Returns the value of this address as an network byte order int, if possible.

If the value of int is greater than 2 ** 31 - 1, a long is returned instead of an int (standard Python behaviour).

__long__(self)

source code 

Returns the value of this address as a network byte order long int.

If the value of int is less than 2 ** 31 - 1, an int is returned instead of a long (standard Python behaviour).

__str__(self)
(Informal representation operator)

source code 

Return the string representation for this address. Format varies dependent on address type.

Overrides: object.__str__

__getitem__(self, index)
(Indexing operator)

source code 

Return the integer value of the word indicated by index. Raises an IndexError exception if index is wrong size for address type

Full slicing support is also available.

__iadd__(self, increment)

source code 

Increment the value of this network address by the specified value.

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

__isub__(self, decrement)

source code 

Decrement the value of this network address by specified value.

If the result is lower than the address type mininum value it rolls around the maximum boundary value.