codekingpro/portable-devtools
114k
1from __future__ import annotations2 3from typing import TYPE_CHECKING4 5if TYPE_CHECKING:6 from mdurl._url import URL7 8 9def format(url: URL) -> str: # noqa: A00110 result = ""11 12 result += url.protocol or ""13 result += "//" if url.slashes else ""14 result += url.auth + "@" if url.auth else ""15 16 if url.hostname and ":" in url.hostname:17 # ipv6 address18 result += "[" + url.hostname + "]"19 else:20 result += url.hostname or ""21 22 result += ":" + url.port if url.port else ""23 result += url.pathname or ""24 result += url.search or ""25 result += url.hash or ""26 27 return result28 