summaryrefslogtreecommitdiffstats
path: root/src/mdurl/_format.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:25:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:25:33 +0000
commit3c33e01482cb0481e2472ee49fa55b0d7f818c26 (patch)
treee1bc734976912ad573bb83e8c338bc3285afe50e /src/mdurl/_format.py
parentInitial commit. (diff)
downloadmdurl-3c33e01482cb0481e2472ee49fa55b0d7f818c26.tar.xz
mdurl-3c33e01482cb0481e2472ee49fa55b0d7f818c26.zip
Adding upstream version 0.1.2.upstream/0.1.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/mdurl/_format.py')
-rw-r--r--src/mdurl/_format.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mdurl/_format.py b/src/mdurl/_format.py
new file mode 100644
index 0000000..12524ca
--- /dev/null
+++ b/src/mdurl/_format.py
@@ -0,0 +1,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