本文整理汇总了Python中XML.shallowText方法的典型用法代码示例。如果您正苦于以下问题:Python XML.shallowText方法的具体用法?Python XML.shallowText怎么用?Python XML.shallowText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML.shallowText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: element_like
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def element_like(self, element):
"""Compare a given variable to the element's content using SQL's 'LIKE' operator,
not including leading and trailing whitespace. This is case-insensitive, and includes
the '%' wildcard which may be placed at the beginning or end of the string.
"""
return "(%s LIKE %s)" % (self.varLookup(element.getAttributeNS(None, 'var')),
quote(XML.shallowText(element).strip(), 'varchar'))
示例2: matches
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def matches(self, msg):
match = self.projectPath.queryObject(msg)
if match:
for node in match:
project = XML.shallowText(node)
if (project.strip().lower() in self.projects):
return True
return False
示例3: textComponent
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [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()]
示例4: component_text
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def component_text(self, element, args):
"""This is a generic version of textComponent, in which 'path' can
be specified by users. Any textComponent can be rewritten as a
<text> component.
"""
path = element.getAttributeNS(None, 'path')
if not path:
raise XML.XMLValidityError("The 'path' attribute on <text> is required.")
xp = XML.XPath(XML.pathShortcuts.get(path, path))
nodes = xp.queryObject(args.message)
if nodes:
return [XML.shallowText(nodes[0])]
else:
return [MarkAsHidden()]
示例5: pathMatchTag
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def pathMatchTag(self, element, function, textExtractor=XML.shallowText):
"""Implements the logic common to all tags that test the text matched by
an XPath against the text inside our element. The given function is used
to determine if the text matches. This implements the properties common to
several elements:
- The caseSensitive attribute defaults to 1, but can be set to zero
to force both strings to lowercase.
- Each XPath match is tested separately, with 'or' semantics:
if any of the XPath matches cause the provided function to match,
this returns True
- If there are no XPath matches, returns False
"""
path = element.getAttributeNS(None, 'path')
xp = XML.XPath(XML.pathShortcuts.get(path, path))
# Are we doing a case sensitive match? Default is no.
caseSensitive = element.getAttributeNS(None, 'caseSensitive')
if caseSensitive:
caseSensitive = int(caseSensitive)
else:
caseSensitive = 0
text = XML.shallowText(element).strip()
if not caseSensitive:
text = text.lower()
def filterMatch(msg):
# Use queryobject then str() so that matched
# nodes without any text still give us at least
# the empty string. This is important so that <find>
# with an empty search string can be used to test
# for the existence of an XPath match.
nodes = xp.queryObject(msg)
if nodes:
matchStrings = map(textExtractor, nodes)
# Any of the XPath matches can make our match true
for matchString in matchStrings:
matchString = matchString.strip()
if not caseSensitive:
matchString = matchString.lower()
if function(matchString, text):
return True
return False
return filterMatch
示例6: rulesetReturn
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def rulesetReturn(msg):
self.result = XML.shallowText(element)
if not self.result:
self.result = None
raise RulesetReturnException()
示例7: element_match
# 需要导入模块: import XML [as 别名]
# 或者: from XML import shallowText [as 别名]
def element_match(self, element):
"""Compare a given variable exactly to the element's content, not including
leading and trailing whitespace.
"""
return "(%s = %s)" % (self.varLookup(element.getAttributeNS(None, 'var')),
quote(XML.shallowText(element).strip(), 'varchar'))