mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
misc: add extract_authentication method
This pulls the username:password out of a URL
This commit is contained in:
parent
df93a225a8
commit
4f6d6bf2d8
@ -265,6 +265,22 @@ def verify_file_checksum(pathname, alg, checksum, size=0):
|
||||
return verify_file_checksums(pathname, {alg: checksum}, size)
|
||||
|
||||
|
||||
def extract_authentication(url):
|
||||
""" Remove plaintext authentication data from a URL
|
||||
|
||||
If the URL has a username:password in its netloc, this removes it
|
||||
and returns the remaining URL, along with the username and password
|
||||
separately. If no authentication data is in the netloc, this just
|
||||
returns the URL unchanged with None for the username and password.
|
||||
|
||||
This returns a tuple in the form (url, username, password)
|
||||
"""
|
||||
u = urlparse(url)
|
||||
if u.username or u.password:
|
||||
return (u._replace(netloc=u.hostname).geturl(), u.username, u.password)
|
||||
return (url, None, None)
|
||||
|
||||
|
||||
def download(src, dst, size=0):
|
||||
""" download/copy a file/url to local file
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user