Example #1
0
def normalize_license_expression(license_text_raw) -> str:
    if license_text_raw is None:
        return ""

    license_text, normalized = normalize(f"{license_text_raw}")

    try:
        license = licensing.parse(license_text)
    except ExpressionError:
        return license_text

    if license is None:
        return ""

    if license.isliteral:
        normalized_license, normalized = normalize(license.render())
        return normalized_license

    operator = license.operator.strip()

    return "({})".format(f" {operator} ".join(
        map(normalize_license_expression, license.args)))
Example #2
0
 def test_license_with_space_instead_of_dash(self):
     license = "MPL 1.0"
     self.assertEqual(("MPL-1.0", True), normalize(license))
Example #3
0
 def test_normalized_license_returned_self(self):
     license = "MIT"
     self.assertEqual(("MIT", False), normalize(license))
Example #4
0
 def test_license_identified_by_long_name(self):
     license = "GNU Free Documentation License v1.1"
     self.assertEqual(("GFDL-1.1", True), normalize(license))
Example #5
0
 def test_license_identified_by_long_name_uppercase_problem(self):
     license = "ISC license"
     self.assertEqual(("ISC", True), normalize(license))
Example #6
0
 def test_complex_license(self):
     license = "M AND I AND T"
     self.assertEqual(("MIT", True), normalize(license))
Example #7
0
 def test_lowercase_license(self):
     license = "mit"
     self.assertEqual(("MIT", True), normalize(license))
Example #8
0
 def test_unknown_license(self):
     license = "Whatever very weird license"
     self.assertEqual((license, False), normalize(license))
Example #9
0
 def test_normalized_license(self):
     license = "Apache2"
     self.assertEqual(("Apache-2.0", True), normalize(license))
Example #10
0
 def test_dot_o_license(self):
     license = "Apache-2.0"
     self.assertEqual(("Apache-2.0", False), normalize(license))