Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/parsers.py
Show All 40 Lines | class SWHXMLParser(BaseParser): | ||||
media_type = "application/xml" | media_type = "application/xml" | ||||
def parse(self, stream, media_type=None, parser_context=None): | def parse(self, stream, media_type=None, parser_context=None): | ||||
""" | """ | ||||
Parses the incoming bytestream as XML and returns the resulting data. | Parses the incoming bytestream as XML and returns the resulting data. | ||||
""" | """ | ||||
parser_context = parser_context or {} | parser_context = parser_context or {} | ||||
encoding = parser_context.get("encoding", settings.DEFAULT_CHARSET) | encoding = parser_context.get("encoding", settings.DEFAULT_CHARSET) | ||||
data = xmltodict.parse(stream, encoding=encoding, process_namespaces=False) | namespaces = { | ||||
"http://www.w3.org/2005/Atom": None, | |||||
"http://purl.org/dc/terms/": None, | |||||
"https://doi.org/10.5063/SCHEMA/CODEMETA-2.0": "codemeta", | |||||
"http://purl.org/net/sword/": "sword", | |||||
} | |||||
data = xmltodict.parse( | |||||
stream, encoding=encoding, namespaces=namespaces, process_namespaces=True | |||||
) | |||||
if "entry" in data: | if "entry" in data: | ||||
data = data["entry"] | data = data["entry"] | ||||
return data | return data | ||||
class SWHAtomEntryParser(SWHXMLParser): | class SWHAtomEntryParser(SWHXMLParser): | ||||
"""Atom entry parser limited to specific mediatype | """Atom entry parser limited to specific mediatype | ||||
Show All 37 Lines |