-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl.py
More file actions
49 lines (39 loc) · 1.22 KB
/
url.py
File metadata and controls
49 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from url_normalize import url_normalize
class URL:
def __init__(self, url):
self.url = url
self.normalized = url_normalize(url)
def isValid(self):
return self.url == self.normalized
def getNormalized(self):
return self.normalized
def __len__(self):
return len(self.normalized)
def __getitem__(self, index):
return self.normalized[index]
# Comparison using normalized url
def __lt__(self, other):
if self.isValid() != other.isValid():
return self.isValid > other.isValid()
else:
return self.normalized < other.normalized
def __le__(self, other):
if self.isValid() != other.isValid():
return self.isValid > other.isValid()
else:
return self.normalized <= other.normalized
def __gt__(self, other):
if self.isValid() != other.isValid():
return self.isValid < other.isValid()
else:
return self.normalized > other.normalized
def __ge__(self, other):
if self.isValid() != other.isValid():
return self.isValid < other.isValid()
else:
return self.normalized >= other.normalized
def __eq__(self, other):
if self.isValid() != other.isValid():
return False
else:
return self.normalized == other.normalized