本文整理汇总了Python中XML.dig方法的典型用法代码示例。如果您正苦于以下问题:Python XML.dig方法的具体用法?Python XML.dig怎么用?Python XML.dig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML.dig方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocess
# 需要导入模块: import XML [as 别名]
# 或者: from XML import dig [as 别名]
def preprocess(self):
message = XML.dig(self.xml, "message")
if not message:
raise XML.XMLValidityError("A Message's root node must be named 'message'")
# Stamp it with the current time if it has no timestamp yet
if not XML.dig(message, "timestamp"):
XML.addElement(message, "timestamp", "%d" % time.time())
示例2: textComponent
# 需要导入模块: import XML [as 别名]
# 或者: from XML import dig [as 别名]
def textComponent(self, element, args, *path):
"""A convenience function for defining components that just look for a node
in the message and return its shallowText.
"""
element = XML.dig(args.message.xml, *path)
if element:
return [XML.shallowText(element)]
else:
return [MarkAsHidden()]
示例3: postprocessMessage
# 需要导入模块: import XML [as 别名]
# 或者: from XML import dig [as 别名]
def postprocessMessage(self, xml):
"""Gets a chance to modify all XML messages before they're loaded
and dispatched to the Hub. This does the following:
- If there is no <generator> at all, adds a generic one
- Removes any <mailHeaders> tag that may already exist in <generator>
- Adds a correct <mailHeaders> tag to the <generator>
"""
# Create the <generator> tag if it doesn't exist
if not XML.dig(xml, "message", "generator"):
xml.documentElement.appendChild(self.getLocalGenerator(xml))
generator = XML.dig(xml, "message", "generator")
# Delete an existing <mailHeaders>
for child in list(XML.getChildElements(generator)):
if child.nodeName == "mailHeaders":
generator.removeChild(child)
# Add a new <mailHeaders>
generator.appendChild(self.getXMLMailHeaders(xml))
return xml