Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/npm.py
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | def normalize_bugs(self, d): | ||||
... 'email': 'bugs@example.org' | ... 'email': 'bugs@example.org' | ||||
... }) | ... }) | ||||
rdflib.term.URIRef('https://example.org/bugs/') | rdflib.term.URIRef('https://example.org/bugs/') | ||||
>>> NpmMapping().normalize_bugs( | >>> NpmMapping().normalize_bugs( | ||||
... 'https://example.org/bugs/') | ... 'https://example.org/bugs/') | ||||
rdflib.term.URIRef('https://example.org/bugs/') | rdflib.term.URIRef('https://example.org/bugs/') | ||||
""" | """ | ||||
if isinstance(d, dict) and isinstance(d.get("url"), str): | if isinstance(d, dict) and isinstance(d.get("url"), str): | ||||
return URIRef(d["url"]) | url = d["url"] | ||||
elif isinstance(d, str): | elif isinstance(d, str): | ||||
return URIRef(d) | url = d | ||||
else: | |||||
url = "" | |||||
parsed_url = urllib.parse.urlparse(url) | |||||
if parsed_url.netloc: | |||||
return URIRef(url) | |||||
else: | else: | ||||
return None | return None | ||||
_parse_author = re.compile( | _parse_author = re.compile( | ||||
r"^ *" r"(?P<name>.*?)" r"( +<(?P<email>.*)>)?" r"( +\((?P<url>.*)\))?" r" *$" | r"^ *" r"(?P<name>.*?)" r"( +<(?P<email>.*)>)?" r"( +\((?P<url>.*)\))?" r" *$" | ||||
) | ) | ||||
def translate_author(self, graph: Graph, root, d): | def translate_author(self, graph: Graph, root, d): | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |