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

Class AddrRange

source code

object --+
         |
        AddrRange
Known Subclasses:

A block of contiguous network addresses bounded by an arbitrary start and stop address. There is no requirement that they fall on strict bit mask boundaries, unlike CIDR addresses.

The only network address aggregate supporting all network address types. Most AddrRange subclasses only support a subset of address types.

Instance Methods
 
__init__(self, start_addr, stop_addr, klass=None)
Constructor.
source code
 
__setattr__(self, name, value)
Police assignments to various class attributes to ensure nothing gets broken accidentally.
source code
 
first(self)
Returns: The lower boundary network address of this range.
source code
 
last(self)
Returns: The upper boundary network address of this range.
source code
 
__len__(self)
Returns: The total number of network addresses in this range.
source code
 
size(self)
Returns: The total number of network addresses in this range.
source code
 
__getitem__(self, index)
Returns: The network address(es) in this address range indicated by index/slice.
source code
 
__iter__(self)
Returns: An iterator object providing access to all network addresses within this range.
source code
 
__contains__(self, addr)
Returns: True if given address or range falls within this range, False otherwise.
source code
 
__eq__(self, other)
Returns: True if the boundary of this range is the same as other, False otherwise.
source code
 
__ne__(self, other)
Returns: True if the boundary of this range is not the same as other, False otherwise.
source code
 
__lt__(self, other)
Returns: True if the lower boundary of this range is less than other, False otherwise.
source code
 
__le__(self, other)
Returns: True if the lower boundary of this range is less or equal to other, False otherwise.
source code
 
__gt__(self, other)
Returns: True if the lower boundary of this range is greater than other, False otherwise.
source code
 
__ge__(self, other)
Returns: True if the lower boundary of this range is greater or equal to other, False otherwise.
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
Returns: An executable Python statement that can recreate an object with an equivalent state.
source code

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

Properties

Inherited from object: __class__

Method Details

__init__(self, start_addr, stop_addr, klass=None)
(Constructor)

source code 

Constructor.

Parameters:
  • start_addr - start address for this network address range.
  • stop_addr - stop address for this network address range.
  • klass - (optional) class used to create each object returned. Default: Addr() objects. See nrange() documentations for additional details on options.
Overrides: object.__init__

__setattr__(self, name, value)

source code 

Police assignments to various class attributes to ensure nothing gets broken accidentally.

Overrides: object.__setattr__

first(self)

source code 
Returns:
The lower boundary network address of this range.

last(self)

source code 
Returns:
The upper boundary network address of this range.

__len__(self)
(Length operator)

source code 
Returns:
The total number of network addresses in this range.
  • Use this method only for ranges that contain less than 2^31 addresses or try the size() method. Raises an IndexError if size is exceeded.

size(self)

source code 
Returns:
The total number of network addresses in this range.
  • Use this method in preference to __len__() when size of ranges exceeds 2^31 addresses.

__getitem__(self, index)
(Indexing operator)

source code 
Returns:
The network address(es) in this address range indicated by index/slice. Slicing objects can produce large sequences so generator objects are returned instead to the usual sequences. Wrapping a raw slice with list() or tuple() may be required dependent on context.

__iter__(self)

source code 
Returns:
An iterator object providing access to all network addresses within this range.

__contains__(self, addr)
(In operator)

source code 
Parameters:
  • addr - object of Addr/AddrRange (sub)class or a network address string to be compared.
Returns:
True if given address or range falls within this range, False otherwise.

__eq__(self, other)
(Equality operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundary of this range is the same as other, False otherwise.

__ne__(self, other)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundary of this range is not the same as other, False otherwise.

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

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the lower boundary of this range is less than other, False otherwise.

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

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the lower boundary of this range is less or equal to other, False otherwise.

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

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the lower boundary of this range is greater than other, False otherwise.

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

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the lower boundary of this range is greater or equal to other, False otherwise.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__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__