Package netaddr :: Module strategy :: Class IPv4Strategy
[frames] | no frames]

Class IPv4Strategy

source code

  object --+    
           |    
AddrStrategy --+
               |
              IPv4Strategy

An optimised AddrStrategy for IP version 4 address processing.

It uses the struct module's pack() and unpack() along with the socket module's inet_ntoa() and inet_aton() functions making it almost 2.5 times faster than a standard AddrStrategy configured for processing IPv4.

However, bear in mind that these modules might not be available everywhere. Runtimes such as Google App Engine gut the socket module. struct is also limited to processing 32-bit integer which is fine here but isn't suitable for 128-bit IPv6 processing.

Instance Methods
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
str_to_int(self, addr)
Returns a network byte order integer that is equivalent to value represented by the IPv4 dotted decimal address string.
source code
 
int_to_str(self, int_val)
Returns an IPv4 dotted decimal address string that is equivalent to value represented by a 32 bit integer in network byte order.
source code
 
int_to_words(self, int_val)
Returns an integer word (octet) sequence that is equivalent to value represented by network byte order integer.
source code
 
words_to_int(self, octets)
Returns a network byte order integer that is equivalent to value represented by word (octet) sequence.
source code
 
int_to_arpa(self, int_val)
Returns the reverse DNS lookup for an IPv4 address in network byte order integer form.
source code

Inherited from AddrStrategy: bits_to_int, bits_to_str, bits_to_words, description, int_to_bits, str_to_bits, str_to_words, valid_bits, valid_int, valid_str, valid_words, word_to_bits, words_to_bits, words_to_str

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

Properties

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

str_to_int(self, addr)

source code 

Returns a network byte order integer that is equivalent to value represented by the IPv4 dotted decimal address string.

Overrides: AddrStrategy.str_to_int

int_to_str(self, int_val)

source code 

Returns an IPv4 dotted decimal address string that is equivalent to value represented by a 32 bit integer in network byte order.

Overrides: AddrStrategy.int_to_str

int_to_words(self, int_val)

source code 

Returns an integer word (octet) sequence that is equivalent to value represented by network byte order integer.

Overrides: AddrStrategy.int_to_words

words_to_int(self, octets)

source code 

Returns a network byte order integer that is equivalent to value represented by word (octet) sequence.

Overrides: AddrStrategy.words_to_int