当前位置: 首页>>代码示例>>Python>>正文


Python XML.addElement方法代码示例

本文整理汇总了Python中cia.LibCIA.XML.addElement方法的典型用法代码示例。如果您正苦于以下问题:Python XML.addElement方法的具体用法?Python XML.addElement怎么用?Python XML.addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cia.LibCIA.XML的用法示例。


在下文中一共展示了XML.addElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import addElement [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
开发者ID:Justasic,项目名称:cia-vc,代码行数:35,代码来源:ColorText.py

示例2: preprocess

# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import addElement [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())
开发者ID:Justasic,项目名称:cia-vc,代码行数:10,代码来源:Message.py

示例3: getXMLMailHeaders

# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import addElement [as 别名]
 def getXMLMailHeaders(self, document):
     """Return a <mailHeaders> tag representing a subset of the headers
        for this message. This is placed in the <generator> tag of any
        message passing through this module, to document and log the
        message's true source.
        """
     node = document.createElementNS(None, "mailHeaders")
     for name, value in self.message.items():
         if name in interestingHeaders:
             XML.addElement(node, "header", content=str(value)).setAttributeNS(None, 'name', name)
     return node
开发者ID:Justasic,项目名称:cia-vc,代码行数:13,代码来源:IncomingMail.py

示例4: pushTag

# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import addElement [as 别名]
    def pushTag(self, name, attributes={}, stateChanges={}):
        """Add a new element to the elementStack, placed at
           the end of the children list for the tag currently
           at the top of the stack.

           name:         The name of the new element
           attributes:   A dict of attributes to set on the new element
           stateChanges: A dict of attributes to change in the new tag's state
           """
        oldTag, oldState = self.elementStack[-1]

        newTag = XML.addElement(self.elementStack[-1][0], name)
        for key, value in attributes.iteritems():
            newTag.setAttributeNS(None, key, value)

        newState = copy.deepcopy(oldState)
        newState.__dict__.update(stateChanges)

        self.elementStack.append((newTag, newState))
开发者ID:Justasic,项目名称:cia-vc,代码行数:21,代码来源:ColorText.py

示例5: getLocalGenerator

# 需要导入模块: from cia.LibCIA import XML [as 别名]
# 或者: from cia.LibCIA.XML import addElement [as 别名]
 def getLocalGenerator(self, document):
     """Return a <generator> tag for messages produced locally"""
     node = document.createElementNS(None, "generator")
     XML.addElement(node, "name", content="CIA IncomingMailParser")
     return node
开发者ID:Justasic,项目名称:cia-vc,代码行数:7,代码来源:IncomingMail.py


注:本文中的cia.LibCIA.XML.addElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。