|
11 | 11 | from socket import timeout
|
12 | 12 | from ssl import SSLError
|
13 | 13 | from time import time
|
14 |
| -from typing import NamedTuple |
15 | 14 | from urllib.error import HTTPError, URLError
|
16 | 15 | from urllib.request import Request, urlopen
|
17 | 16 |
|
|
23 | 22 |
|
24 | 23 |
|
25 | 24 | @total_ordering
|
26 |
| -class Version(NamedTuple): |
27 |
| - """Minimal version class used for parse_version. Should be enough for our purpose.""" |
28 |
| - major: int = 0 |
29 |
| - minor: int = 0 |
30 |
| - micro: int = 0 |
31 |
| - nano: int = 0 |
| 25 | +class Version: |
| 26 | + def __init__(self, *components): |
| 27 | + self.components = list(components) |
32 | 28 |
|
33 | 29 | def __str__(self):
|
34 |
| - return f"{self.major}.{self.minor}.{self.micro}.{self.nano}" |
| 30 | + return '.'.join(map(str, self.components)) |
35 | 31 |
|
36 | 32 | def __lt__(self, other):
|
37 |
| - if self.major != other.major: |
38 |
| - return self.major < other.major |
39 |
| - if self.minor != other.minor: |
40 |
| - return self.minor < other.minor |
41 |
| - if self.micro != other.micro: |
42 |
| - return self.micro < other.micro |
43 |
| - |
44 |
| - return self.nano < other.nano |
| 33 | + # extended comparison that accounts for different lengths by padding with zeros |
| 34 | + max_length = max(len(self.components), len(other.components)) |
| 35 | + # extend both lists with zeros up to the maximum length |
| 36 | + extended_self = self.components + [0] * (max_length - len(self.components)) |
| 37 | + extended_other = other.components + [0] * (max_length - len(other.components)) |
| 38 | + |
| 39 | + for self_comp, other_comp in zip(extended_self, extended_other): |
| 40 | + if self_comp < other_comp: |
| 41 | + return True |
| 42 | + elif self_comp > other_comp: |
| 43 | + return False |
| 44 | + return False # return False if all comparisons are equal |
45 | 45 |
|
46 | 46 | def __eq__(self, other):
|
47 |
| - return all((self.major == other.major, self.minor == other.minor, self.micro == other.micro, self.nano == other.nano)) |
48 |
| - |
| 47 | + # Uses the same logic for equality |
| 48 | + return not self < other and not other < self |
49 | 49 |
|
50 | 50 | def temp_path():
|
51 | 51 | """Return temporary path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/"""
|
@@ -376,7 +376,4 @@ def parse_version(vstring):
|
376 | 376 | else:
|
377 | 377 | vnums.append(0) # default to 0 if no numeric part found
|
378 | 378 |
|
379 |
| - # ensure the version tuple always has 4 components |
380 |
| - vnums = (vnums + [0] * 4)[:4] |
381 |
| - |
382 | 379 | return Version(*vnums)
|
0 commit comments