vinegar.transform.ipv6_address
Transformations for IPv6 addresses.
- vinegar.transform.ipv6_address.net_address(value: str, raise_error_if_malformed: bool = False) str
Calculate the network address for an IPv6 address and subnet mask.
The subnet mask must be given as part of the input string (separated from the IP address by a forward slash) and is included in the returned net address.
For example, an input of “2001:db8::1/32” results in “2001:db8::/32”.
- Parameters:
value – input IP address and mask to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address or mask should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
network address for the specified IP address and mask.
- vinegar.transform.ipv6_address.normalize(value: str, raise_error_if_malformed: bool = False) str
Normalize an IPv6 address.
This function takes an IPv6 address (as a
str) and transforms it into a normalized form. The normalized form of the address should be close to the format as defined by RFC 5952, but the actual return value might differ slightly.Note
Internally, this method uses
socket.inet_ptonandsocket.inet_ntopto normalize the address. This means that the actual result might differ slightly depending on the platform. However, it is guaranteed that when normalizing different forms of the same address, the normalized form will always be the same when doing this on the same platform.When a malformed IP 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 IP address to be transformed.
raise_error_if_malformed –
Trueif a malformed IP 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 IP address.
- vinegar.transform.ipv6_address.strip_mask(value: str, raise_error_if_malformed: bool = False) str
Strip a subnet mask from an IPv6 address (if present).
For example, for the input string “2001:db8::1/32”, this returns “2001:db8::1”. If the input IP address does not specify a subnet mask, it is returned as is.
- Parameters:
value – input IP address to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
input IP address with the subnet mask removed.