Did I find the right examples for you? yes no

All Samples(63)  |  Call(26)  |  Derive(0)  |  Import(37)
```Ensure we have a valid IPv6 address.

Args:
ip_str: A string, the IPv6 address.

Returns:
A boolean, True if this is a valid IPv6 address.
```

```        def is_valid_ipv6_address(ip_str):
"""
Ensure we have a valid IPv6 address.

Args:
ip_str: A string, the IPv6 address.

Returns:
A boolean, True if this is a valid IPv6 address.

"""

# We need to have at least one ':'.
if ':' not in ip_str:
return False

# We can only have one '::' shortener.
if ip_str.count('::') > 1:
return False

# '::' should be encompassed by start, digits or end.
if ':::' in ip_str:
return False

# A single colon can neither start nor end an address.
if ((ip_str.startswith(':') and not ip_str.startswith('::')) or
(ip_str.endswith(':') and not ip_str.endswith('::'))):
return False

# We can never have more than 7 ':' (1::2:3:4:5:6:7:8 is invalid)
if ip_str.count(':') > 7:
return False

# If we have no concatenation, we need to have 8 fields with 7 ':'.
if '::' not in ip_str and ip_str.count(':') != 7:
# We might have an IPv4 mapped address.
if ip_str.count('.') != 3:
return False

ip_str = _explode_shorthand_ip_string(ip_str)

# Now that we have that all squared away, let's check that each of the
# hextets are between 0x0 and 0xFFFF.
for hextet in ip_str.split(':'):
if hextet.count('.') == 3:
# If we have an IPv4 mapped address, the IPv4 portion has to
# be at the end of the IPv6 portion.
if not ip_str.split(':')[-1] == hextet:
return False
try:
except ValidationError:
return False
else:
try:
# a value error here means that we got a bad hextet,
# something like 0xzzzz
if int(hextet, 16) < 0x0 or int(hextet, 16) > 0xFFFF:
return False
except ValueError:
return False
return True
```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.utils import six

```
```def validate_ipv6_address(value):
raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode

# These values, if given to validate(), will trigger the self.required check.
```
```def validate_ipv6_address(value):
raise ValidationError(_(u'Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode

# These values, if given to validate(), will trigger the self.required check.
```
```def validate_ipv6_address(value):
raise ValidationError(_(u'Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.utils import six

```
```def validate_ipv6_address(value):
raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode

# These values, if given to validate(), will trigger the self.required check.
```
```def validate_ipv6_address(value):
raise ValidationError(_(u'Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.utils import six

```
```def validate_ipv6_address(value):
raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _, ungettext_lazy
from django.utils.encoding import force_text
from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
```
```def validate_ipv6_address(value):
raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _, ungettext_lazy
from django.utils.encoding import force_text
from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
```
```def validate_ipv6_address(value):
raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode

# These values, if given to validate(), will trigger the self.required check.
```
```def validate_ipv6_address(value):
raise ValidationError(_(u'Enter a valid IPv6 address.'), code='invalid')

```

```from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
```def validate_ipv6_address(value):