MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / GenericVersion

Class GenericVersion

vulntotal/vulntotal_utils.py:14–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class GenericVersion:
15 def __init__(self, version):
16 self.value = version
17 self.decomposed = tuple(
18 [com for com in self.value.replace(" ", "").lstrip("vV").split(".")]
19 )
20
21 def __str__(self):
22 return str(self.value)
23
24 def __eq__(self, other):
25 if not isinstance(other, self.__class__):
26 return NotImplemented
27 for i, j in zip(self.decomposed, other.decomposed):
28 if i.isnumeric() and j.isnumeric():
29 i = int(i)
30 j = int(j)
31 if not i.__eq__(j):
32 return False
33 return True
34
35 def __lt__(self, other):
36 if not isinstance(other, self.__class__):
37 return NotImplemented
38 for i, j in zip(self.decomposed, other.decomposed):
39 if i.isnumeric() and j.isnumeric():
40 i = int(i)
41 j = int(j)
42 if i.__eq__(j):
43 continue
44 if i.__lt__(j):
45 return True
46 if i.__gt__(j):
47 return False
48 return False
49
50 def __le__(self, other):
51 if not isinstance(other, self.__class__):
52 return NotImplemented
53 return self.__lt__(other) or self.__eq__(other)
54
55
56def compare(version, package_comparator, package_version):

Callers 4

to_advisoriesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected