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

# Class Addr

source code

    object --+
             |
            Addr

Known Subclasses:
  - IP
  - , EUI

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: hash of this address suitable for dict keys, sets etc | source code
__int__(self) Returns: value of this address as a network byte order integer | source code
__long__(self) Returns: value of this address as a network byte order integer | source code
__str__(self) Returns: common string representation of this address | source code
__repr__(self) Returns: executable Python string to recreate equivalent object | source code
bits(self) Returns: human-readable binary digit string of this address | source code
packed(self) Returns: binary packed string of this address | source code
bin(self) Returns: standard Python binary representation of this address. | source code
__len__(self) Returns: The size (width) 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 referenced by index (both positive and negative). | source code
__setitem__(self, index, value) Sets the value of the word referenced by index in this address | source code
__hex__(self) Returns: network byte order hexadecimal string of this address | source code
__iadd__(self, num) Increment value of network address by specified amount. | source code
__isub__(self, num) Decrement value of network address by specified amount. | source code
__add__(self, other) Returns: A new (potentially larger) Addr class/subclass instance. | source code
__sub__(self, other) Returns: A new (potentially smaller) Addr class/subclass instance. | source code
__eq__(self, other) Returns: `True` if this address is numerically the same as other, `False` otherwise. | source code
__ne__(self, other) Returns: `True` if this address is not numerically the same other, `False` otherwise. | source code
__lt__(self, other) Returns: `True` if this address is numerically lower in value than other, `False` otherwise. | source code
__le__(self, other) Returns: `True` if this address is numerically lower or equal in value to other, `False` otherwise. | source code
__gt__(self, other) Returns: `True` if this address is numerically greater in value than other, `False` otherwise. | source code
__ge__(self, other) Returns: `True` if this address is numerically greater or equal in value to other, `False` otherwise. | source code
__or__(self, other) Returns: bitwise OR (x | y) of self.value with other.value. | source code
__and__(self, other) Returns: bitwise AND (x & y) of self.value with other.value. | source code
__xor__(self, other) Returns: bitwise exclusive OR (x ^ y) of self.value with other.value. | source code
__lshift__(self, numbits) Returns: integer value of this IP address shifted left by x bits. | source code
__rshift__(self, numbits) Returns: integer value of this IP address right shifted by x bits. | source code
__invert__(self, other) Returns: inversion (~x) of self.value. | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`

Class Variables
| STRATEGIES = ``(`IPv4StrategyOpt(32, 8, '.', 4, 10, False)`,` IPv6S`...``
| 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: hash of this address suitable for dict keys, sets etc Overrides: object.__hash__

### __int__(self) | source code
Returns: value of this address as a network byte order integer

### __long__(self) | source code
Returns: value of this address as a network byte order integer

### __str__(self) (Informal representation operator) | source code
str(x) Returns: common string representation of this address Overrides: object.__str__

### __repr__(self) (Representation operator) | source code
repr(x) Returns: executable Python string to recreate equivalent object Overrides: object.__repr__

### bits(self) | source code
Returns: human-readable binary digit string of this address

### packed(self) | source code
Returns: binary packed string of this address

### bin(self) | source code
Returns: standard Python binary representation of this address. A back port of the format provided by the builtin bin() type available in Python 2.6.x and higher.

### __len__(self) (Length operator) | source code
Returns: The size (width) 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 referenced by index (both positive and negative). Raises `IndexError` if index is out of bounds. Also supports Python list slices for accessing word groups.

### __hex__(self) | source code
Returns: network byte order hexadecimal string of this address

### __iadd__(self, num) | source code
Increment value of network address by specified amount. Behaves like an unsigned integer, rolling over to zero when it reaches the maximum value threshold. Parameters: `num` - size of increment

### __isub__(self, num) | source code
Decrement value of network address by specified amount. Behaves like an unsigned integer, rolling over to maximum value when it goes below zero. Parameters: `num` - size of decrement

### __add__(self, other) (Addition operator) | source code
Parameters: `other` - an integer or int-like object. Returns: A new (potentially larger) Addr class/subclass instance.

### __sub__(self, other) (Subtraction operator) | source code
Parameters: `other` - an integer or int-like object. Returns: A new (potentially smaller) Addr class/subclass instance.

### __eq__(self, other) (Equality operator) | source code
Returns: `True` if this address is numerically the same as other, `False` otherwise.

### __ne__(self, other) | source code
Returns: `True` if this address is not numerically the same other, `False` otherwise.

### __lt__(self, other) (Less-than operator) | source code
Returns: `True` if this address is numerically lower in value than other, `False` otherwise.

### __le__(self, other) (Less-than-or-equals operator) | source code
Returns: `True` if this address is numerically lower or equal in value to other, `False` otherwise.

### __gt__(self, other) (Greater-than operator) | source code
Returns: `True` if this address is numerically greater in value than other, `False` otherwise.

### __ge__(self, other) (Greater-than-or-equals operator) | source code
Returns: `True` if this address is numerically greater or equal in value to other, `False` otherwise.

### __or__(self, other) (Or operator) | source code
Parameters: `other` - an integer or int-like object. Returns: bitwise OR (x | y) of self.value with other.value.

### __and__(self, other) (And operator) | source code
Parameters: `other` - an integer or int-like object. Returns: bitwise AND (x & y) of self.value with other.value.

### __xor__(self, other) (Exclusive-Or operator) | source code
Parameters: `other` - an integer or int-like object. Returns: bitwise exclusive OR (x ^ y) of self.value with other.value.

### __lshift__(self, numbits) | source code
Parameters: `numbits` - size of shift (in bits). Returns: integer value of this IP address shifted left by x bits.

### __rshift__(self, numbits) | source code
Parameters: `numbits` - size of shift (in bits). Returns: integer value of this IP address right shifted by x bits.

### __invert__(self, other) | source code
Parameters: `other` - an integer or int-like object. Returns: inversion (~x) of self.value.

Class Variable Details

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