Skip to content

Instantly share code, notes, and snippets.

@flyte
Created January 24, 2014 15:53
Show Gist options
  • Save flyte/8600002 to your computer and use it in GitHub Desktop.
Save flyte/8600002 to your computer and use it in GitHub Desktop.
Rebuild a URL with stars covering the password.
def star_url(url):
"""
Rebuild a URL with stars covering the password.
"""
url = urlparse(url)
ret = ""
# Scheme (http/https)
if url.scheme:
ret += "%s://" % url.scheme
# Username/password
if url.username:
ret += url.user
if url.password:
ret += ":*****"
ret += "@"
# Hostname
ret += url.hostname
# Port
if url.port:
ret += ":%s" % url.port
# Path
ret += url.path
# Query (?key=value)
if url.query:
ret += "?%s" % query
# Fragment (#some_id)
if url.fragment:
ret += "#%s" % fragment
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment