vinegar.transform.mac_address
Transformations for MAC addresses.
- vinegar.transform.mac_address.normalize(value: str, target_case: str = 'upper', delimiter: str = ':', raise_error_if_malformed: bool = False) str
Normalize a MAC address.
This function takes a MAC address (as a
str) and transforms it into a normalized form. This means that each byte of the MAC address is represented by exactly two characters (adding a leading “0” if needed). The MAC address is also transformed to consistenly use upper or lower case characters and to use the specified delimiter.While an input MAC address can have mixed upper / lower case characters, it must consistently use one delimiter (“:” or “-“).
When a malformed MAC address is encountered, the behavior depends on the
raise_error_if_malformedoption. If that option is set toTrue, aValueErroris raised. If it isFalse(the default), the input value is returned unchanged.- Parameters:
value – input MAC address to be transformed.
target_case –
upperif the transformed MAC address shall use upper-case characters,lowerif the transformed MAC address shall use lower-case characters. The default isupper.delimiter –
:orcolonif the bytes of the MAC address shall be separated by a colon and-,dashorminusif the bytes of the MAC address shall be separated by a minus sign. The default is:.raise_error_if_malformed –
Trueif a malformed MAC address should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
normalized form of the input MAC address.