'Encodes the netloc part to an ASCII safe URL as bytes.'

def encode_netloc(self):

    rv = (self.ascii_host or '')
    if (':' in rv):
        rv = ('[%s]' % rv)
    port = self.port
    if (port is not None):
        rv = ('%s:%d' % (rv, port))
    auth = ':'.join(filter(None, [url_quote((self.raw_username or ''), 'utf-8', 'strict', '/:%'), url_quote((self.raw_password or ''), 'utf-8', 'strict', '/:%')]))
    if auth:
        rv = ('%s@%s' % (auth, rv))
    return to_native(rv)
