Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/mdurl/_format.py: 94%

17 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:15 +0000

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5if TYPE_CHECKING: 

6 from mdurl._url import URL 

7 

8 

9def format(url: URL) -> str: # noqa: A001 

10 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 address 

18 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 result