Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 096dacf

Browse filesBrowse files
Add tests for JSON and YAML capabilities.
Signed-off-by: Xavier Figueroa <xavierfigueroav@gmail.com>
1 parent ac6ed5d commit 096dacf
Copy full SHA for 096dacf

14 files changed

+1,024-841Lines changed: 1024 additions & 841 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎data/SPDXJsonExample.json‎

Copy file name to clipboardExpand all lines: data/SPDXJsonExample.json
+161-391Lines changed: 161 additions & 391 deletions
Large diffs are not rendered by default.
Collapse file

‎data/SPDXYamlExample.yaml‎

Copy file name to clipboardExpand all lines: data/SPDXYamlExample.yaml
+127-420Lines changed: 127 additions & 420 deletions
Large diffs are not rendered by default.
Collapse file

‎spdx/parsers/jsonyaml.py‎

Copy file name to clipboardExpand all lines: spdx/parsers/jsonyaml.py
+18-8Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import six
22
from spdx import document
3+
from spdx import utils
34
from spdx.parsers.builderexceptions import SPDXValueError, CardinalityError, OrderError
45
from spdx.parsers import rdf
5-
from spdx.document import License
66

77
ERROR_MESSAGES = rdf.ERROR_MESSAGES
88

@@ -140,7 +140,7 @@ def parse_external_document_refs(self, external_document_refs):
140140
self.parse_ext_doc_ref_chksum(external_document_ref.get('checksum'))
141141
else:
142142
self.value_error('EXT_DOC_REF', external_document_ref)
143-
else:
143+
elif external_document_refs is not None:
144144
self.value_error('EXT_DOC_REFS_SECTION', external_document_refs)
145145

146146
def parse_ext_doc_ref_id(self, ext_doc_ref_id):
@@ -536,7 +536,9 @@ def parse_file_concluded_license(self, concluded_license):
536536
- concluded_license: Python str/unicode
537537
"""
538538
if isinstance(concluded_license, six.string_types):
539-
license_object = License.from_identifier(concluded_license)
539+
lic_parser = utils.LicenseListParser()
540+
lic_parser.build(write_tables=0, debug=0)
541+
license_object = lic_parser.parse(concluded_license)
540542
try:
541543
return self.builder.set_concluded_license(self.document, license_object)
542544
except SPDXValueError:
@@ -556,7 +558,9 @@ def parse_file_license_info_from_files(self, license_info_from_files):
556558
if isinstance(license_info_from_files, list):
557559
for license_info_from_file in license_info_from_files:
558560
if isinstance(license_info_from_file, six.string_types):
559-
license_object = License.from_identifier(license_info_from_file)
561+
lic_parser = utils.LicenseListParser()
562+
lic_parser.build(write_tables=0, debug=0)
563+
license_object = lic_parser.parse(license_info_from_file)
560564
try:
561565
self.builder.set_file_license_in_file(self.document, license_object)
562566
except SPDXValueError:
@@ -840,7 +844,7 @@ def parse_pkg_verif_code_field(self, pkg_verif_code_field):
840844
- pkg_verif_code_field: Python dict('value':str/unicode, 'excludedFilesNames':list)
841845
"""
842846
if isinstance(pkg_verif_code_field, dict):
843-
self.parse_pkg_verif_exc_files(pkg_verif_code_field.get('excludedFileNames'))
847+
self.parse_pkg_verif_exc_files(pkg_verif_code_field.get('excludedFilesNames'))
844848
return self.parse_pkg_verif_code(pkg_verif_code_field.get('value'))
845849
else:
846850
self.value_error('PKG_VERIF_CODE_FIELD', pkg_verif_code_field)
@@ -915,7 +919,9 @@ def parse_pkg_concluded_license(self, pkg_concluded_license):
915919
- pkg_concluded_license: Python str/unicode
916920
"""
917921
if isinstance(pkg_concluded_license, six.string_types):
918-
license_object = License.from_identifier(pkg_concluded_license)
922+
lic_parser = utils.LicenseListParser()
923+
lic_parser.build(write_tables=0, debug=0)
924+
license_object = lic_parser.parse(pkg_concluded_license)
919925
try:
920926
return self.builder.set_pkg_licenses_concluded(self.document, license_object)
921927
except SPDXValueError:
@@ -935,7 +941,9 @@ def parse_pkg_license_info_from_files(self, license_info_from_files):
935941
if isinstance(license_info_from_files, list):
936942
for license_info_from_file in license_info_from_files:
937943
if isinstance(license_info_from_file, six.string_types):
938-
license_object = License.from_identifier(license_info_from_file)
944+
lic_parser = utils.LicenseListParser()
945+
lic_parser.build(write_tables=0, debug=0)
946+
license_object = lic_parser.parse(license_info_from_file)
939947
try:
940948
self.builder.set_pkg_license_from_file(self.document, license_object)
941949
except SPDXValueError:
@@ -953,7 +961,9 @@ def parse_pkg_declared_license(self, pkg_declared_license):
953961
- pkg_declared_license: Python str/unicode
954962
"""
955963
if isinstance(pkg_declared_license, six.string_types):
956-
license_object = License.from_identifier(pkg_declared_license)
964+
lic_parser = utils.LicenseListParser()
965+
lic_parser.build(write_tables=0, debug=0)
966+
license_object = lic_parser.parse(pkg_declared_license)
957967
try:
958968
return self.builder.set_pkg_license_declared(self.document, license_object)
959969
except SPDXValueError:
Collapse file

