Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/maven.py
# Copyright (C) 2018-2021 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
from typing import Any, Dict, Optional | |||||
import xml.parsers.expat | import xml.parsers.expat | ||||
import xmltodict | import xmltodict | ||||
from swh.indexer.codemeta import CROSSWALK_TABLE, SCHEMA_URI | from swh.indexer.codemeta import CROSSWALK_TABLE, SCHEMA_URI | ||||
from .base import DictMapping, SingleFileMapping | from .base import DictMapping, SingleFileMapping | ||||
class MavenMapping(DictMapping, SingleFileMapping): | class MavenMapping(DictMapping, SingleFileMapping): | ||||
""" | """ | ||||
dedicated class for Maven (pom.xml) mapping and translation | dedicated class for Maven (pom.xml) mapping and translation | ||||
""" | """ | ||||
name = "maven" | name = "maven" | ||||
filename = b"pom.xml" | filename = b"pom.xml" | ||||
mapping = CROSSWALK_TABLE["Java (Maven)"] | mapping = CROSSWALK_TABLE["Java (Maven)"] | ||||
string_fields = ["name", "version", "description", "email"] | string_fields = ["name", "version", "description", "email"] | ||||
def translate(self, content): | def translate(self, content: bytes) -> Optional[Dict[str, Any]]: | ||||
try: | try: | ||||
vlorentz: ditto | |||||
Done Inline ActionsI could change it though. I haven't done type annotations before I came across the issue, so still learning things. VickyMerzOwn: I could change it though. I haven't done type annotations before I came across the issue, so… | |||||
d = xmltodict.parse(content).get("project") or {} | d = xmltodict.parse(content).get("project") or {} | ||||
except xml.parsers.expat.ExpatError: | except xml.parsers.expat.ExpatError: | ||||
self.log.warning("Error parsing XML from %s", self.log_suffix) | self.log.warning("Error parsing XML from %s", self.log_suffix) | ||||
return None | return None | ||||
except UnicodeDecodeError: | except UnicodeDecodeError: | ||||
self.log.warning("Error unidecoding XML from %s", self.log_suffix) | self.log.warning("Error unidecoding XML from %s", self.log_suffix) | ||||
return None | return None | ||||
except (LookupError, ValueError): | except (LookupError, ValueError): | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |
ditto