Source code for tradeexecutor.utils.url

"""URL helpers."""
from urllib.parse import urlparse

[docs]def redact_url_password(url: str) -> str: """Remove password from the URL. Designed to sanitize PSQL connection URLs in logs. :param url: URL as a string :return: URL where password is replaced with ??? """ # parsed = urlparse(url) if parsed.port: replaced = parsed._replace(netloc="{}:{}@{}:{}".format(parsed.username, "???", parsed.hostname, parsed.port)) return replaced.geturl() # 'https://user:[email protected]/path?key=value#hash else: replaced = parsed._replace(netloc="{}:{}@{}".format(parsed.username, "???", parsed.hostname)) return replaced.geturl()
[docs]def get_url_domain(url: str) -> str: """Redact URL so that only domain is displayed. Some services e.g. infura use path as an API key. """ parsed = urlparse(url) return parsed.hostname