usb-0000:00:01.2-2/input0 �# Copyright (c) 2020 Matt Martz # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type import re from ansible.module_utils.compat.version import LooseVersion, Version from ansible.module_utils.six import text_type # Regular expression taken from # https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string SEMVER_RE = re.compile( r''' ^ (?P0|[1-9]\d*) \. (?P0|[1-9]\d*) \. (?P0|[1-9]\d*) (?: - (?P (?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*) (?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))* ) )? (?: \+ (?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*) )? $ ''', flags=re.X ) class _Alpha: """Class to easily allow comparing strings Largely this exists to make comparing an integer and a string on py3 so that it works like py2. """ def __init__(self, specifier): self.specifier = specifier def __repr__(self): return repr(self.specifier) def __eq__(self, other): if isinstance(other, _Alpha): return self.specifier == other.specifier elif isinstance(other, str): return self.specifier == other return False def __ne__(self, other): return not self.__eq__(other) def __lt__(self, other): if isinstance(other, _Alpha): return self.specifier < other.specifier elif isinstance(other, str): return self.specifier < other elif isinstance(other, _Numeric): return False raise ValueError def __le__(self, other): return self.__lt__(other) or self.__eq__(other) def __gt__(self, other): return not self.__le__(other) def __ge__(self, other): return not self.__lt__(other) class _Numeric: """Class to easily allow comparing numbers Largely this exists to make comparing an integer and a string on py3 so that it works like py2. """ def __init__(self, specifier): self.specifier = int(specifier) def __repr__(self): return repr(self.specifier) def __eq__(self, other): if isinstance(other, _Numeric): return self.specifier == other.specifier elif isinstance(other, int): return self.specifier == other return False def __ne__(self, other): return not self.__eq__(other) def __lt__(self, other): if isinstance(other, _Numeric): return self.specifier < other.specifier elif isinstance(other, int): return self.specifier < other elif isinstance(other, _Alpha): return True raise ValueError def __le__(self, other): return self.__lt__(other) or self.__eq__(other) def __gt__(self, other): return not self.__le__(other) def __ge__(self, other): return not self.__lt__(other) class SemanticVersion(Version): """Version comparison class that implements Semantic Versioning 2.0.0 Based off of ``distutils.version.Version`` """ version_re = SEMVER_RE def __init__(self, vstring=None): self.vstring = vstring self.major = None self.minor = None self.patch = None self.prerelease = () self.buildmetadata = () if vstring: self.parse(vstring) def __repr__(self): return 'SemanticVersion(%r)' % self.vstring @staticmethod def from_loose_version(loose_version): """This method is designed to take a ``LooseVersion`` and attempt to construct a ``SemanticVersion`` from it This is useful where you want to do simple version math without requiring users to provid