blob: 12524ca626065183ec9974f3d7d08dadd4a7d3e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mdurl._url import URL
def format(url: URL) -> str: # noqa: A001
result = ""
result += url.protocol or ""
result += "//" if url.slashes else ""
result += url.auth + "@" if url.auth else ""
if url.hostname and ":" in url.hostname:
# ipv6 address
result += "[" + url.hostname + "]"
else:
result += url.hostname or ""
result += ":" + url.port if url.port else ""
result += url.pathname or ""
result += url.search or ""
result += url.hash or ""
return result
|