Package netaddr :: Module strategy :: Class EUI48Strategy |
[hide private]
[frames] | no frames]

# Class EUI48Strategy

source code

      object --+
               |
    AddrStrategy --+
                   |
                  EUI48Strategy

Implements the operations that can be performed on an IEEE 48-bit EUI (Extended Unique Identifer) a.k.a. a MAC (Media Access Control) layer 2 address.

Supports all common (and some less common MAC string formats including Cisco's 'triple hextet' format and also bare MACs that contain no delimiters.

Instance Methods | [hide private]
__init__(self, word_fmt=`'``%.2X``'`, word_sep=`'``-``'`) Constructor. | source code
reset(self) Resets the internal state of this strategy to safe default values. | source code
valid_str(self, addr) Returns: `True` if MAC address string is valid, `False` otherwise. | source code
str_to_int(self, addr) Returns: An unsigned integer that is equivalent to value represented by EUI-48/MAC string address. | source code
int_to_str(self, int_val, word_sep=None, word_fmt=None) Returns: A MAC address in string form that is equivalent to value represented by an unsigned integer. | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`
Inherited from AddrStrategy
__repr__(self) Returns: executable Python string to recreate equivalent object | source code
bits_to_int(self, bits) Returns: An unsigned integer that is equivalent to value represented by network address in readable binary form. | 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_bits(self, int_val, word_sep=None) Returns: A network address in readable binary form that is equivalent to value represented by an unsigned integer. | source code
int_to_packed(self, int_val) Returns: a packed string that is equivalent to value represented by an unsigned integer. | source code
int_to_words(self, int_val, num_words=None, word_size=None) | source code
packed_to_int(self, packed_int) Returns: An unsigned integer equivalent to value of network address represented by packed binary string. | source code
valid_bits(self, bits) Returns: `True` if network address is valid for this address type, `False` otherwise. | source code
valid_int(self, int_val) Returns: `True` if integer falls within the boundaries of this address type, `False` otherwise. | 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: An unsigned integer that is equivalent to value represented by word sequence. | source code

Class Variables | [hide private]
| RE_MAC_FORMATS = ``[`re.compile(r'`(?i)`^`(``[`0`-`9A`-`F`]``{1,2}``)`:`(``[`0`-`9A`-`F`]``{``...``
| _ = ``'``^([0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F``...``
Inherited from AddrStrategy
| STRUCT_FORMATS = ``{`8`:` `'``B``'``,` 16`:` `'``H``'``,` 32`:` `'``I``'``}`` Lookup table for struct module format strings.

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, word_fmt=`'``%.2X``'`, word_sep=`'``-``'`) (Constructor) | source code
Constructor. Parameters: `word_sep` - separator between each word. (Default: '-') `word_fmt` - format string for each hextet. (Default: '%02x') Overrides: object.__init__

### valid_str(self, addr) | source code
Parameters: `addr` - An EUI-48 or MAC address in string form. Returns: `True` if MAC address string is valid, `False` otherwise. Overrides: AddrStrategy.valid_str

### str_to_int(self, addr) | source code
Parameters: `addr` - An EUI-48 or MAC address in string form. Returns: An unsigned integer that is equivalent to value represented by EUI-48/MAC string address. Overrides: AddrStrategy.str_to_int

### int_to_str(self, int_val, word_sep=None, word_fmt=None) | source code
Parameters: `int_val` - An unsigned integer. `word_sep` - (optional) The separator used between words in an address string. `word_fmt` - (optional) A Python format string used to format each word of address. Returns: A MAC address in string form that is equivalent to value represented by an unsigned integer. Overrides: AddrStrategy.int_to_str

Class Variable Details | [hide private]

  ### RE_MAC_FORMATS Value:
      [re.compile(r'(?i)^([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0
      -9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2})$'),
       re.compile(r'(?i)^([0-9A-F]{1,2})-([0-9A-F]{1,2})-([0-9A-F]{1,2})-([0
      -9A-F]{1,2})-([0-9A-F]{1,2})-([0-9A-F]{1,2})$'),
       re.compile(r'(?i)^([0-9A-F]{1,4}):([0-9A-F]{1,4}):([0-9A-F]{1,4})$'),
       re.compile(r'(?i)^([0-9A-F]{1,4})-([0-9A-F]{1,4})-([0-9A-F]{1,4})$'),
       re.compile(r'(?i)^([0-9A-F]{5,6})-([0-9A-F]{5,6})$'),
       re.compile(r'(?i)^([0-9A-F]{5,6}):([0-9A-F]{5,6})$'),
      ...

  ### _ Value:
      '^([0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-
      9A-F][0-9A-F][0-9A-F])$'