本文整理汇总了Python中cia.LibCIA.XML.shallowText方法的典型用法代码示例。如果您正苦于以下问题:Python XML.shallowText方法的具体用法?Python XML.shallowText怎么用?Python XML.shallowText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cia.LibCIA.XML
的用法示例。
在下文中一共展示了XML.shallowText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: component_headers
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def component_headers(self, element, args):
"""Format all relevant commit metadata in an email-style header box"""
message = args.message
commit = XML.dig(message.xml, "message", "body", "commit")
source = XML.dig(message.xml, "message", "source")
author = XML.dig(commit, "author")
version = XML.dig(commit, "version")
revision = XML.dig(commit, "revision")
diffLines = XML.dig(commit, "diffLines")
url = XML.dig(commit, "url")
log = XML.dig(commit, "log")
project = XML.dig(source, "project")
module = XML.dig(source, "module")
branch = XML.dig(source, "branch")
headers = OrderedDict()
if author:
headers['Author'] = XML.shallowText(author)
if project:
headers['Project'] = XML.shallowText(project)
if module:
headers['Module'] = XML.shallowText(module)
if branch:
headers['Branch'] = XML.shallowText(branch)
if version:
headers['Version'] = XML.shallowText(version)
if revision:
headers['Revision'] = XML.shallowText(revision)
if diffLines:
headers['Changed Lines'] = XML.shallowText(diffLines)
if url:
headers['URL'] = tag('a', href=XML.shallowText(url))[ Util.extractSummary(url) ]
return [Template.MessageHeaders(headers)]
示例2: component_files
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def component_files(self, element, args):
"""Format the contents of our <files> tag as a tree with nested lists"""
from cia.LibCIA.Web import Template
files = XML.dig(args.message.xml, "message", "body", "commit", "files")
if not (files and XML.hasChildElements(files)):
return []
# First we organize the files into a tree of nested dictionaries.
# The dictionary we ultimately have FileTree render maps each node
# (file or directory) to a dictionary of its contents. The keys
# in these dictionaries can be any Nouvelle-renderable object
# produced by format_file.
#
# As a first step, we build a dictionary mapping path segment to
# [fileTag, children] lists. We then create a visual representation
# of each fileTag and generate the final dictionary.
fileTree = {}
for fileTag in XML.getChildElements(files):
if fileTag.nodeName == 'file':
# Separate the file into path segments and walk into our tree
node = [None, fileTree]
for segment in XML.shallowText(fileTag).split('/'):
if segment:
node = node[1].setdefault(segment, [None, {}])
# The leaf node owns this fileTag
node[0] = fileTag
return [Template.FileTree(self.format_file_tree(fileTree))]
示例3: consolidateFiles
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def consolidateFiles(self, xmlFiles):
"""Given a <files> element, find the directory common to all files
and return a 2-tuple with that directory followed by
a list of files within that directory.
"""
files = []
if xmlFiles:
for fileTag in XML.getChildElements(xmlFiles):
if fileTag.nodeName == 'file':
files.append(XML.shallowText(fileTag))
# If we only have one file, return it as the prefix.
# This prevents the below regex from deleting the filename
# itself, assuming it was a partial filename.
if len(files) == 1:
return files[0], []
# Start with the prefix found by commonprefix,
# then actually make it end with a directory rather than
# possibly ending with part of a filename.
prefix = re.sub("[^/]*$", "", posixpath.commonprefix(files))
endings = []
for file in files:
ending = file[len(prefix):].strip()
if ending == '':
ending = '.'
endings.append(ending)
return prefix, endings
示例4: element_like
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.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'))
示例5: matches
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.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
示例6: textComponent
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.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()]
示例7: format
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def format(self, args):
if not args.input:
return
project = XML.dig(args.message.xml, "message", "source", "project")
if project:
from cia.LibCIA.IRC.Formatting import format
prefix = format("%s:" % XML.shallowText(project), 'bold') + " "
return "\n".join([prefix + line for line in args.input.split("\n")])
else:
return args.input
示例8: component_text
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.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()]
示例9: pathMatchTag
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.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
示例10: getNormalizedLog
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def getNormalizedLog(xml, tabWidth=8):
"""Given the DOM node for a <log> tag, return a list of
text lines with whitespace normalized appropriately.
This strips all whitespace from the right side, and homogeneously
strips whitespace from the left side as much as possible.
Leading and trailing blank lines are removed, but internal
blank lines are not.
"""
if not xml:
return []
lines = []
maxLeftStrip = None
for line in XML.shallowText(xml).split("\n"):
# Expand tabs and strip righthand whitespace
line = line.replace("\t", " "*tabWidth).rstrip()
strippedLine = line.lstrip()
# Blank lines don't count in determining the left strip amount
if strippedLine:
# Determine how much we can strip from the left side
leftStrip = len(line) - len(strippedLine)
# Determine the maximum amount of space we can strip
# from the left side homogeneously across the whole text
if maxLeftStrip is None or leftStrip < maxLeftStrip:
maxLeftStrip = leftStrip
# Skip leading blank lines
if lines or strippedLine:
lines.append(line)
# Remove trailing blank lines
while lines and not lines[-1].strip():
del lines[-1]
# Homogeneous left strip
if maxLeftStrip is None:
return lines
else:
return [line[maxLeftStrip:] for line in lines]
示例11: getCrunchedLog
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def getCrunchedLog(xml):
"""Given the DOM node for a <log> tag, return the log as
a string with all groups of one or more whitespace
characters replaced with a single space.
"""
return re.sub("\s+", " ", XML.shallowText(xml)).strip()
示例12: param_widthLimit
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def param_widthLimit(self, tag):
self.widthLimit = int(XML.shallowText(tag))
if self.wrapWidth > self.widthLimit:
self.wrapWidth = self.widthLimit
示例13: loadParametersFrom
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def loadParametersFrom(self, xml):
self.formattingCode = XML.shallowText(xml).strip()
示例14: rulesetReturn
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def rulesetReturn(msg):
self.result = XML.shallowText(element)
if not self.result:
self.result = None
raise RulesetReturnException()
示例15: component_url
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import shallowText [as 别名]
def component_url(self, element, args):
element = XML.dig(args.message.xml, "message", "body", "commit", "url")
if element:
return [tag('a', href=XML.shallowText(element))[ 'link' ]]
else:
return [Message.MarkAsHidden()]