Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary.py
Show First 20 Lines • Show All 466 Lines • ▼ Show 20 Lines | def parse_licenses(self, d): | ||||
... </license> | ... </license> | ||||
... </licenses> | ... </licenses> | ||||
... ''') | ... ''') | ||||
>>> pprint(MavenMapping().parse_licenses(d)) | >>> pprint(MavenMapping().parse_licenses(d)) | ||||
[{'@id': 'https://www.apache.org/licenses/LICENSE-2.0.txt'}, | [{'@id': 'https://www.apache.org/licenses/LICENSE-2.0.txt'}, | ||||
{'@id': 'https://opensource.org/licenses/MIT'}] | {'@id': 'https://opensource.org/licenses/MIT'}] | ||||
""" | """ | ||||
licenses = d.get('licenses', {}).get('license', []) | licenses = d.get('licenses') | ||||
if not isinstance(licenses, dict): | |||||
return | |||||
licenses = licenses.get('license') | |||||
if isinstance(licenses, dict): | if isinstance(licenses, dict): | ||||
licenses = [licenses] | licenses = [licenses] | ||||
elif not isinstance(licenses, list): | |||||
return | |||||
return [{"@id": license['url']} | return [{"@id": license['url']} | ||||
for license in licenses | for license in licenses | ||||
if 'url' in license] or None | if isinstance(license, dict) and 'url' in license] or None | ||||
_normalize_pkginfo_key = str.lower | _normalize_pkginfo_key = str.lower | ||||
class LinebreakPreservingEmailPolicy(email.policy.EmailPolicy): | class LinebreakPreservingEmailPolicy(email.policy.EmailPolicy): | ||||
def header_fetch_parse(self, name, value): | def header_fetch_parse(self, name, value): | ||||
if hasattr(value, 'name'): | if hasattr(value, 'name'): | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |