Skip to content

Commit 1688126

Browse files
committed
Merge remote-tracking branch 'bmwcarit/improvements-upstream'
2 parents 4836b1e + c86b526 commit 1688126

File tree

11 files changed

+252
-86
lines changed

11 files changed

+252
-86
lines changed

examples/write_tv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import codecs
99
from spdx.writers.tagvalue import write_document, InvalidDocumentError
10-
from spdx.document import Document, License, LicenseConjuction, ExtractedLicense
10+
from spdx.document import Document, License, LicenseConjunction, ExtractedLicense
1111
from spdx.version import Version
1212
from spdx.creationinfo import Person
1313
from spdx.review import Review
@@ -55,7 +55,7 @@
5555
package.download_location = 'http://www.tagwritetest.test/download'
5656
package.homepage = SPDXNone()
5757
package.verif_code = '4e3211c67a2d28fced849ee1bb76e7391b93feba'
58-
license_set = LicenseConjuction(License.from_identifier('Apache-2.0'),
58+
license_set = LicenseConjunction(License.from_identifier('Apache-2.0'),
5959
License.from_identifier('BSD-2-Clause'))
6060
package.conc_lics = license_set
6161
package.license_declared = license_set

spdx/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ def load_license_list():
4141

4242

4343
LICENSE_MAP = load_license_list()
44-
LICENSE_LIST_VERSION = Version(major=1, minor=19)
44+
LICENSE_LIST_VERSION = Version(major=2, minor=25)

spdx/creationinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __eq__(self, other):
5858
def to_value(self):
5959
"""Tag/value representation of Organization entity."""
6060
if self.email is not None:
61-
return 'Organization : {0} ({1})'.format(self.name, self.email)
61+
return 'Organization: {0} ({1})'.format(self.name, self.email)
6262
else:
6363
return 'Organization: {0}'.format(self.name)
6464

@@ -87,7 +87,7 @@ def __eq__(self, other):
8787
def to_value(self):
8888
"""Tag/value representation of Person entity."""
8989
if self.email is not None:
90-
return 'Person : {0} ({1})'.format(self.name, self.email)
90+
return 'Person: {0} ({1})'.format(self.name, self.email)
9191
else:
9292
return 'Person: {0}'.format(self.name)
9393

spdx/document.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
from spdx.version import Version
1818

1919

20+
def _add_parens(required, text):
21+
"""
22+
Add parens around a license expression if `required` is True, otherwise
23+
return `text` unmodified.
24+
"""
25+
if required:
26+
return '(' + str(text) + ')'
27+
return text
28+
2029
class License(object):
2130

2231
"""Represents a License."""
@@ -78,25 +87,33 @@ def __hash__(self):
7887
return self.identifier.__hash__()
7988

8089

81-
class LicenseConjuction(License):
90+
class LicenseConjunction(License):
8291

83-
"""A conjuction of two licenses."""
92+
"""A conjunction of two licenses."""
8493

8594
def __init__(self, license_1, license_2):
8695
self.license_1 = license_1
8796
self.license_2 = license_2
88-
super(LicenseConjuction, self).__init__(
97+
super(LicenseConjunction, self).__init__(
8998
self.full_name, self.identifier)
9099

91100
@property
92101
def full_name(self):
93-
return '{0} AND {1}'.format(self.license_1.full_name,
94-
self.license_2.full_name)
102+
license_1_complex = type(self.license_1) == LicenseDisjunction
103+
license_2_complex = type(self.license_2) == LicenseDisjunction
104+
105+
return '{0} AND {1}'.format(
106+
_add_parens(license_1_complex, self.license_1.full_name),
107+
_add_parens(license_2_complex, self.license_2.full_name))
95108

96109
@property
97110
def identifier(self):
98-
return '{0} AND {1}'.format(self.license_1.identifier,
99-
self.license_2.identifier)
111+
license_1_complex = type(self.license_1) == LicenseDisjunction
112+
license_2_complex = type(self.license_2) == LicenseDisjunction
113+
114+
return '{0} AND {1}'.format(
115+
_add_parens(license_1_complex, self.license_1.identifier),
116+
_add_parens(license_2_complex, self.license_2.identifier))
100117

101118

102119
class LicenseDisjunction(License):
@@ -111,13 +128,21 @@ def __init__(self, license_1, license_2):
111128

112129
@property
113130
def full_name(self):
114-
return '{0} OR {1}'.format(self.license_1.full_name,
115-
self.license_2.full_name)
131+
license_1_complex = type(self.license_1) == LicenseConjunction
132+
license_2_complex = type(self.license_2) == LicenseConjunction
133+
134+
return '{0} OR {1}'.format(
135+
_add_parens(license_1_complex, self.license_1.full_name),
136+
_add_parens(license_2_complex, self.license_2.full_name))
116137

117138
@property
118139
def identifier(self):
119-
return '{0} OR {1}'.format(self.license_1.identifier,
120-
self.license_2.identifier)
140+
license_1_complex = type(self.license_1) == LicenseConjunction
141+
license_2_complex = type(self.license_2) == LicenseConjunction
142+
143+
return '{0} OR {1}'.format(
144+
_add_parens(license_1_complex, self.license_1.identifier),
145+
_add_parens(license_2_complex, self.license_2.identifier))
121146

122147
class ExtractedLicense(License):
123148
"""Represents an ExtractedLicense.

spdx/parsers/rdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def handle_conjunctive_list(self, lics_set):
235235
self.value_error('LICS_LIST_MEMBER', lics_member)
236236
break
237237
if len(licenses) > 1:
238-
return reduce(lambda a, b: document.LicenseConjuction(a, b), licenses)
238+
return reduce(lambda a, b: document.LicenseConjunction(a, b), licenses)
239239
else:
240240
self.value_error('PKG_CONC_LIST', '')
241241
return

spdx/parsers/tagvaluebuilders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def checksum_from_sha1(value):
3838
checksum. Returns None if doesn't match CHECKSUM_RE.
3939
"""
4040
# More constrained regex at lexer level
41-
CHECKSUM_RE = re.compile('SHA1:(.+)', re.UNICODE)
41+
CHECKSUM_RE = re.compile('SHA1: *(.+)', re.UNICODE)
4242
match = CHECKSUM_RE.match(value)
4343
if match:
4444
return checksum.Algorithm(identifier='SHA1', value=match.group(1))

0 commit comments

Comments
 (0)