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_entry_properties_from_node(entry, include_id, id_prefix_to_skip=None, use_title_as_id=False):
''' get properties from entry xml '''
properties = {}
etag = entry.getAttributeNS(METADATA_NS, 'etag')
if etag:
properties['etag'] = etag
for updated in _MinidomXmlToObject.get_child_nodes(entry, 'updated'):
properties['updated'] = updated.firstChild.nodeValue
for name in _MinidomXmlToObject.get_children_from_path(entry, 'author', 'name'):
if name.firstChild is not None:
properties['author'] = name.firstChild.nodeValue
if include_id:
if use_title_as_id:
for title in _MinidomXmlToObject.get_child_nodes(entry, 'title'):
properties['name'] = title.firstChild.nodeValue
else:
# TODO: check if this is used
for id in _MinidomXmlToObject.get_child_nodes(entry, 'id'):
properties['name'] = _get_readable_id(
id.firstChild.nodeValue, id_prefix_to_skip)
return properties
@staticmethod
def get_entry_properties_from_node(entry, include_id, id_prefix_to_skip=None, use_title_as_id=False):
''' get properties from entry xml '''
properties = {}
etag = entry.getAttributeNS(METADATA_NS, 'etag')
if etag:
properties['etag'] = etag
for updated in _MinidomXmlToObject.get_child_nodes(entry, 'updated'):
properties['updated'] = updated.firstChild.nodeValue
for name in _MinidomXmlToObject.get_children_from_path(entry, 'author', 'name'):
if name.firstChild is not None:
properties['author'] = name.firstChild.nodeValue
if include_id:
if use_title_as_id:
for title in _MinidomXmlToObject.get_child_nodes(entry, 'title'):
properties['name'] = title.firstChild.nodeValue
else:
# TODO: check if this is used
for id in _MinidomXmlToObject.get_child_nodes(entry, 'id'):
properties['name'] = _get_readable_id(
id.firstChild.nodeValue, id_prefix_to_skip)
return properties
@staticmethod
def get_children_from_path(node, *path):
'''descends through a hierarchy of nodes returning the list of children
at the inner most level. Only returns children who share a common parent,
not cousins.'''
cur = node
for index, child in enumerate(path):
if isinstance(child, _strtype):
next = _MinidomXmlToObject.get_child_nodes(cur, child)
else:
next = _MinidomXmlToObject._get_child_nodesNS(cur, *child)
if index == len(path) - 1:
return next
elif not next:
break
cur = next[0]
return []
Val2
element_type=str
parent_xml_element_name='ExtendedProperties'
pair_xml_element_name='ExtendedProperty'
key_xml_element_name='Name'
value_xml_element_name='Value'
'''
return_obj = {}
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, parent_xml_element_name)
if xmlelements:
xmlelements = _MinidomXmlToObject.get_child_nodes(xmlelements[0], pair_xml_element_name)
for pair in xmlelements:
keys = _MinidomXmlToObject.get_child_nodes(pair, key_xml_element_name)
values = _MinidomXmlToObject.get_child_nodes(pair, value_xml_element_name)
if keys and values:
key = keys[0].firstChild.nodeValue
valueContentNode = values[0].firstChild
value = valueContentNode.nodeValue if valueContentNode else None
return_obj[key] = value
return return_obj
element_type=str
parent_xml_element_name='ExtendedProperties'
pair_xml_element_name='ExtendedProperty'
key_xml_element_name='Name'
value_xml_element_name='Value'
'''
return_obj = {}
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, parent_xml_element_name)
if xmlelements:
xmlelements = _MinidomXmlToObject.get_child_nodes(xmlelements[0], pair_xml_element_name)
for pair in xmlelements:
keys = _MinidomXmlToObject.get_child_nodes(pair, key_xml_element_name)
values = _MinidomXmlToObject.get_child_nodes(pair, value_xml_element_name)
if keys and values:
key = keys[0].firstChild.nodeValue
valueContentNode = values[0].firstChild
value = valueContentNode.nodeValue if valueContentNode else None
return_obj[key] = value
return return_obj
xml_element_name):
'''Converts an xml fragment into a list of scalar types. The parent xml
element contains a flat list of xml elements which are converted into the
specified scalar type and added to the list.
Example:
xmldoc=
http://{storage-service-name}.blob.core.windows.net/
http://{storage-service-name}.queue.core.windows.net/
http://{storage-service-name}.table.core.windows.net/
element_type=str
parent_xml_element_name='Endpoints'
xml_element_name='Endpoint'
'''
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, parent_xml_element_name)
if xmlelements:
xmlelements = _MinidomXmlToObject.get_child_nodes(xmlelements[0], xml_element_name)
return [_MinidomXmlToObject._get_node_value(xmlelement, element_type) \
for xmlelement in xmlelements]
@staticmethod
def _fill_dict(xmldoc, element_name):
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, element_name)
if xmlelements:
return_obj = {}
for child in xmlelements[0].childNodes:
if child.firstChild:
return_obj[child.nodeName] = child.firstChild.nodeValue
return return_obj