Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/client/__init__.py
Show All 32 Lines | Returns: | ||||
A dict of values corresponding to the parsed xml | A dict of values corresponding to the parsed xml | ||||
""" | """ | ||||
if isinstance(stream, bytes): | if isinstance(stream, bytes): | ||||
stream = stream.decode(encoding) | stream = stream.decode(encoding) | ||||
data = xmltodict.parse(stream, encoding=encoding, process_namespaces=False) | data = xmltodict.parse(stream, encoding=encoding, process_namespaces=False) | ||||
if 'entry' in data: | if 'entry' in data: | ||||
data = data['entry'] | data = data['entry'] | ||||
if 'sword:error' in data: | |||||
data = data['sword:error'] | |||||
return dict(data) | return dict(data) | ||||
def _parse_with_filter(stream, encoding='utf-8', keys=[]): | def _parse_with_filter(stream, encoding='utf-8', keys=[]): | ||||
"""Given a xml stream, parse the result and filter with keys. | """Given a xml stream, parse the result and filter with keys. | ||||
Args: | Args: | ||||
stream (bytes/text): The stream to parse | stream (bytes/text): The stream to parse | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | def parse_result_error(self, xml_content): | ||||
Returns: | Returns: | ||||
dict with following keys: | dict with following keys: | ||||
'error': The error message | 'error': The error message | ||||
'detail': Some more detail about the error if any | 'detail': Some more detail about the error if any | ||||
""" | """ | ||||
return _parse_with_filter(xml_content, keys=['summary', 'detail']) | return _parse_with_filter(xml_content, keys=[ | ||||
'summary', 'detail', 'sword:verboseDescription']) | |||||
def do_execute(self, method, url, info): | def do_execute(self, method, url, info): | ||||
"""Execute the http query to url using method and info information. | """Execute the http query to url using method and info information. | ||||
By default, execute a simple query to url with the http | By default, execute a simple query to url with the http | ||||
method. Override this in daughter class to improve the | method. Override this in daughter class to improve the | ||||
default behavior if needed. | default behavior if needed. | ||||
▲ Show 20 Lines • Show All 313 Lines • Show Last 20 Lines |