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

Class AddrRange

source code

object --+
         |
        AddrRange
Known Subclasses:

Represents 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.

This is the only network address aggregate class that supports all network address types (essentially Addr (sub)class objects). Most if not all subclasses of AddrRange tend towards support for only a subset of address types.

Instance Methods
 
__init__(self, start_addr, stop_addr, klass=None)
Constructor.
source code
 
first(self)
Returns the Addr instance for the lower boundary of this network address range.
source code
 
last(self)
Returns the Addr instance for the upper boundary of this network address range.
source code
 
__len__(self)
Return total number of addresses to be found in this address range.
source code
 
size(self)
Return total number of addresses to be found in this address range.
source code
 
__getitem__(self, index)
Return the Addr instance from this address range indicated by index or slice.
source code
 
__iter__(self)
Returns an iterator object providing lazily evaluated access to all Addr() instances within this network address range.
source code
 
__contains__(self, addr)
Returns True if given address or address range falls within the boundary of this network address False otherwise.
source code
 
__eq__(self, other)
True if the boundary addresses of this address range are the same as those of the other and the address types they represent are the same, False otherwise.
source code
 
__ne__(self, other)
True if the boundary addresses of this address range are not the same as those of the other, False otherwise.
source code
 
__lt__(self, other)
True if the lower boundary address of this address range is less than that of the other and the address types they represent are the same, False otherwise.
source code
 
__le__(self, other)
True if the lower boundary address of this address range is less than or equal to that of the other and the address types they represent are the same, False otherwise.
source code
 
__gt__(self, other)
True if the lower boundary address of this address range is greater than that of the other and the address types they represent are the same, False otherwise.
source code
 
__ge__(self, other)
True if the lower boundary address of this address range is greater than or equal to that of the other and the address types they represent are the same, False otherwise.
source code
 
__str__(self)
str(x)
source code

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

Properties

Inherited from object: __class__

Method Details

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

source code 

Constructor.

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 return object. Default: Addr objects. See nrange() documentations for additional details on options.

Overrides: object.__init__

__len__(self)
(Length operator)

source code 

Return total number of addresses to be found in this address range.

NB - Use this method only for ranges that contain less than 2 ** 31 addresses. Raises an IndexError if size is exceeded.

size(self)

source code 

Return total number of addresses to be found in this address range.

NB - Use this method in preference to __len__() when size of ranges exceeds 2 ** 31 addresses.

__getitem__(self, index)
(Indexing operator)

source code 

Return the Addr instance from this address range indicated by index or slice.

Raises an IndexError exception if index is out of bounds in relation to size of address range.

Slicing objects of this class can potentially produce truly massive sequences so generators are returned in preference to sequences. The extra step of wrapping a raw slice with list() or tuple() may be required dependent on context.

__contains__(self, addr)
(In operator)

source code 

Returns True if given address or address range falls within the boundary of this network address False otherwise.

addr - object of (sub)class Addr/AddrRange or string based address to be compared.

__ne__(self, other)

source code 

True if the boundary addresses of this address range are not the same as those of the other, False otherwise.

Raises a TypeError if address type of other is not the same as self.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)