def METHOD_NAME(s, defaultport):
    match = re.match('\[([0-9a-fA-F:]+)\](?::([0-9]+))?$', s)
    if match: # ipv6
        host = match.group(1)
        port = match.group(2)
    elif s.count(':') > 1: # ipv6, no port
        host = s
        port = ''
    else:
        (host,_,port) = s.partition(':')
    if not port:
        port = defaultport
    else:
        port = int(port)
    host = name_to_ipv6(host)
    return (host,port)