absurdfarce commented on code in PR #1273:
URL:
https://github.com/apache/cassandra-python-driver/pull/1273#discussion_r2892662456
##########
cassandra/util.py:
##########
@@ -1692,54 +1692,43 @@ def __repr__(self):
self.lower_bound, self.upper_bound, self.value
)
+VERSION_REGEX =
re.compile("(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:-\\w[.\\w]*)*)?(\\+[.\\w]+)?")
@total_ordering
class Version(object):
- """
- Internal minimalist class to compare versions.
- A valid version is: <int>.<int>.<int>.<int or str>.
-
- TODO: when python2 support is removed, use packaging.version.
- """
-
- _version = None
- major = None
- minor = 0
- patch = 0
- build = 0
- prerelease = 0
def __init__(self, version):
self._version = version
- if '-' in version:
- version_without_prerelease, self.prerelease = version.split('-', 1)
- else:
- version_without_prerelease = version
- parts = list(reversed(version_without_prerelease.split('.')))
- if len(parts) > 4:
- prerelease_string = "-{}".format(self.prerelease) if
self.prerelease else ""
- log.warning("Unrecognized version: {}. Only 4 components plus
prerelease are supported. "
- "Assuming version as {}{}".format(version,
'.'.join(parts[:-5:-1]), prerelease_string))
+
+ match = VERSION_REGEX.match(version)
+ if not match:
+ raise ValueError("Version string did not match expected format")
Review Comment:
Another fair point; including the string we're trying to match against could
be useful here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]