- split_results = urlsplit(href)
- protocol, netloc, path, query, tag = split_results
- user = split_results.username
- password = split_results.password
- host = split_results.hostname
- port = split_results.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
-