Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/utils.py
Show All 9 Lines | |||||
import xmltodict | import xmltodict | ||||
from swh.model.identifiers import SWHID, normalize_timestamp, parse_swhid | from swh.model.identifiers import SWHID, normalize_timestamp, parse_swhid | ||||
from swh.model.model import MetadataTargetType | from swh.model.model import MetadataTargetType | ||||
def parse_xml(stream, encoding="utf-8"): | def parse_xml(stream, encoding="utf-8"): | ||||
namespaces = { | namespaces = { | ||||
"http://www.w3.org/2005/Atom": None, | "http://www.w3.org/2005/Atom": "atom", | ||||
"http://www.w3.org/2007/app": "app", | "http://www.w3.org/2007/app": "app", | ||||
"http://purl.org/dc/terms/": "dc", | "http://purl.org/dc/terms/": "dc", | ||||
"https://doi.org/10.5063/SCHEMA/CODEMETA-2.0": "codemeta", | "https://doi.org/10.5063/SCHEMA/CODEMETA-2.0": "codemeta", | ||||
"http://purl.org/net/sword/terms/": "sword", | "http://purl.org/net/sword/terms/": "sword", | ||||
"https://www.softwareheritage.org/schema/2018/deposit": "swh", | "https://www.softwareheritage.org/schema/2018/deposit": "swh", | ||||
} | } | ||||
data = xmltodict.parse( | data = xmltodict.parse( | ||||
stream, encoding=encoding, namespaces=namespaces, process_namespaces=True | stream, encoding=encoding, namespaces=namespaces, process_namespaces=True | ||||
) | ) | ||||
if "entry" in data: | if "atom:entry" in data: | ||||
data = data["entry"] | data = data["atom:entry"] | ||||
return data | return data | ||||
def merge(*dicts): | def merge(*dicts): | ||||
"""Given an iterator of dicts, merge them losing no information. | """Given an iterator of dicts, merge them losing no information. | ||||
Args: | Args: | ||||
*dicts: arguments are all supposed to be dict to merge into one | *dicts: arguments are all supposed to be dict to merge into one | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |