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