source: uri/uri.py@ 262

Last change on this file since 262 was 262, checked in by wouter, 3 years ago

docu of URI

File size: 1.8 KB
RevLine 
[231]1from __future__ import annotations
2from rfc3986.api import uri_reference
3
4class URI:
[262]5 '''
6 Immutable object containing an Uniform Resource Identifier (URI).
7 An URI is a string of characters identifying a resource on the web.
8 It generally looks like scheme://user@host:port/bla/bla?query#fragment.
9 Many of these parts are optional, check the specs of rfc3986
10 '''
[231]11 def __init__(self, uri:str):
[262]12 '''
13 Constructor checks that the provided URI meets the specs.
14 '''
[231]15 self._uri=uri
16 self._parse= uri_reference(uri)
17 self._normal=self._parse.normalize()
18
19 def getUri(self):
[262]20 '''
21 @return the original URI provided in the constructor
22 '''
[231]23 return self._uri
24
25 def getScheme(self):
[262]26 '''
27 The scheme of the URI. Scheme specifies the format of the data
28 and the communication protocols needed. Eg "https" or "ws"
29 '''
[231]30 return self._parse.scheme
31
32
33 def getHost(self):
[262]34 '''
35 @return the Name or IP address of the machine containing the resource
36 '''
[231]37 return self._parse.host
38
39 def getPath(self):
[262]40 '''
41 @return the Path part of the URI. The pat to the data on the machine.
42 '''
[231]43 return self._parse.path
44
45 def getQuery(self):
[262]46 '''
47 @return the query part of the URI
48 '''
[231]49 return self._parse.query
50
51 def getFragment(self):
[262]52 '''
53 @return the fragment contained in the URI.
54 '''
[231]55 return self._parse.fragment
56
57 def __repr__(self)->str:
58 return self._uri
59
60 def __eq__(self, other):
61 return isinstance(other, self.__class__) and \
62 self._normal==other._normal
63
64 def __hash__(self):
[232]65 return hash(self._normal)
[231]66
Note: See TracBrowser for help on using the repository browser.