clean_ipv6_address
Clean an IPv6 address string.
Raise ValidationError if the address is invalid.
Replace the longest continuous zero-sequence with "::", remove leading zeroes, and make sure all hextets are lowercase.
def clean_ipv6_address(
ip_str: string,
unpack_ipv4: boolean = False,
error_message: string = _("This is not a valid IPv6 address."),
max_length: integer = MAX_IPV6_ADDRESS_LENGTH
) - > string
Clean an IPv6 address string. Replace the longest continuous zero-sequence with "::", remove leading zeroes, and make sure all hextets are lowercase. Raise ValidationError if the address is invalid.
Parameters
| Name | Type | Description |
|---|---|---|
| ip_str | string | The raw IPv6 address string to be validated and formatted. |
| unpack_ipv4 | boolean = False | Determines whether to return a plain IPv4 address if an IPv4-mapped IPv6 address is encountered. |
| error_message | string = _("This is not a valid IPv6 address.") | The custom error message to be included in the ValidationError if the input string is not a valid IPv6 address. |
| max_length | integer = MAX_IPV6_ADDRESS_LENGTH | The maximum allowed character length for the input IP string before it is considered invalid. |
Returns
| Type | Description |
|---|---|
string | A compressed IPv6 address string, or a plain IPv4 address string if unpack_ipv4 is enabled and an IPv4-mapped address is detected. |