summaryrefslogtreecommitdiffstats
path: root/third_party/python/mozilla_version
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/python/mozilla_version')
-rw-r--r--third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/LICENSE363
-rw-r--r--third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/METADATA17
-rw-r--r--third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/RECORD17
-rw-r--r--third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/WHEEL6
-rw-r--r--third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/top_level.txt1
-rw-r--r--third_party/python/mozilla_version/mozilla_version/__init__.py1
-rw-r--r--third_party/python/mozilla_version/mozilla_version/balrog.py142
-rw-r--r--third_party/python/mozilla_version/mozilla_version/errors.py64
-rw-r--r--third_party/python/mozilla_version/mozilla_version/gecko.py435
-rw-r--r--third_party/python/mozilla_version/mozilla_version/maven.py56
-rw-r--r--third_party/python/mozilla_version/mozilla_version/parser.py48
-rw-r--r--third_party/python/mozilla_version/mozilla_version/version.py177
12 files changed, 1327 insertions, 0 deletions
diff --git a/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/LICENSE b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/LICENSE
new file mode 100644
index 0000000000..e87a115e46
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/LICENSE
@@ -0,0 +1,363 @@
+Mozilla Public License, version 2.0
+
+1. Definitions
+
+1.1. "Contributor"
+
+ means each individual or legal entity that creates, contributes to the
+ creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+
+ means the combination of the Contributions of others (if any) used by a
+ Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+
+ means Source Code Form to which the initial Contributor has attached the
+ notice in Exhibit A, the Executable Form of such Source Code Form, and
+ Modifications of such Source Code Form, in each case including portions
+ thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ a. that the initial Contributor has attached the notice described in
+ Exhibit B to the Covered Software; or
+
+ b. that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the terms of
+ a Secondary License.
+
+1.6. "Executable Form"
+
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+
+ means a work that combines Covered Software with other material, in a
+ separate file or files, that is not Covered Software.
+
+1.8. "License"
+
+ means this document.
+
+1.9. "Licensable"
+
+ means having the right to grant, to the maximum extent possible, whether
+ at the time of the initial grant or subsequently, any and all of the
+ rights conveyed by this License.
+
+1.10. "Modifications"
+
+ means any of the following:
+
+ a. any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered Software; or
+
+ b. any new file in Source Code Form that contains any Covered Software.
+
+1.11. "Patent Claims" of a Contributor
+
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the License,
+ by the making, using, selling, offering for sale, having made, import,
+ or transfer of either its Contributions or its Contributor Version.
+
+1.12. "Secondary License"
+
+ means either the GNU General Public License, Version 2.0, the GNU Lesser
+ General Public License, Version 2.1, the GNU Affero General Public
+ License, Version 3.0, or any later versions of those licenses.
+
+1.13. "Source Code Form"
+
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that controls, is
+ controlled by, or is under common control with You. For purposes of this
+ definition, "control" means (a) the power, direct or indirect, to cause
+ the direction or management of such entity, whether by contract or
+ otherwise, or (b) ownership of more than fifty percent (50%) of the
+ outstanding shares or beneficial ownership of such entity.
+
+
+2. License Grants and Conditions
+
+2.1. Grants
+
+ Each Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ a. under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+ b. under Patent Claims of such Contributor to make, use, sell, offer for
+ sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+ The licenses granted in Section 2.1 with respect to any Contribution
+ become effective for each Contribution on the date the Contributor first
+ distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+ The licenses granted in this Section 2 are the only rights granted under
+ this License. No additional rights or licenses will be implied from the
+ distribution or licensing of Covered Software under this License.
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
+ Contributor:
+
+ a. for any code that a Contributor has removed from Covered Software; or
+
+ b. for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+ c. under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+ This License does not grant any rights in the trademarks, service marks,
+ or logos of any Contributor (except as may be necessary to comply with
+ the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+ No Contributor makes additional grants as a result of Your choice to
+ distribute the Covered Software under a subsequent version of this
+ License (see Section 10.2) or under the terms of a Secondary License (if
+ permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+ Each Contributor represents that the Contributor believes its
+ Contributions are its original creation(s) or it has sufficient rights to
+ grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+ This License is not intended to limit any rights You have under
+ applicable copyright doctrines of fair use, fair dealing, or other
+ equivalents.
+
+2.7. Conditions
+
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
+ Section 2.1.
+
+
+3. Responsibilities
+
+3.1. Distribution of Source Form
+
+ All distribution of Covered Software in Source Code Form, including any
+ Modifications that You create or to which You contribute, must be under
+ the terms of this License. You must inform recipients that the Source
+ Code Form of the Covered Software is governed by the terms of this
+ License, and how they can obtain a copy of this License. You may not
+ attempt to alter or restrict the recipients' rights in the Source Code
+ Form.
+
+3.2. Distribution of Executable Form
+
+ If You distribute Covered Software in Executable Form then:
+
+ a. such Covered Software must also be made available in Source Code Form,
+ as described in Section 3.1, and You must inform recipients of the
+ Executable Form how they can obtain a copy of such Source Code Form by
+ reasonable means in a timely manner, at a charge no more than the cost
+ of distribution to the recipient; and
+
+ b. You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter the
+ recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+ You may create and distribute a Larger Work under terms of Your choice,
+ provided that You also comply with the requirements of this License for
+ the Covered Software. If the Larger Work is a combination of Covered
+ Software with a work governed by one or more Secondary Licenses, and the
+ Covered Software is not Incompatible With Secondary Licenses, this
+ License permits You to additionally distribute such Covered Software
+ under the terms of such Secondary License(s), so that the recipient of
+ the Larger Work may, at their option, further distribute the Covered
+ Software under the terms of either this License or such Secondary
+ License(s).
+
+3.4. Notices
+
+ You may not remove or alter the substance of any license notices
+ (including copyright notices, patent notices, disclaimers of warranty, or
+ limitations of liability) contained within the Source Code Form of the
+ Covered Software, except that You may alter any license notices to the
+ extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+ You may choose to offer, and to charge a fee for, warranty, support,
+ indemnity or liability obligations to one or more recipients of Covered
+ Software. However, You may do so only on Your own behalf, and not on
+ behalf of any Contributor. You must make it absolutely clear that any
+ such warranty, support, indemnity, or liability obligation is offered by
+ You alone, and You hereby agree to indemnify every Contributor for any
+ liability incurred by such Contributor as a result of warranty, support,
+ indemnity or liability terms You offer. You may include additional
+ disclaimers of warranty and limitations of liability specific to any
+ jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+
+ If it is impossible for You to comply with any of the terms of this License
+ with respect to some or all of the Covered Software due to statute,
+ judicial order, or regulation then You must: (a) comply with the terms of
+ this License to the maximum extent possible; and (b) describe the
+ limitations and the code they affect. Such description must be placed in a
+ text file included with all distributions of the Covered Software under
+ this License. Except to the extent prohibited by statute or regulation,
+ such description must be sufficiently detailed for a recipient of ordinary
+ skill to be able to understand it.
+
+5. Termination
+
+5.1. The rights granted under this License will terminate automatically if You
+ fail to comply with any of its terms. However, if You become compliant,
+ then the rights granted under this License from a particular Contributor
+ are reinstated (a) provisionally, unless and until such Contributor
+ explicitly and finally terminates Your grants, and (b) on an ongoing
+ basis, if such Contributor fails to notify You of the non-compliance by
+ some reasonable means prior to 60 days after You have come back into
+ compliance. Moreover, Your grants from a particular Contributor are
+ reinstated on an ongoing basis if such Contributor notifies You of the
+ non-compliance by some reasonable means, this is the first time You have
+ received notice of non-compliance with this License from such
+ Contributor, and You become compliant prior to 30 days after Your receipt
+ of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+ infringement claim (excluding declaratory judgment actions,
+ counter-claims, and cross-claims) alleging that a Contributor Version
+ directly or indirectly infringes any patent, then the rights granted to
+ You by any and all Contributors for the Covered Software under Section
+ 2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
+ license agreements (excluding distributors and resellers) which have been
+ validly granted by You or Your distributors under this License prior to
+ termination shall survive termination.
+
+6. Disclaimer of Warranty
+
+ Covered Software is provided under this License on an "as is" basis,
+ without warranty of any kind, either expressed, implied, or statutory,
+ including, without limitation, warranties that the Covered Software is free
+ of defects, merchantable, fit for a particular purpose or non-infringing.
+ The entire risk as to the quality and performance of the Covered Software
+ is with You. Should any Covered Software prove defective in any respect,
+ You (not any Contributor) assume the cost of any necessary servicing,
+ repair, or correction. This disclaimer of warranty constitutes an essential
+ part of this License. No use of any Covered Software is authorized under
+ this License except under this disclaimer.
+
+7. Limitation of Liability
+
+ Under no circumstances and under no legal theory, whether tort (including
+ negligence), contract, or otherwise, shall any Contributor, or anyone who
+ distributes Covered Software as permitted above, be liable to You for any
+ direct, indirect, special, incidental, or consequential damages of any
+ character including, without limitation, damages for lost profits, loss of
+ goodwill, work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses, even if such party shall have been
+ informed of the possibility of such damages. This limitation of liability
+ shall not apply to liability for death or personal injury resulting from
+ such party's negligence to the extent applicable law prohibits such
+ limitation. Some jurisdictions do not allow the exclusion or limitation of
+ incidental or consequential damages, so this exclusion and limitation may
+ not apply to You.
+
+8. Litigation
+
+ Any litigation relating to this License may be brought only in the courts
+ of a jurisdiction where the defendant maintains its principal place of
+ business and such litigation shall be governed by laws of that
+ jurisdiction, without reference to its conflict-of-law provisions. Nothing
+ in this Section shall prevent a party's ability to bring cross-claims or
+ counter-claims.
+
+9. Miscellaneous
+
+ This License represents the complete agreement concerning the subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. Any law or regulation which provides that
+ the language of a contract shall be construed against the drafter shall not
+ be used to construe this License against a Contributor.
+
+
+10. Versions of the License
+
+10.1. New Versions
+
+ Mozilla Foundation is the license steward. Except as provided in Section
+ 10.3, no one other than the license steward has the right to modify or
+ publish new versions of this License. Each version will be given a
+ distinguishing version number.
+
+10.2. Effect of New Versions
+
+ You may distribute the Covered Software under the terms of the version
+ of the License under which You originally received the Covered Software,
+ or under the terms of any subsequent version published by the license
+ steward.
+
+10.3. Modified Versions
+
+ If you create software not governed by this License, and you want to
+ create a new license for such software, you may create and use a
+ modified version of this License if you rename the license and remove
+ any references to the name of the license steward (except to note that
+ such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+ Licenses If You choose to distribute Source Code Form that is
+ Incompatible With Secondary Licenses under the terms of this version of
+ the License, the notice described in Exhibit B of this License must be
+ attached.
+
+Exhibit A - Source Code Form License Notice
+
+ This Source Code Form is subject to the
+ terms of the Mozilla Public License, v.
+ 2.0. If a copy of the MPL was not
+ distributed with this file, You can
+ obtain one at
+ http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular file,
+then You may include the notice in a location (such as a LICENSE file in a
+relevant directory) where a recipient would be likely to look for such a
+notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+
+ This Source Code Form is "Incompatible
+ With Secondary Licenses", as defined by
+ the Mozilla Public License, v. 2.0.
+
diff --git a/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/METADATA b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/METADATA
new file mode 100644
index 0000000000..cd20533c13
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/METADATA
@@ -0,0 +1,17 @@
+Metadata-Version: 2.1
+Name: mozilla-version
+Version: 0.3.4
+Summary: Process Firefox versions numbers. Tells whether they are valid or not, whether they are nightlies or regular releases, whether this version precedes that other.
+Home-page: https://github.com/mozilla-releng/mozilla-version
+Author: Mozilla Release Engineering
+Author-email: release+python@mozilla.com
+License: MPL2
+Platform: UNKNOWN
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Requires-Dist: attrs
+Requires-Dist: enum34 ; python_version < "3.4"
+
+UNKNOWN
+
+
diff --git a/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/RECORD b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/RECORD
new file mode 100644
index 0000000000..71d5e5b4ce
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/RECORD
@@ -0,0 +1,17 @@
+mozilla_version/__init__.py,sha256=ro9IDUmjUco6GHJhqbgynResbswRnh6HL5Iv1ttDuWU,60
+mozilla_version/balrog.py,sha256=TjRzV-3E1NVEqqXVda5dhzUMdXuiZ2CYqH-Uf-JgnBA,4975
+mozilla_version/errors.py,sha256=bahCd1gb9rW3e23ZjdVOJvF7IQ9kSOKycO4juE2cHQA,2176
+mozilla_version/gecko.py,sha256=C2beofD_Sfs2YNyq9PRe28oGvAX61aOCGLCnWNIMHJg,15337
+mozilla_version/maven.py,sha256=9UXfvpGLOtO1U1mCScuyu2-0U-VdHPtLemOcN-PByyE,1720
+mozilla_version/parser.py,sha256=bLDrJ7JQzHLkAKoKMWX6nQvKIBZV9vqroqDZUfNUMts,1359
+mozilla_version/version.py,sha256=vJVaPjRgKQtNXhA-gWiHTJjzPJwR6uhszeTZ1yay64c,5411
+mozilla_version/test/__init__.py,sha256=r9z_NrSZeN6vCBiocNFI00XPm2bveSogzO-jsLa7Q-I,87
+mozilla_version/test/test_balrog.py,sha256=IqZjc4K5S0vtE3VtYKezbBU6ZHxxkrEdPFgH2so21UU,7839
+mozilla_version/test/test_gecko.py,sha256=pRZ5YT_n0blv2zSvTYkPictZbsnhbEGXlmWzLrC3kfQ,14622
+mozilla_version/test/test_maven.py,sha256=jNe-drnPwc_DkqZPnTasdK_QGNmqqxLAprX6VRFyMzs,2892
+mozilla_version/test/test_version.py,sha256=RGkyZhkRF8FW_MUN6HZNSKOmFHRLR8gPKJG_N-GGqI4,5465
+mozilla_version-0.3.4.dist-info/LICENSE,sha256=YCIsKMGn9qksffmOXF9EWeYk5uKF4Lm5RGevX2qzND0,15922
+mozilla_version-0.3.4.dist-info/METADATA,sha256=oUEXSEKibWqJsbh8uWqaUqHOkruAShgZGQH09etZVVE,580
+mozilla_version-0.3.4.dist-info/WHEEL,sha256=h_aVn5OB2IERUjMbi2pucmR_zzWJtk303YXvhh60NJ8,110
+mozilla_version-0.3.4.dist-info/top_level.txt,sha256=K1r8SXa4ny0i7OTfimG0Ct33oHkXtLjuU1E5_aHBe94,16
+mozilla_version-0.3.4.dist-info/RECORD,,
diff --git a/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/WHEEL b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/WHEEL
new file mode 100644
index 0000000000..78e6f69d1d
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/WHEEL
@@ -0,0 +1,6 @@
+Wheel-Version: 1.0
+Generator: bdist_wheel (0.33.4)
+Root-Is-Purelib: true
+Tag: py2-none-any
+Tag: py3-none-any
+
diff --git a/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/top_level.txt b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/top_level.txt
new file mode 100644
index 0000000000..f5c7efa40b
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version-0.3.4.dist-info/top_level.txt
@@ -0,0 +1 @@
+mozilla_version
diff --git a/third_party/python/mozilla_version/mozilla_version/__init__.py b/third_party/python/mozilla_version/mozilla_version/__init__.py
new file mode 100644
index 0000000000..ba46ee264d
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/__init__.py
@@ -0,0 +1 @@
+"""Defines characteristics of Mozilla's version numbers."""
diff --git a/third_party/python/mozilla_version/mozilla_version/balrog.py b/third_party/python/mozilla_version/mozilla_version/balrog.py
new file mode 100644
index 0000000000..0860d5698a
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/balrog.py
@@ -0,0 +1,142 @@
+"""Defines characteristics of a Balrog release name.
+
+Balrog is the server that delivers Firefox and Thunderbird updates. Release names follow
+the pattern "{product}-{version}-build{build_number}"
+
+Examples:
+ .. code-block:: python
+
+ from mozilla_version.balrog import BalrogReleaseName
+
+ balrog_release = BalrogReleaseName.parse('firefox-60.0.1-build1')
+
+ balrog_release.product # firefox
+ balrog_release.version.major_number # 60
+ str(balrog_release) # 'firefox-60.0.1-build1'
+
+ previous_release = BalrogReleaseName.parse('firefox-60.0-build2')
+ previous_release < balrog_release # True
+
+ invalid = BalrogReleaseName.parse('60.0.1') # raises PatternNotMatchedError
+ invalid = BalrogReleaseName.parse('firefox-60.0.1') # raises PatternNotMatchedError
+
+ # Releases can be built thanks to version classes like FirefoxVersion
+ BalrogReleaseName('firefox', FirefoxVersion(60, 0, 1, 1)) # 'firefox-60.0.1-build1'
+
+"""
+
+import attr
+import re
+
+from mozilla_version.errors import PatternNotMatchedError
+from mozilla_version.parser import get_value_matched_by_regex
+from mozilla_version.gecko import (
+ GeckoVersion, FirefoxVersion, DeveditionVersion, FennecVersion, ThunderbirdVersion
+)
+
+
+_VALID_ENOUGH_BALROG_RELEASE_PATTERN = re.compile(
+ r"^(?P<product>[a-z]+)-(?P<version>.+)$", re.IGNORECASE
+)
+
+
+_SUPPORTED_PRODUCTS = {
+ 'firefox': FirefoxVersion,
+ 'devedition': DeveditionVersion,
+ 'fennec': FennecVersion,
+ 'thunderbird': ThunderbirdVersion,
+}
+
+
+def _supported_product(string):
+ product = string.lower()
+ if product not in _SUPPORTED_PRODUCTS:
+ raise PatternNotMatchedError(string, pattern='unknown product')
+ return product
+
+
+def _products_must_be_identical(method):
+ def checker(this, other):
+ if this.product != other.product:
+ raise ValueError('Cannot compare "{}" and "{}"'.format(this.product, other.product))
+ return method(this, other)
+ return checker
+
+
+@attr.s(frozen=True, cmp=False, hash=True)
+class BalrogReleaseName(object):
+ """Class that validates and handles Balrog release names.
+
+ Raises:
+ PatternNotMatchedError: if a parsed string doesn't match the pattern of a valid release
+ MissingFieldError: if a mandatory field is missing in the string. Mandatory fields are
+ `product`, `major_number`, `minor_number`, and `build_number`
+ ValueError: if an integer can't be cast or is not (strictly) positive
+ TooManyTypesError: if the string matches more than 1 `VersionType`
+ NoVersionTypeError: if the string matches none.
+
+ """
+
+ product = attr.ib(type=str, converter=_supported_product)
+ version = attr.ib(type=GeckoVersion)
+
+ def __attrs_post_init__(self):
+ """Ensure attributes are sane all together."""
+ if self.version.build_number is None:
+ raise PatternNotMatchedError(self, pattern='build_number must exist')
+
+ @classmethod
+ def parse(cls, release_string):
+ """Construct an object representing a valid Firefox version number."""
+ regex_matches = _VALID_ENOUGH_BALROG_RELEASE_PATTERN.match(release_string)
+ if regex_matches is None:
+ raise PatternNotMatchedError(release_string, _VALID_ENOUGH_BALROG_RELEASE_PATTERN)
+
+ product = get_value_matched_by_regex('product', regex_matches, release_string)
+ try:
+ VersionClass = _SUPPORTED_PRODUCTS[product.lower()]
+ except KeyError:
+ raise PatternNotMatchedError(release_string, pattern='unknown product')
+
+ version_string = get_value_matched_by_regex('version', regex_matches, release_string)
+ version = VersionClass.parse(version_string)
+
+ return cls(product, version)
+
+ def __str__(self):
+ """Implement string representation.
+
+ Computes a new string based on the given attributes.
+ """
+ version_string = str(self.version).replace('build', '-build')
+ return '{}-{}'.format(self.product, version_string)
+
+ @_products_must_be_identical
+ def __eq__(self, other):
+ """Implement `==` operator."""
+ return self.version == other.version
+
+ @_products_must_be_identical
+ def __ne__(self, other):
+ """Implement `!=` operator."""
+ return self.version != other.version
+
+ @_products_must_be_identical
+ def __lt__(self, other):
+ """Implement `<` operator."""
+ return self.version < other.version
+
+ @_products_must_be_identical
+ def __le__(self, other):
+ """Implement `<=` operator."""
+ return self.version <= other.version
+
+ @_products_must_be_identical
+ def __gt__(self, other):
+ """Implement `>` operator."""
+ return self.version > other.version
+
+ @_products_must_be_identical
+ def __ge__(self, other):
+ """Implement `>=` operator."""
+ return self.version >= other.version
diff --git a/third_party/python/mozilla_version/mozilla_version/errors.py b/third_party/python/mozilla_version/mozilla_version/errors.py
new file mode 100644
index 0000000000..84cd2169f5
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/errors.py
@@ -0,0 +1,64 @@
+"""Defines all errors reported by mozilla-version."""
+
+
+class PatternNotMatchedError(ValueError):
+ """Error when a string doesn't match an expected pattern.
+
+ Args:
+ string (str): The string it was unable to match.
+ pattern (str): The pattern used it tried to match.
+ """
+
+ def __init__(self, string, pattern):
+ """Constructor."""
+ super(PatternNotMatchedError, self).__init__(
+ '"{}" does not match the pattern: {}'.format(string, pattern)
+ )
+
+
+class NoVersionTypeError(ValueError):
+ """Error when `version_string` matched the pattern, but was unable to find its type.
+
+ Args:
+ version_string (str): The string it was unable to guess the type.
+ """
+
+ def __init__(self, version_string):
+ """Constructor."""
+ super(NoVersionTypeError, self).__init__(
+ 'Version "{}" matched the pattern of a valid version, but it is unable to find what type it is. \
+This is likely a bug in mozilla-version'.format(version_string)
+ )
+
+
+class MissingFieldError(ValueError):
+ """Error when `version_string` lacks an expected field.
+
+ Args:
+ version_string (str): The string it was unable to extract a given field.
+ field_name (str): The name of the missing field.
+ """
+
+ def __init__(self, version_string, field_name):
+ """Constructor."""
+ super(MissingFieldError, self).__init__(
+ 'Release "{}" does not contain a valid {}'.format(version_string, field_name)
+ )
+
+
+class TooManyTypesError(ValueError):
+ """Error when `version_string` has too many types."""
+
+ def __init__(self, version_string, first_matched_type, second_matched_type):
+ """Constructor.
+
+ Args:
+ version_string (str): The string that gave too many types.
+ first_matched_type (str): The name of the first detected type.
+ second_matched_type (str): The name of the second detected type
+ """
+ super(TooManyTypesError, self).__init__(
+ 'Release "{}" cannot match types "{}" and "{}"'.format(
+ version_string, first_matched_type, second_matched_type
+ )
+ )
diff --git a/third_party/python/mozilla_version/mozilla_version/gecko.py b/third_party/python/mozilla_version/mozilla_version/gecko.py
new file mode 100644
index 0000000000..dd14dda6b0
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/gecko.py
@@ -0,0 +1,435 @@
+"""Defines characteristics of a Gecko version number, including Firefox.
+
+Examples:
+ .. code-block:: python
+
+ from mozilla_version.gecko import FirefoxVersion
+
+ version = FirefoxVersion.parse('60.0.1')
+
+ version.major_number # 60
+ version.minor_number # 0
+ version.patch_number # 1
+
+ version.is_release # True
+ version.is_beta # False
+ version.is_nightly # False
+
+ str(version) # '60.0.1'
+
+ previous_version = FirefoxVersion.parse('60.0b14')
+ previous_version < version # True
+
+ previous_version.beta_number # 14
+ previous_version.major_number # 60
+ previous_version.minor_number # 0
+ previous_version.patch_number # raises AttributeError
+
+ previous_version.is_beta # True
+ previous_version.is_release # False
+ previous_version.is_nightly # False
+
+ invalid_version = FirefoxVersion.parse('60.1') # raises PatternNotMatchedError
+ invalid_version = FirefoxVersion.parse('60.0.0') # raises PatternNotMatchedError
+ version = FirefoxVersion.parse('60.0') # valid
+
+ # Versions can be built by raw values
+ FirefoxVersion(60, 0)) # '60.0'
+ FirefoxVersion(60, 0, 1)) # '60.0.1'
+ FirefoxVersion(60, 1, 0)) # '60.1.0'
+ FirefoxVersion(60, 0, 1, 1)) # '60.0.1build1'
+ FirefoxVersion(60, 0, beta_number=1)) # '60.0b1'
+ FirefoxVersion(60, 0, is_nightly=True)) # '60.0a1'
+ FirefoxVersion(60, 0, is_aurora_or_devedition=True)) # '60.0a2'
+ FirefoxVersion(60, 0, is_esr=True)) # '60.0esr'
+ FirefoxVersion(60, 0, 1, is_esr=True)) # '60.0.1esr'
+
+"""
+
+import attr
+import re
+
+from mozilla_version.errors import (
+ PatternNotMatchedError, TooManyTypesError, NoVersionTypeError
+)
+from mozilla_version.parser import strictly_positive_int_or_none
+from mozilla_version.version import BaseVersion, VersionType
+
+
+def _find_type(version):
+ version_type = None
+
+ def ensure_version_type_is_not_already_defined(previous_type, candidate_type):
+ if previous_type is not None:
+ raise TooManyTypesError(
+ str(version), previous_type, candidate_type
+ )
+
+ if version.is_nightly:
+ version_type = VersionType.NIGHTLY
+ if version.is_aurora_or_devedition:
+ ensure_version_type_is_not_already_defined(
+ version_type, VersionType.AURORA_OR_DEVEDITION
+ )
+ version_type = VersionType.AURORA_OR_DEVEDITION
+ if version.is_beta:
+ ensure_version_type_is_not_already_defined(version_type, VersionType.BETA)
+ version_type = VersionType.BETA
+ if version.is_esr:
+ ensure_version_type_is_not_already_defined(version_type, VersionType.ESR)
+ version_type = VersionType.ESR
+ if version.is_release:
+ ensure_version_type_is_not_already_defined(version_type, VersionType.RELEASE)
+ version_type = VersionType.RELEASE
+
+ if version_type is None:
+ raise NoVersionTypeError(str(version))
+
+ return version_type
+
+
+@attr.s(frozen=True, cmp=False, hash=True)
+class GeckoVersion(BaseVersion):
+ """Class that validates and handles version numbers for Gecko-based products.
+
+ You may want to use specific classes like FirefoxVersion. These classes define edge cases
+ that were shipped.
+
+ Raises:
+ PatternNotMatchedError: if the string doesn't match the pattern of a valid version number
+ MissingFieldError: if a mandatory field is missing in the string. Mandatory fields are
+ `major_number` and `minor_number`
+ ValueError: if an integer can't be cast or is not (strictly) positive
+ TooManyTypesError: if the string matches more than 1 `VersionType`
+ NoVersionTypeError: if the string matches none.
+
+ """
+
+ # XXX This pattern doesn't catch all subtleties of a Firefox version (like 32.5 isn't valid).
+ # This regex is intended to assign numbers. Then checks are done by attrs and
+ # __attrs_post_init__()
+ _VALID_ENOUGH_VERSION_PATTERN = re.compile(r"""
+ ^(?P<major_number>\d+)
+ \.(?P<minor_number>\d+)
+ (\.(?P<patch_number>\d+))?
+ (
+ (?P<is_nightly>a1)
+ |(?P<is_aurora_or_devedition>a2)
+ |b(?P<beta_number>\d+)
+ |(?P<is_esr>esr)
+ )?
+ -?(build(?P<build_number>\d+))?$""", re.VERBOSE)
+
+ _ALL_VERSION_NUMBERS_TYPES = (
+ 'major_number', 'minor_number', 'patch_number', 'beta_number',
+ )
+
+ _OPTIONAL_NUMBERS = BaseVersion._OPTIONAL_NUMBERS + ('beta_number', 'build_number')
+
+ build_number = attr.ib(type=int, converter=strictly_positive_int_or_none, default=None)
+ beta_number = attr.ib(type=int, converter=strictly_positive_int_or_none, default=None)
+ is_nightly = attr.ib(type=bool, default=False)
+ is_aurora_or_devedition = attr.ib(type=bool, default=False)
+ is_esr = attr.ib(type=bool, default=False)
+ version_type = attr.ib(init=False, default=attr.Factory(_find_type, takes_self=True))
+
+ def __attrs_post_init__(self):
+ """Ensure attributes are sane all together."""
+ if self.minor_number == 0 and self.patch_number == 0:
+ raise PatternNotMatchedError(
+ self, pattern='Minor number and patch number cannot be both equal to 0'
+ )
+
+ if self.minor_number != 0 and self.patch_number is None:
+ raise PatternNotMatchedError(
+ self, pattern='Patch number cannot be undefined if minor number is greater than 0'
+ )
+
+ if self.beta_number is not None and self.patch_number is not None:
+ raise PatternNotMatchedError(
+ self, pattern='Beta number and patch number cannot be both defined'
+ )
+
+ if self.patch_number is not None and self.is_nightly:
+ raise PatternNotMatchedError(
+ self, pattern='Patch number cannot be defined on a nightly version'
+ )
+
+ if self.patch_number is not None and self.is_aurora_or_devedition:
+ raise PatternNotMatchedError(
+ self, pattern='Patch number cannot be defined on an aurora version'
+ )
+
+ @classmethod
+ def parse(cls, version_string):
+ """Construct an object representing a valid Firefox version number."""
+ return super(GeckoVersion, cls).parse(
+ version_string, regex_groups=('is_nightly', 'is_aurora_or_devedition', 'is_esr')
+ )
+
+ @property
+ def is_beta(self):
+ """Return `True` if `FirefoxVersion` was built with a string matching a beta version."""
+ return self.beta_number is not None
+
+ @property
+ def is_release(self):
+ """Return `True` if `FirefoxVersion` was built with a string matching a release version."""
+ return not (self.is_nightly or self.is_aurora_or_devedition or self.is_beta or self.is_esr)
+
+ def __str__(self):
+ """Implement string representation.
+
+ Computes a new string based on the given attributes.
+ """
+ string = super(GeckoVersion, self).__str__()
+
+ if self.is_nightly:
+ string = '{}a1'.format(string)
+ elif self.is_aurora_or_devedition:
+ string = '{}a2'.format(string)
+ elif self.is_beta:
+ string = '{}b{}'.format(string, self.beta_number)
+ elif self.is_esr:
+ string = '{}esr'.format(string)
+
+ if self.build_number is not None:
+ string = '{}build{}'.format(string, self.build_number)
+
+ return string
+
+ def __eq__(self, other):
+ """Implement `==` operator.
+
+ A version is considered equal to another if all numbers match and if they are of the same
+ `VersionType`. Like said in `VersionType`, release and ESR are considered equal (if they
+ share the same numbers). If a version contains a build number but not the other, the build
+ number won't be considered in the comparison.
+
+ Examples:
+ .. code-block:: python
+
+ assert GeckoVersion.parse('60.0') == GeckoVersion.parse('60.0')
+ assert GeckoVersion.parse('60.0') == GeckoVersion.parse('60.0esr')
+ assert GeckoVersion.parse('60.0') == GeckoVersion.parse('60.0build1')
+ assert GeckoVersion.parse('60.0build1') == GeckoVersion.parse('60.0build1')
+
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('61.0')
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('60.1.0')
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('60.0.1')
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('60.0a1')
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('60.0a2')
+ assert GeckoVersion.parse('60.0') != GeckoVersion.parse('60.0b1')
+ assert GeckoVersion.parse('60.0build1') != GeckoVersion.parse('60.0build2')
+
+ """
+ return super(GeckoVersion, self).__eq__(other)
+
+ def _compare(self, other):
+ """Compare this release with another.
+
+ Returns:
+ 0 if equal
+ < 0 is this precedes the other
+ > 0 if the other precedes this
+
+ """
+ if isinstance(other, str):
+ other = GeckoVersion.parse(other)
+ elif not isinstance(other, GeckoVersion):
+ raise ValueError('Cannot compare "{}", type not supported!'.format(other))
+
+ difference = super(GeckoVersion, self)._compare(other)
+ if difference != 0:
+ return difference
+
+ channel_difference = self._compare_version_type(other)
+ if channel_difference != 0:
+ return channel_difference
+
+ if self.is_beta and other.is_beta:
+ beta_difference = self.beta_number - other.beta_number
+ if beta_difference != 0:
+ return beta_difference
+
+ # Build numbers are a special case. We might compare a regular version number
+ # (like "32.0b8") versus a release build (as in "32.0b8build1"). As a consequence,
+ # we only compare build_numbers when we both have them.
+ try:
+ return self.build_number - other.build_number
+ except TypeError:
+ pass
+
+ return 0
+
+ def _compare_version_type(self, other):
+ return self.version_type.compare(other.version_type)
+
+
+class _VersionWithEdgeCases(GeckoVersion):
+ def __attrs_post_init__(self):
+ for edge_case in self._RELEASED_EDGE_CASES:
+ if all(
+ getattr(self, number_type) == edge_case.get(number_type, None)
+ for number_type in self._ALL_VERSION_NUMBERS_TYPES
+ ):
+ if self.build_number is None:
+ return
+ elif self.build_number == edge_case.get('build_number', None):
+ return
+
+ super(_VersionWithEdgeCases, self).__attrs_post_init__()
+
+
+class FirefoxVersion(_VersionWithEdgeCases):
+ """Class that validates and handles Firefox version numbers."""
+
+ _RELEASED_EDGE_CASES = ({
+ 'major_number': 33,
+ 'minor_number': 1,
+ 'build_number': 1,
+ }, {
+ 'major_number': 33,
+ 'minor_number': 1,
+ 'build_number': 2,
+ }, {
+ 'major_number': 33,
+ 'minor_number': 1,
+ 'build_number': 3,
+ }, {
+ 'major_number': 38,
+ 'minor_number': 0,
+ 'patch_number': 5,
+ 'beta_number': 1,
+ 'build_number': 1,
+ }, {
+ 'major_number': 38,
+ 'minor_number': 0,
+ 'patch_number': 5,
+ 'beta_number': 1,
+ 'build_number': 2,
+ }, {
+ 'major_number': 38,
+ 'minor_number': 0,
+ 'patch_number': 5,
+ 'beta_number': 2,
+ 'build_number': 1,
+ }, {
+ 'major_number': 38,
+ 'minor_number': 0,
+ 'patch_number': 5,
+ 'beta_number': 3,
+ 'build_number': 1,
+ })
+
+
+class DeveditionVersion(GeckoVersion):
+ """Class that validates and handles Devedition after it became an equivalent to beta."""
+
+ # No edge case were shipped
+
+ def __attrs_post_init__(self):
+ """Ensure attributes are sane all together."""
+ if (
+ (not self.is_beta) or
+ (self.major_number < 54) or
+ (self.major_number == 54 and self.beta_number < 11)
+ ):
+ raise PatternNotMatchedError(
+ self, pattern='Devedition as a product must be a beta >= 54.0b11'
+ )
+
+
+class FennecVersion(_VersionWithEdgeCases):
+ """Class that validates and handles Fennec (Firefox for Android) version numbers."""
+
+ _RELEASED_EDGE_CASES = ({
+ 'major_number': 33,
+ 'minor_number': 1,
+ 'build_number': 1,
+ }, {
+ 'major_number': 33,
+ 'minor_number': 1,
+ 'build_number': 2,
+ }, {
+ 'major_number': 38,
+ 'minor_number': 0,
+ 'patch_number': 5,
+ 'beta_number': 4,
+ 'build_number': 1,
+ })
+
+ def __attrs_post_init__(self):
+ """Ensure attributes are sane all together."""
+ # Versions matching 68.Xa1, 68.XbN, or simply 68.X are expected since bug 1523402. The
+ # latter is needed because of the version.txt of beta
+ if (
+ self.major_number == 68 and
+ self.minor_number > 0 and
+ self.patch_number is None
+ ):
+ return
+
+ if self.major_number >= 69:
+ raise PatternNotMatchedError(self, pattern='Last Fennec version is 68')
+
+ super(FennecVersion, self).__attrs_post_init__()
+
+
+class ThunderbirdVersion(_VersionWithEdgeCases):
+ """Class that validates and handles Thunderbird version numbers."""
+
+ _RELEASED_EDGE_CASES = ({
+ 'major_number': 45,
+ 'minor_number': 1,
+ 'beta_number': 1,
+ 'build_number': 1,
+ }, {
+ 'major_number': 45,
+ 'minor_number': 2,
+ 'build_number': 1,
+ }, {
+ 'major_number': 45,
+ 'minor_number': 2,
+ 'build_number': 2,
+ }, {
+ 'major_number': 45,
+ 'minor_number': 2,
+ 'beta_number': 1,
+ 'build_number': 2,
+ })
+
+
+class GeckoSnapVersion(GeckoVersion):
+ """Class that validates and handles Gecko's Snap version numbers.
+
+ Snap is a Linux packaging format developped by Canonical. Valid numbers are like "63.0b7-1",
+ "1" stands for "build1". Release Engineering set this scheme at the beginning of Snap and now
+ we can't rename published snap to the regular pattern like "63.0b7-build1".
+ """
+
+ # Our Snaps are recent enough to not list any edge case, yet.
+
+ # Differences between this regex and the one in GeckoVersion:
+ # * no a2
+ # * no "build"
+ # * but mandatory dash and build number.
+ # Example: 63.0b7-1
+ _VALID_ENOUGH_VERSION_PATTERN = re.compile(r"""
+ ^(?P<major_number>\d+)
+ \.(?P<minor_number>\d+)
+ (\.(?P<patch_number>\d+))?
+ (
+ (?P<is_nightly>a1)
+ |b(?P<beta_number>\d+)
+ |(?P<is_esr>esr)
+ )?
+ -(?P<build_number>\d+)$""", re.VERBOSE)
+
+ def __str__(self):
+ """Implement string representation.
+
+ Returns format like "63.0b7-1"
+ """
+ string = super(GeckoSnapVersion, self).__str__()
+ return string.replace('build', '-')
diff --git a/third_party/python/mozilla_version/mozilla_version/maven.py b/third_party/python/mozilla_version/mozilla_version/maven.py
new file mode 100644
index 0000000000..91cecb3431
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/maven.py
@@ -0,0 +1,56 @@
+"""Defines characteristics of a Maven version at Mozilla."""
+
+import attr
+import re
+
+from mozilla_version.version import BaseVersion
+
+
+@attr.s(frozen=True, cmp=False, hash=True)
+class MavenVersion(BaseVersion):
+ """Class that validates and handles Maven version numbers.
+
+ At Mozilla, Maven packages are used in projects like "GeckoView" or "Android-Components".
+ """
+
+ is_snapshot = attr.ib(type=bool, default=False)
+
+ _VALID_ENOUGH_VERSION_PATTERN = re.compile(r"""
+ ^(?P<major_number>\d+)
+ \.(?P<minor_number>\d+)
+ (\.(?P<patch_number>\d+))?
+ (?P<is_snapshot>-SNAPSHOT)?$""", re.VERBOSE)
+
+ @classmethod
+ def parse(cls, version_string):
+ """Construct an object representing a valid Maven version number."""
+ return super(MavenVersion, cls).parse(version_string, regex_groups=('is_snapshot', ))
+
+ def __str__(self):
+ """Implement string representation.
+
+ Computes a new string based on the given attributes.
+ """
+ string = super(MavenVersion, self).__str__()
+
+ if self.is_snapshot:
+ string = '{}-SNAPSHOT'.format(string)
+
+ return string
+
+ def _compare(self, other):
+ if isinstance(other, str):
+ other = MavenVersion.parse(other)
+ elif not isinstance(other, MavenVersion):
+ raise ValueError('Cannot compare "{}", type not supported!'.format(other))
+
+ difference = super(MavenVersion, self)._compare(other)
+ if difference != 0:
+ return difference
+
+ if not self.is_snapshot and other.is_snapshot:
+ return 1
+ elif self.is_snapshot and not other.is_snapshot:
+ return -1
+ else:
+ return 0
diff --git a/third_party/python/mozilla_version/mozilla_version/parser.py b/third_party/python/mozilla_version/mozilla_version/parser.py
new file mode 100644
index 0000000000..d3a6ef6bb6
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/parser.py
@@ -0,0 +1,48 @@
+"""Defines parser helpers."""
+
+from mozilla_version.errors import MissingFieldError
+
+
+def get_value_matched_by_regex(field_name, regex_matches, string):
+ """Ensure value stored in regex group exists."""
+ try:
+ value = regex_matches.group(field_name)
+ if value is not None:
+ return value
+ except IndexError:
+ pass
+
+ raise MissingFieldError(string, field_name)
+
+
+def does_regex_have_group(regex_matches, group_name):
+ """Return a boolean depending on whether a regex group is matched."""
+ try:
+ return regex_matches.group(group_name) is not None
+ except IndexError:
+ return False
+
+
+def positive_int(val):
+ """Parse `val` into a positive integer."""
+ if isinstance(val, float):
+ raise ValueError('"{}" must not be a float'.format(val))
+ val = int(val)
+ if val >= 0:
+ return val
+ raise ValueError('"{}" must be positive'.format(val))
+
+
+def positive_int_or_none(val):
+ """Parse `val` into either `None` or a positive integer."""
+ if val is None:
+ return val
+ return positive_int(val)
+
+
+def strictly_positive_int_or_none(val):
+ """Parse `val` into either `None` or a strictly positive integer."""
+ val = positive_int_or_none(val)
+ if val is None or val > 0:
+ return val
+ raise ValueError('"{}" must be strictly positive'.format(val))
diff --git a/third_party/python/mozilla_version/mozilla_version/version.py b/third_party/python/mozilla_version/mozilla_version/version.py
new file mode 100644
index 0000000000..1f78bec590
--- /dev/null
+++ b/third_party/python/mozilla_version/mozilla_version/version.py
@@ -0,0 +1,177 @@
+"""Defines common characteristics of a version at Mozilla."""
+
+import attr
+import re
+
+from enum import Enum
+
+from mozilla_version.errors import MissingFieldError, PatternNotMatchedError
+from mozilla_version.parser import (
+ get_value_matched_by_regex,
+ does_regex_have_group,
+ positive_int,
+ positive_int_or_none
+)
+
+
+@attr.s(frozen=True, cmp=False, hash=True)
+class BaseVersion(object):
+ """Class that validates and handles general version numbers."""
+
+ major_number = attr.ib(type=int, converter=positive_int)
+ minor_number = attr.ib(type=int, converter=positive_int)
+ patch_number = attr.ib(type=int, converter=positive_int_or_none, default=None)
+
+ _MANDATORY_NUMBERS = ('major_number', 'minor_number')
+ _OPTIONAL_NUMBERS = ('patch_number', )
+ _ALL_NUMBERS = _MANDATORY_NUMBERS + _OPTIONAL_NUMBERS
+
+ _VALID_ENOUGH_VERSION_PATTERN = re.compile(r"""
+ ^(?P<major_number>\d+)
+ \.(?P<minor_number>\d+)
+ (\.(?P<patch_number>\d+))?$""", re.VERBOSE)
+
+ @classmethod
+ def parse(cls, version_string, regex_groups=()):
+ """Construct an object representing a valid version number."""
+ regex_matches = cls._VALID_ENOUGH_VERSION_PATTERN.match(version_string)
+
+ if regex_matches is None:
+ raise PatternNotMatchedError(version_string, cls._VALID_ENOUGH_VERSION_PATTERN)
+
+ kwargs = {}
+
+ for field in cls._MANDATORY_NUMBERS:
+ kwargs[field] = get_value_matched_by_regex(field, regex_matches, version_string)
+ for field in cls._OPTIONAL_NUMBERS:
+ try:
+ kwargs[field] = get_value_matched_by_regex(field, regex_matches, version_string)
+ except MissingFieldError:
+ pass
+
+ for regex_group in regex_groups:
+ kwargs[regex_group] = does_regex_have_group(regex_matches, regex_group)
+
+ return cls(**kwargs)
+
+ def __str__(self):
+ """Implement string representation.
+
+ Computes a new string based on the given attributes.
+ """
+ semvers = [str(self.major_number), str(self.minor_number)]
+ if self.patch_number is not None:
+ semvers.append(str(self.patch_number))
+
+ return '.'.join(semvers)
+
+ def __eq__(self, other):
+ """Implement `==` operator."""
+ return self._compare(other) == 0
+
+ def __ne__(self, other):
+ """Implement `!=` operator."""
+ return self._compare(other) != 0
+
+ def __lt__(self, other):
+ """Implement `<` operator."""
+ return self._compare(other) < 0
+
+ def __le__(self, other):
+ """Implement `<=` operator."""
+ return self._compare(other) <= 0
+
+ def __gt__(self, other):
+ """Implement `>` operator."""
+ return self._compare(other) > 0
+
+ def __ge__(self, other):
+ """Implement `>=` operator."""
+ return self._compare(other) >= 0
+
+ def _compare(self, other):
+ """Compare this release with another.
+
+ Returns:
+ 0 if equal
+ < 0 is this precedes the other
+ > 0 if the other precedes this
+
+ """
+ if isinstance(other, str):
+ other = BaseVersion.parse(other)
+ elif not isinstance(other, BaseVersion):
+ raise ValueError('Cannot compare "{}", type not supported!'.format(other))
+
+ for field in ('major_number', 'minor_number', 'patch_number'):
+ this_number = getattr(self, field)
+ this_number = 0 if this_number is None else this_number
+ other_number = getattr(other, field)
+ other_number = 0 if other_number is None else other_number
+
+ difference = this_number - other_number
+
+ if difference != 0:
+ return difference
+
+ return 0
+
+
+class VersionType(Enum):
+ """Enum that sorts types of versions (e.g.: nightly, beta, release, esr).
+
+ Supports comparison. `ESR` is considered higher than `RELEASE` (even if they technically have
+ the same codebase). For instance: 60.0.1 < 60.0.1esr but 61.0 > 60.0.1esr.
+ This choice has a practical use case: if you have a list of Release and ESR version, you can
+ easily extract one kind or the other thanks to the VersionType.
+
+ Examples:
+ .. code-block:: python
+
+ assert VersionType.NIGHTLY == VersionType.NIGHTLY
+ assert VersionType.ESR > VersionType.RELEASE
+
+ """
+
+ NIGHTLY = 1
+ AURORA_OR_DEVEDITION = 2
+ BETA = 3
+ RELEASE = 4
+ ESR = 5
+
+ def __eq__(self, other):
+ """Implement `==` operator."""
+ return self.compare(other) == 0
+
+ def __ne__(self, other):
+ """Implement `!=` operator."""
+ return self.compare(other) != 0
+
+ def __lt__(self, other):
+ """Implement `<` operator."""
+ return self.compare(other) < 0
+
+ def __le__(self, other):
+ """Implement `<=` operator."""
+ return self.compare(other) <= 0
+
+ def __gt__(self, other):
+ """Implement `>` operator."""
+ return self.compare(other) > 0
+
+ def __ge__(self, other):
+ """Implement `>=` operator."""
+ return self.compare(other) >= 0
+
+ def compare(self, other):
+ """Compare this `VersionType` with anotherself.
+
+ Returns:
+ 0 if equal
+ < 0 is this precedes the other
+ > 0 if the other precedes this
+
+ """
+ return self.value - other.value
+
+ __hash__ = Enum.__hash__