Coverage for venv\Lib\site-packages\rid_lib\types\http_s.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-20 16:40 +0800

1from urllib.parse import urlsplit, urlunsplit 

2 

3from rid_lib.core import RID 

4 

5class HTTP(RID): 

6 scheme = "http" 

7 

8 def __init__(self, authority, path, query, fragment): 

9 self.authority = authority 

10 self.path = path 

11 self.query = query 

12 self.fragment = fragment 

13 

14 @property 

15 def reference(self): 

16 return urlunsplit(( 

17 "", 

18 self.authority, 

19 self.path, 

20 self.query, 

21 self.fragment 

22 )) 

23 

24 @classmethod 

25 def from_reference(cls, reference): 

26 uri_components = urlsplit(reference, scheme=cls.scheme) 

27 # excluding scheme component 

28 return cls(*uri_components[1:]) 

29 

30class HTTPS(HTTP): 

31 scheme = "https" 

32 

33RID.register_context(HTTP) 

34RID.register_context(HTTPS)