def _parse_netloc(netloc):
    """Parse a user:pass@host:port and return a dict suitable for formatting
    a cell mapping template.
    """
    these = {'username': None, 'password': None, 'hostname': None, 'port': None
        }
    if '@' in netloc:
        userpass, hostport = netloc.split('@', 1)
    else:
        hostport = netloc
        userpass = ''
    if hostport.startswith('['):
        host_end = hostport.find(']')
        if host_end < 0:
            raise ValueError('Invalid IPv6 URL')
        these['hostname'] = hostport[1:host_end]
        these['port'] = hostport[host_end + 1:]
    elif ':' in hostport:
        these['hostname'], these['port'] = hostport.split(':', 1)
    else:
        these['hostname'] = hostport
    if ':' in userpass:
        these['username'], these['password'] = userpass.split(':', 1)
    else:
        these['username'] = userpass
    return these
