本文整理汇总了Python中nova.api.openstack.xmlutil.safe_minidom_parse_string函数的典型用法代码示例。如果您正苦于以下问题:Python safe_minidom_parse_string函数的具体用法?Python safe_minidom_parse_string怎么用?Python safe_minidom_parse_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_minidom_parse_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: default
def default(self, string):
events = []
dom = xmlutil.safe_minidom_parse_string(string)
events_node = self.find_first_child_named(dom, "events")
for event_node in self.find_children_named(events_node, "event"):
events.append(self._extract_event(event_node))
return {"body": {"events": events}}
示例2: action_peek_xml
def action_peek_xml(body):
"""Determine action to invoke."""
dom = xmlutil.safe_minidom_parse_string(body)
action_node = dom.childNodes[0]
return action_node.tagName
示例3: deserialize
def deserialize(self, text):
dom = xmlutil.safe_minidom_parse_string(text)
metadata_node = self.find_first_child_named(dom, "metadata")
key = metadata_node.getAttribute("key")
metadata = {}
metadata[key] = self.extract_text(metadata_node)
return {'body': {'metadata': metadata}}
示例4: default
def default(self, string):
dom = xmlutil.safe_minidom_parse_string(string)
action_node = dom.childNodes[0]
action_name = action_node.tagName
action_data = None
if action_node.hasAttribute("admin_password"):
action_data = {'admin_password':
action_node.getAttribute("admin_password")}
return {'body': {action_name: action_data}}
示例5: default
def default(self, string):
node = xmlutil.safe_minidom_parse_string(string)
service = {}
service_node = self.find_first_child_named(node, 'service')
if service_node is None:
return service
service['host'] = service_node.getAttribute('host')
service['binary'] = service_node.getAttribute('binary')
return dict(body=service)
示例6: default
def default(self, string):
node = xmlutil.safe_minidom_parse_string(string)
service = {}
service_node = self.find_first_child_named(node, "service")
if service_node is None:
return service
service["host"] = service_node.getAttribute("host")
service["binary"] = service_node.getAttribute("binary")
service["disabled_reason"] = service_node.getAttribute("disabled_reason")
return dict(body=service)
示例7: default
def default(self, string):
"""Deserialize an xml-formatted security group create request."""
dom = xmlutil.safe_minidom_parse_string(string)
security_group = {}
sg_node = self.find_first_child_named(dom, "security_group")
if sg_node is not None:
if sg_node.hasAttribute("name"):
security_group["name"] = sg_node.getAttribute("name")
desc_node = self.find_first_child_named(sg_node, "description")
if desc_node:
security_group["description"] = self.extract_text(desc_node)
return {"body": {"security_group": security_group}}
示例8: test_safe_parse_xml
def test_safe_parse_xml(self):
normal_body = ('<?xml version="1.0" ?>'
'<foo><bar><v1>hey</v1><v2>there</v2></bar></foo>')
dom = xmlutil.safe_minidom_parse_string(normal_body)
# Some versions of minidom inject extra newlines so we ignore them
result = str(dom.toxml()).replace('\n', '')
self.assertEqual(normal_body, result)
self.assertRaises(exception.MalformedRequestBody,
xmlutil.safe_minidom_parse_string,
tests_utils.killer_xml_body())
示例9: default
def default(self, string):
node = xmlutil.safe_minidom_parse_string(string)
updates = {}
updates_node = self.find_first_child_named(node, "updates")
if updates_node is not None:
maintenance = self.find_first_child_named(updates_node, "maintenance_mode")
if maintenance is not None:
updates[maintenance.tagName] = self.extract_text(maintenance)
status = self.find_first_child_named(updates_node, "status")
if status is not None:
updates[status.tagName] = self.extract_text(status)
return dict(body=updates)
示例10: test_safe_parse_xml
def test_safe_parse_xml(self):
normal_body = ("""
<?xml version="1.0" ?><foo>
<bar>
<v1>hey</v1>
<v2>there</v2>
</bar>
</foo>""").strip()
dom = xmlutil.safe_minidom_parse_string(normal_body)
self.assertEqual(normal_body, str(dom.toxml()))
self.assertRaises(exception.MalformedRequestBody,
xmlutil.safe_minidom_parse_string,
tests_utils.killer_xml_body())
示例11: default
def default(self, string):
"""Deserialize an xml-formatted volume create request."""
dom = xmlutil.safe_minidom_parse_string(string)
vol = self._extract_volume(dom)
return {"body": {"volume": vol}}
示例12: _extract_metadata_container
def _extract_metadata_container(self, datastring):
dom = xmlutil.safe_minidom_parse_string(datastring)
metadata_node = self.find_first_child_named(dom, "metadata")
metadata = self.extract_metadata(metadata_node)
return {'body': {'metadata': metadata}}
示例13: update
def update(self, datastring):
dom = xmlutil.safe_minidom_parse_string(datastring)
metadata_item = self.extract_metadata(dom)
return {'body': {'meta': metadata_item}}
示例14: deserialize
def deserialize(self, text):
dom = xmlutil.safe_minidom_parse_string(text)
metadata_node = self.find_first_child_named(dom, "metadata")
metadata = self.extract_metadata(metadata_node)
return {'body': {'metadata': metadata}}
示例15: default
def default(self, string):
"""Deserialize an xml-formatted security group create request."""
dom = xmlutil.safe_minidom_parse_string(string)
security_group_rule = self._extract_security_group_rule(dom)
return {'body': {'security_group_rule': security_group_rule}}