Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_rml_element_text(rml, element):
element_xmletree = rml.find(xmletree.prefixtag("rml", element))
return xmletree.get_element_text(element_xmletree)
def get_rml_turnovers(rml):
""" turnover -> turnovers """
result = {}
rml_turnovers = rml.findall(xmletree.prefixtag("rml", "turnover"))
if rml_turnovers is not None:
turnovers = []
for rml_turnover in rml_turnovers:
if rml_turnover is not None:
turnover = {}
turnover.update(xmletree.get_element_attribute_and_set_key(rml_turnover, "currency", "currency"))
turnover.update(xmletree.get_element_attribute_and_set_key(rml_turnover, "year", "year"))
turnover["value"] = xmletree.get_element_text(rml_turnover)
if turnover:
turnovers.append(turnover)
if turnovers:
result["turnovers"] = turnovers
return result
conditions.append(value)
if conditions:
sap["conditions"] = conditions
# copyright -> copyright
sap.update(get_rml_element_text_and_set_key(rml_romeo, "copyright", "copyright"))
# copyrightlinks -> copyright_urls
rml_copyrightlinks = rml_romeo.find(xmletree.prefixtag("rml", "copyrightlinks"))
if rml_copyrightlinks is not None:
rml_copyrightlinks_list = rml_copyrightlinks.findall(xmletree.prefixtag("rml", "copyrightlink"))
if rml_copyrightlinks_list is not None:
copyright_urls = []
for rml_copyrightlink in rml_copyrightlinks_list:
copyrightlinktext = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinktext")))
copyrightlinkurl = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinkurl")))
copyright_url = metajson_service.create_url(copyrightlinkurl, None, None, copyrightlinktext, None, None)
copyright_urls.append(copyright_url)
if copyright_urls:
sap["copyright_urls"] = copyright_urls
# paidaccess -> paid_access
rml_paidaccess = rml_romeo.find(xmletree.prefixtag("rml", "paidaccess"))
if rml_paidaccess is not None:
paid_access = {}
# paidaccessname -> label
paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessname", "label"))
# paidaccessurl -> url
paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessurl", "url"))
def get_rml_money_and_set_key(rml, element, key):
""" element -> key """
result = {}
rml_element = rml.find(xmletree.prefixtag("rml", element))
if rml_element is not None:
money = {}
# currency -> currency
money.update(xmletree.get_element_attribute_and_set_key(rml_element, "currency", "currency"))
# text -> value
money["value"] = xmletree.get_element_text(rml_element)
if money:
result[key] = money
return result
def get_mods_element_text(rml, element, strip=True):
element_xmletree = rml.find(xmletree.prefixtag("mods", element))
return xmletree.get_element_text(element_xmletree, strip)
def get_mods_elements_text(rml, element):
elements_xmletree = rml.findall(xmletree.prefixtag("mods", element))
if elements_xmletree is not None:
results = []
for element_xmletree in elements_xmletree:
if element_xmletree is not None:
results.append(xmletree.get_element_text(element_xmletree))
if results:
return results
return None
result = {}
rml_ims = rml.findall(xmletree.prefixtag("rml", "instantMessage"))
if rml_ims is not None:
ims = []
for rml_im in rml_ims:
if rml_im is not None:
# @preferred -> preferred
preferred = xmletree.get_element_attribute_as_boolean(rml_im, "preferred")
# @relationType -> relation_type
relation_type = rml_im.get("relationType")
# @service -> service
service = rml_im.get("service")
# @visible -> visible
visible = xmletree.get_element_attribute_as_boolean(rml_im, "visible")
# value
value = xmletree.get_element_text(rml_im)
im = metajson_service.create_instant_message(value, service, preferred, relation_type, visible)
if im:
ims.append(im)
if ims:
result["instant_messages"] = ims
return result
def get_rml_uris(rml):
""" uri -> urls """
result = {}
rml_uris = rml.findall(xmletree.prefixtag("rml", "uri"))
if rml_uris is not None:
urls = []
for rml_uri in rml_uris:
if rml_uri is not None:
preferred = xmletree.get_element_attribute_as_boolean(rml_uri, "preferred")
relation_type = rml_uri.get("relationType")
visible = xmletree.get_element_attribute_as_boolean(rml_uri, "visible")
value = xmletree.get_element_text(rml_uri)
url = metajson_service.create_url(value, preferred, relation_type, None, None, visible)
if url:
urls.append(url)
if urls:
result["urls"] = urls
return result