‎spdx/parsers/rdf.py‎

Copy file name to clipboardExpand all lines: spdx/parsers/rdf.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def get_extr_lics_xref(self, extr_lic):
207207
Return a list of cross references.
208208
"""
209209
xrefs = list(self.graph.triples((extr_lic, RDFS.seeAlso, None)))
210-
return map(lambda xref_triple: six.text_type(xref_triple[2]), xrefs)
210+
return list(map(lambda xref_triple: xref_triple[2], xrefs))
211211

212212
def get_extr_lics_comment(self, extr_lics):
213213
"""
@@ -249,7 +249,7 @@ def parse_only_extr_license(self, extr_lic):
249249
lic.full_name = name
250250
if comment is not None:
251251
lic.comment = comment
252-
lic.cross_ref = xrefs
252+
lic.cross_ref = list(map(lambda x: six.text_type(x), xrefs))
253253
return lic
254254

255255
def handle_extracted_license(self, extr_lic):
Collapse file

‎spdx/writers/jsonyaml.py‎

Copy file name to clipboardExpand all lines: spdx/writers/jsonyaml.py
+10-15Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ def license(self, license_field):
2121
"""
2222
Returns a string representation of a license or spdx.utils special object
2323
"""
24+
if isinstance(license_field, (document.LicenseDisjunction, document.LicenseConjunction)):
25+
return '({})'.format(license_field)
26+
2427
if isinstance(license_field, document.License):
25-
license_str = str(license_field.identifier)
28+
license_str = license_field.identifier.__str__()
2629
else:
2730
license_str = license_field.__str__()
28-
29-
tmp_license_str = license_str.lower()
30-
comp_license = 'and' in tmp_license_str or 'or' in tmp_license_str
31-
if comp_license:
32-
if license_str.startswith('(') and license_str.endswith(')'):
33-
return license_str
34-
return ''.join(['(', license_str, ')'])
3531
return license_str
3632

3733
def checksum(self, checksum_field):
@@ -54,7 +50,7 @@ def __init__(self, document):
5450
def create_creation_info(self):
5551
creation_info_object = dict()
5652
creation_info = self.document.creation_info
57-
creation_info_object['creators'] = map(str, creation_info.creators)
53+
creation_info_object['creators'] = list(map(str, creation_info.creators))
5854
creation_info_object['created'] = creation_info.created_iso_format
5955

6056
if creation_info.license_list_version:
@@ -92,11 +88,10 @@ def create_package_info(self):
9288
package_object = dict()
9389
package = self.document.package
9490
package_object['name'] = package.name
95-
package_object['id'] = "PackageSPDXID" # Mandatory field but there's not in package class
96-
package_object['downloadLocation'] = package.download_location
91+
package_object['downloadLocation'] = package.download_location.__str__()
9792
package_object['packageVerificationCode'] = self.package_verification_code(package)
9893
package_object['licenseConcluded'] = self.license(package.conc_lics)
99-
package_object['licenseInfoFromFiles'] = map(self.license, package.licenses_from_files)
94+
package_object['licenseInfoFromFiles'] = list(map(self.license, package.licenses_from_files))
10095
package_object['licenseDeclared'] = self.license(package.license_declared)
10196
package_object['copyrightText'] = package.cr_text.__str__()
10297

@@ -119,7 +114,7 @@ def create_package_info(self):
119114
package_object['originator'] = package.originator.__str__()
120115

121116
if package.has_optional_field('check_sum'):
122-
package_object['checksums'] = self.checksum(package.check_sum)
117+
package_object['checksums'] = [self.checksum(package.check_sum)]
123118
package_object['sha1'] = package.check_sum.value
124119

125120
if package.has_optional_field('description'):
@@ -168,7 +163,7 @@ def create_file_info(self):
168163
file_object['id'] = str(file.spdx_id)
169164
file_object['checksums'] = [self.checksum(file.chk_sum)]
170165
file_object['licenseConcluded'] = self.license(file.conc_lics)
171-
file_object['licenseInfoFromFiles'] = map(self.license, file.licenses_in_file)
166+
file_object['licenseInfoFromFiles'] = list(map(self.license, file.licenses_in_file))
172167
file_object['copyrightText'] = file.copyright.__str__()
173168
file_object['sha1'] = file.chk_sum.value
174169

@@ -328,7 +323,7 @@ def create_ext_document_references(self):
328323
return ext_document_reference_objects
329324

330325
def create_document(self):
331-
self.document_object = dict()
326+
self.document_object = dict()
332327

333328
self.document_object['specVersion'] = self.document.version.__str__()
334329
self.document_object['namespace'] = self.document.namespace.__str__()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.