def is_valid_ipv6_address(ip_str):
 from django.core.validators import validate_ipv4_address
 symbols_re = re.compile('^[0-9a-fA-F:.]+$')
 if (not symbols_re.match(ip_str)):
  return False
 if (':' not in ip_str):
  return False
 if (ip_str.count('::') > 1):
  return False
 if (':::' in ip_str):
  return False
 if ((ip_str.startswith(':') and (not ip_str.startswith('::'))) or (ip_str.endswith(':') and (not ip_str.endswith('::')))):
  return False
 if (ip_str.count(':') > 7):
  return False
 if (('::' not in ip_str) and (ip_str.count(':') != 7)):
  if (ip_str.count('.') != 3):
   return False
 ip_str = _explode_shorthand_ip_string(ip_str)
 for hextet in ip_str.split(':'):
  if (hextet.count('.') == 3):
   if (not (ip_str.split(':')[(-1)] == hextet)):
    return False
   try:
    validate_ipv4_address(hextet)
   except ValidationError:
    return False
  else:
   try:
    if ((int(hextet, 16) < 0) or (int(hextet, 16) > 65535)):
     return False
   except ValueError:
    return False
 return True

def is_valid_ipv6_address ( ip_str ) : from django . core . validators import validate_ipv4_address symbols_re = re . compile ( '^[0-9a-fA-F:.]+$' ) if ( not symbols_re . match ( ip_str ) ) : return False if ( ':' not in ip_str ) : return False if ( ip_str . count ( '::' ) > 1 ) : return False if ( ':::' in ip_str ) : return False if ( ( ip_str . startswith ( ':' ) and ( not ip_str . startswith ( '::' ) ) ) or ( ip_str . endswith ( ':' ) and ( not ip_str . endswith ( '::' ) ) ) ) : return False if ( ip_str . count ( ':' ) > 7 ) : return False if ( ( '::' not in ip_str ) and ( ip_str . count ( ':' ) != 7 ) ) : if ( ip_str . count ( '.' ) != 3 ) : return False ip_str = _explode_shorthand_ip_string ( ip_str ) for hextet in ip_str . split ( ':' ) : if ( hextet . count ( '.' ) == 3 ) : if ( not ( ip_str . split ( ':' ) [ ( - 1 ) ] == hextet ) ) : return False try : validate_ipv4_address ( hextet ) except ValidationError : return False else : try : if ( ( int ( hextet , 16 ) < 0 ) or ( int ( hextet , 16 ) > 65535 ) ) : return False except ValueError : return False return True
checks if a string is a valid ipv6 address .