|
6 | 6 |
|
7 | 7 | from functools import total_ordering |
8 | 8 | import functools |
9 | | -import re |
10 | 9 |
|
11 | 10 | import attr |
12 | 11 | import semantic_version |
@@ -388,6 +387,19 @@ class LegacyOpensslVersion(Version): |
388 | 387 | univers.versions.InvalidVersion: '3.0.2' is not a valid <class 'univers.versions.LegacyOpensslVersion'> |
389 | 388 | """ |
390 | 389 |
|
| 390 | + major = attr.ib(type=int, default=None, repr=False) |
| 391 | + minor = attr.ib(type=int, default=None, repr=False) |
| 392 | + build = attr.ib(type=int, default=None, repr=False) |
| 393 | + patch = attr.ib(type=str, default=None, repr=False) |
| 394 | + |
| 395 | + def __attrs_post_init__(self): |
| 396 | + super().__attrs_post_init__() |
| 397 | + major, minor, build, patch = self.value |
| 398 | + object.__setattr__(self, "major", major) |
| 399 | + object.__setattr__(self, "minor", minor) |
| 400 | + object.__setattr__(self, "build", build) |
| 401 | + object.__setattr__(self, "patch", patch) |
| 402 | + |
391 | 403 | @classmethod |
392 | 404 | def is_valid(cls, string): |
393 | 405 | return bool(cls.parse(string)) |
@@ -448,7 +460,29 @@ def build_value(cls, string): |
448 | 460 | return cls.parse(string) |
449 | 461 |
|
450 | 462 | def __str__(self): |
451 | | - return f"{self.value[0]}.{self.value[1]}.{self.value[2]}{self.value[3]}" |
| 463 | + return f"{self.major}.{self.minor}.{self.build}{self.patch}" |
| 464 | + |
| 465 | + def __lt__(self, other): |
| 466 | + if not isinstance(other, self.__class__): |
| 467 | + return NotImplemented |
| 468 | + # Check if versions have the same base, and `one and only one` of them is a pre-release. |
| 469 | + if (self.major, self.minor, self.build) == (other.major, other.minor, other.build) and ( |
| 470 | + self.is_prerelease() != other.is_prerelease() |
| 471 | + ): |
| 472 | + return self.is_prerelease() |
| 473 | + return self.value.__lt__(other.value) |
| 474 | + |
| 475 | + def __gt__(self, other): |
| 476 | + if not isinstance(other, self.__class__): |
| 477 | + return NotImplemented |
| 478 | + if (self.major, self.minor, self.build) == (other.major, other.minor, other.build) and ( |
| 479 | + self.is_prerelease() != other.is_prerelease() |
| 480 | + ): |
| 481 | + return other.is_prerelease() |
| 482 | + return self.value.__gt__(other.value) |
| 483 | + |
| 484 | + def is_prerelease(self): |
| 485 | + return self.patch.startswith(("-beta", "-alpha")) |
452 | 486 |
|
453 | 487 |
|
454 | 488 | @attr.s(frozen=True, order=False, eq=False, hash=True) |
|
0 commit comments