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

# Class AddrStrategy

source code

    object --+
             |
            AddrStrategy

Known Subclasses:
  - EUI48Strategy
  - , IPv4StrategyStd
  - , IPv6Strategy

Basic support for common operations performed on each address type

Instance Methods
__init__(self, width, word_size, word_sep, word_fmt=`'``%x``'`, addr_type=0, word_base=16, uppercase=False) Constructor. | source code
__repr__(self) Returns: executable Python string to recreate equivalent object | source code
valid_bits(self, bits) Returns: `True` if network address is valid for this address type, `False` otherwise. | source code
bits_to_int(self, bits) Returns: A network byte order integer that is equivalent to value represented by network address in readable binary form. | source code
valid_int(self, int_val) Returns: `True` if network byte order integer falls within the boundaries of this address type, `False` otherwise. | source code
int_to_str(self, int_val) Returns: A network address in string form that is equivalent to value represented by a network byte order integer. | source code
int_to_bits(self, int_val) Returns: A network address in readable binary form that is equivalent to value represented by a network byte order integer. | source code
int_to_bin(self, int_val) Returns: A network address in standard binary representation format that is equivalent to integer address value. | source code
int_to_words(self, int_val, num_words=None, word_size=None) | source code
int_to_packed(self, int_val) Returns: a packed string that is equivalent to value represented by a network byte order integer. | source code
packed_to_int(self, packed_int) Returns: A network byte order integer that is equivalent to value of network address represented by packed binary string. | source code
valid_str(self, addr) Returns: `True` if network address in string form is valid for this address type, `False` otherwise. | source code
str_to_int(self, addr) Returns: A network byte order integer that is equivalent to value represented by network address in string form. | source code
valid_words(self, words) Returns: `True` if word sequence is valid for this address type, `False` otherwise. | source code
words_to_int(self, words) Returns: A network byte order integer that is equivalent to value represented by word sequence. | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Class Variables
| STRUCT_FORMATS = ``{`8`:` `'``B``'``,` 16`:` `'``H``'``,` 32`:` `'``I``'``}`` Lookup table for struct module format strings.

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, width, word_size, word_sep, word_fmt=`'``%x``'`, addr_type=0, word_base=16, uppercase=False) (Constructor) | source code
Constructor. Parameters: `width` - size of address in bits. (e.g. 32 - IPv4, 48 - MAC, 128 - IPv6) `word_size` - size of each word. (e.g. 8 - octets, 16 - hextets) `word_sep` - separator between each word. (e.g. '.' - IPv4, ':' - IPv6, '-' - EUI-48) `word_fmt` - format string for each word. (Default: '%x') `addr_type` - address type. (Default: AT_UNSPEC) `word_base` - number base used to convert each word using int(). (Default: 16) `uppercase` - uppercase address. (Default: False) Overrides: object.__init__

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

### valid_bits(self, bits) | source code
Parameters: `bits` - A network address in readable binary form. Returns: `True` if network address is valid for this address type, `False` otherwise.

### bits_to_int(self, bits) | source code
Parameters: `bits` - A network address in readable binary form. Returns: A network byte order integer that is equivalent to value represented by network address in readable binary form.

### valid_int(self, int_val) | source code
Parameters: `int_val` - A network byte order integer. Returns: `True` if network byte order integer falls within the boundaries of this address type, `False` otherwise.

### int_to_str(self, int_val) | source code
Parameters: `int_val` - A network byte order integer. Returns: A network address in string form that is equivalent to value represented by a network byte order integer.

### int_to_bits(self, int_val) | source code
Parameters: `int_val` - A network byte order integer. Returns: A network address in readable binary form that is equivalent to value represented by a network byte order integer.

### int_to_bin(self, int_val) | source code
Parameters: `int_val` - A network byte order integer. Returns: A network address in standard binary representation format that is equivalent to integer address value. Essentially a back port of the bin() builtin in Python 2.6.x and higher.

### int_to_words(self, int_val, num_words=None, word_size=None) | source code
Parameters: `int_val` - A network byte order integer to be split. `num_words` - (optional) number of words expected in return value tuple. Uses address type default if not specified. `word_size` - (optional) size/width of individual words (in bits). Uses address type default if not specified.

### int_to_packed(self, int_val) | source code
Parameters: `int_val` - the integer to be packed. Returns: a packed string that is equivalent to value represented by a network byte order integer.

### packed_to_int(self, packed_int) | source code
Parameters: `packed_int` - a packed string containing an unsigned integer. Network byte order is assumed. Returns: A network byte order integer that is equivalent to value of network address represented by packed binary string.

### valid_str(self, addr) | source code
Parameters: `addr` - A network address in string form. Returns: `True` if network address in string form is valid for this address type, `False` otherwise.

### str_to_int(self, addr) | source code
Parameters: `addr` - A network address in string form. Returns: A network byte order integer that is equivalent to value represented by network address in string form.

### valid_words(self, words) | source code
Parameters: `words` - A sequence containing integer word values. Returns: `True` if word sequence is valid for this address type, `False` otherwise.

### words_to_int(self, words) | source code
Parameters: `words` - A list or tuple containing integer word values. Returns: A network byte order integer that is equivalent to value represented by word sequence.