本文整理汇总了Python中cia.LibCIA.XML.createRootNode方法的典型用法代码示例。如果您正苦于以下问题:Python XML.createRootNode方法的具体用法?Python XML.createRootNode怎么用?Python XML.createRootNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cia.LibCIA.XML
的用法示例。
在下文中一共展示了XML.createRootNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import createRootNode [as 别名]
def parse(self, message):
"""Given a string of text in the original CIA commit format, return a <colorText>
element representing it as a DOM tree.
"""
# Initialize our model of the current text format in the original message
self.parsedState = ColorState()
self.document = XML.createRootNode()
# Initialize our stack of (element, ColorState) tuples representing
# the state of the XML document being generated. This starts out with
# our root element in it.
self.elementStack = [
(XML.addElement(self.document, "colorText"), ColorState())
]
# Break up the message into lines, each with its whitespace stripped.
# Run our lexical scanner on each line separately, turning it into
# a stream of events. Insert <br/> tags between lines.
lines = []
for line in message.split("\n"):
# Ignore extra whitespace
line = line.strip()
# Ignore blank lines
if line:
lines.append(line)
for i in xrange(len(lines)):
if i != 0:
XML.addElement(self.elementStack[-1][0], 'br')
self.lex(lines[i])
self.closeTags()
return self.document
示例2: command_Announce
# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import createRootNode [as 别名]
def command_Announce(self, project):
"""Old-style announcements: Announce <project> in the subject line.
The body of the email contained the message's text, marked up
with {color} tags but with no metadata.
"""
xml = XML.createRootNode()
# Convert the given project name to a <project> tag inside <source>,
# after filtering it a bit... in the old CIA project names and IRC channel
# names weren't particularly distinct, so preceeding "#" characters on
# projects were ignored. We preserve this behaviour.
if project[0] == "#":
project = project[1:]
XML.buryValue(xml, project, "message", "source", "project")
# Since old-style commits didn't have any metadata, the best we can do
# is to represent the log in a <colorText> element
colorText = ColorTextParser().parse(self.message.get_payload()).documentElement
XML.bury(xml, "message", "body").appendChild(xml.importNode(colorText, True))
return xml