Skip to content

Fix #91 by passing all rdflib types in six.text_type function #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion data/SPDXRdfExample.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
<referencesFile>
<File rdf:about="https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-File2">
<copyrightText>Copyright 2010, 2011 Source Auditor Inc.</copyrightText>
<licenseComments></licenseComments>
<licenseInfoInFile rdf:resource="http://spdx.org/licenses/Apache-2.0"/>
<licenseConcluded rdf:resource="http://spdx.org/licenses/Apache-2.0"/>
<fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
Expand Down
26 changes: 13 additions & 13 deletions spdx/parsers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def to_special_value(self, value):
elif value == self.spdx_namespace.unknown:
return utils.UnKnown()
else:
return value
return six.text_type(value)


class LicenseParser(BaseParser):
Expand Down Expand Up @@ -135,7 +135,7 @@ def handle_lics(self, lics):
if special == lics:
if self.LICS_REF_REGEX.match(lics):
# Is a license ref i.e LicenseRef-1
return document.License.from_identifier(lics)
return document.License.from_identifier(six.text_type(lics))
else:
# Not a known license form
raise SPDXValueError('License')
Expand Down Expand Up @@ -164,7 +164,7 @@ def get_extr_license_ident(self, extr_lic):

identifier_tripple = identifier_tripples[0]
_s, _p, identifier = identifier_tripple
return identifier
return six.text_type(identifier)

def get_extr_license_text(self, extr_lic):
"""
Expand All @@ -183,7 +183,7 @@ def get_extr_license_text(self, extr_lic):

text_tripple = text_tripples[0]
_s, _p, text = text_tripple
return text
return six.text_type(text)

def get_extr_lic_name(self, extr_lic):
"""
Expand All @@ -195,14 +195,14 @@ def get_extr_lic_name(self, extr_lic):
return
elif len(extr_name_list) == 0:
return
return self.to_special_value(extr_name_list[0][2])
return six.text_type(self.to_special_value(extr_name_list[0][2]))

def get_extr_lics_xref(self, extr_lic):
"""
Return a list of cross references.
"""
xrefs = list(self.graph.triples((extr_lic, RDFS.seeAlso, None)))
return map(lambda xref_triple: xref_triple[2], xrefs)
return map(lambda xref_triple: six.text_type(xref_triple[2]), xrefs)

def get_extr_lics_comment(self, extr_lics):
"""
Expand All @@ -214,7 +214,7 @@ def get_extr_lics_comment(self, extr_lics):
self.more_than_one_error('extracted license comment')
return
elif len(comment_list) == 1:
return comment_list[0][2]
return six.text_type(comment_list[0][2])
else:
return

Expand Down Expand Up @@ -244,7 +244,7 @@ def parse_only_extr_license(self, extr_lic):
lic.full_name = name
if comment is not None:
lic.comment = comment
lic.cross_ref = map(lambda x: six.text_type(x), xrefs)
lic.cross_ref = xrefs
return lic

def handle_extracted_license(self, extr_lic):
Expand Down Expand Up @@ -341,7 +341,7 @@ def parse_package(self, p_term):
def p_pkg_cr_text(self, p_term, predicate):
try:
for _, _, text in self.graph.triples((p_term, predicate, None)):
self.builder.set_pkg_cr_text(self.doc, self.to_special_value(six.text_type(text)))
self.builder.set_pkg_cr_text(self.doc, six.text_type(self.to_special_value(text)))
except CardinalityError:
self.more_than_one_error('package copyright text')

Expand Down Expand Up @@ -626,7 +626,7 @@ def p_file_lic_info(self, f_term, predicate):
def p_file_spdx_id(self, f_term, predicate):
try:
try:
self.builder.set_file_spdx_id(self.doc, f_term)
self.builder.set_file_spdx_id(self.doc, six.text_type(f_term))
except SPDXValueError:
self.value_error('FILE_SPDX_ID_VALUE', f_term)
except CardinalityError:
Expand Down Expand Up @@ -851,7 +851,7 @@ def parse_annotation(self, r_term):
annotation_type = self.get_annotation_type(r_term)
self.builder.add_annotation_type(self.doc, annotation_type)
try:
self.builder.set_annotation_spdx_id(self.doc, r_term)
self.builder.set_annotation_spdx_id(self.doc, six.text_type(r_term))
except CardinalityError:
self.more_than_one_error('SPDX Identifier Reference')

Expand All @@ -861,7 +861,7 @@ def get_annotation_type(self, r_term):
for _, _, typ in self.graph.triples((
r_term, self.spdx_namespace['annotationType'], None)):
if typ is not None:
return typ
return six.text_type(typ)
else:
self.error = True
msg = 'Annotation must have exactly one annotation type.'
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def parse_doc_fields(self, doc_term):
"""Parses the version, data license, name, SPDX Identifier, namespace,
and comment."""
try:
self.builder.set_doc_spdx_id(self.doc, doc_term)
self.builder.set_doc_spdx_id(self.doc, six.text_type(doc_term))
except SPDXValueError:
self.value_error('DOC_SPDX_ID_VALUE', doc_term)
try:
Expand Down
Loading