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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

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