- protocol, request = splittype(href)
- user, password, port = None, None, None
- host, path = splithost(request)
- if host:
- user, host = splituser(host)
- if user:
- user, password = splitpasswd(user)
- host, port = splitport(host)
- if port: port = int(port)
-
- if protocol == 'place':
- href = protocol + ":"
- else:
- href = protocol + "://"
- if user:
- href += quote(user)
- if password:
- href += ':' + quote(password)
- href += '@'
- if host:
- href += host.encode('idna').decode('ascii')
- if port:
- href += ':%d' % port
- if path:
- href += path
-