Python xml.dom.minidom.Text() Examples

The following are 30 code examples of xml.dom.minidom.Text(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xml.dom.minidom , or try the search function .
Example #1
Source File: expatbuilder.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #2
Source File: expatbuilder.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #3
Source File: expatbuilder.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #4
Source File: distrib.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def render_GET(self, request):
        """
        Render as HTML a listing of all known users with links to their
        personal resources.
        """
        listing = Element('ul')
        for link, text in self._users():
            linkElement = Element('a')
            linkElement.setAttribute('href', link + '/')
            textNode = Text()
            textNode.data = text
            linkElement.appendChild(textNode)
            item = Element('li')
            item.appendChild(linkElement)
            listing.appendChild(item)
        return self.template % {'users': listing.toxml()} 
Example #5
Source File: slides.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def insertPrevNextLinks(slides, filename, ext):
    for slide in slides:
        for name, offset in (("previous", -1), ("next", +1)):
            if (slide.pos > 0 and name == "previous") or \
               (slide.pos < len(slides)-1 and name == "next"):
                for node in domhelpers.findElementsWithAttribute(slide.dom, "class", name):
                    if node.tagName == 'a':
                        node.setAttribute('href', '%s-%d%s'
                                          % (filename[0], slide.pos+offset, ext))
                    else:
                        text = dom.Text()
                        text.data = slides[slide.pos+offset].title
                        node.appendChild(text)
            else:
                for node in domhelpers.findElementsWithAttribute(slide.dom, "class", name):
                    pos = 0
                    for child in node.parentNode.childNodes:
                        if child is node:
                            del node.parentNode.childNodes[pos]
                            break
                        pos += 1 
Example #6
Source File: tree.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def addMtime(document, fullpath):
    """
    Set the last modified time of the given document.

    @type document: A DOM Node or Document
    @param document: The output template which defines the presentation of the
    last modified time.

    @type fullpath: C{str}
    @param fullpath: The file name from which to take the last modified time.

    @return: C{None}
    """
    for node in domhelpers.findElementsWithAttribute(document, "class","mtime"):
        txt = dom.Text()
        txt.data = time.ctime(os.path.getmtime(fullpath))
        node.appendChild(txt) 
Example #7
Source File: tree.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def _makeLineNumbers(howMany):
    """
    Return an element which will render line numbers for a source listing.

    @param howMany: The number of lines in the source listing.
    @type howMany: C{int}

    @return: An L{dom.Element} which can be added to the document before
        the source listing to add line numbers to it.
    """
    # Figure out how many digits wide the widest line number label will be.
    width = len(str(howMany))

    # Render all the line labels with appropriate padding
    labels = ['%*d' % (width, i) for i in range(1, howMany + 1)]

    # Create a p element with the right style containing the labels
    p = dom.Element('p')
    p.setAttribute('class', 'py-linenumber')
    t = dom.Text()
    t.data = '\n'.join(labels) + '\n'
    p.appendChild(t)
    return p 
Example #8
Source File: expatbuilder.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #9
Source File: tree.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def setVersion(template, version):
    """
    Add a version indicator to the given template.

    @type template: A DOM Node or Document
    @param template: The output template which defines the presentation of the
    version information.

    @type version: C{str}
    @param version: The version string to add to the template.

    @return: C{None}
    """
    for node in domhelpers.findElementsWithAttribute(template, "class",
                                                               "version"):
        text = dom.Text()
        text.data = version
        node.appendChild(text) 
Example #10
Source File: expatbuilder.py    From jawfish with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #11
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_setTitle(self):
        """
        L{tree.setTitle} inserts the given title into the first I{title}
        element and the first element with the I{title} class in the given
        template.
        """
        parent = dom.Element('div')
        firstTitle = dom.Element('title')
        parent.appendChild(firstTitle)
        secondTitle = dom.Element('span')
        secondTitle.setAttribute('class', 'title')
        parent.appendChild(secondTitle)

        titleNodes = [dom.Text()]
        # minidom has issues with cloning documentless-nodes.  See Python issue
        # 4851.
        titleNodes[0].ownerDocument = dom.Document()
        titleNodes[0].data = 'foo bar'

        tree.setTitle(parent, titleNodes, None)
        self.assertEqual(firstTitle.toxml(), '<title>foo bar</title>')
        self.assertEqual(
            secondTitle.toxml(), '<span class="title">foo bar</span>') 
Example #12
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_setTitleWithChapter(self):
        """
        L{tree.setTitle} includes a chapter number if it is passed one.
        """
        document = dom.Document()

        parent = dom.Element('div')
        parent.ownerDocument = document

        title = dom.Element('title')
        parent.appendChild(title)

        titleNodes = [dom.Text()]
        titleNodes[0].ownerDocument = document
        titleNodes[0].data = 'foo bar'

        # Oh yea.  The numberer has to agree to put the chapter number in, too.
        numberer.setNumberSections(True)

        tree.setTitle(parent, titleNodes, '13')
        self.assertEqual(title.toxml(), '<title>13. foo bar</title>') 
Example #13
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_makeLineNumbers(self):
        """
        L{tree._makeLineNumbers} takes an integer and returns a I{p} tag with
        that number of line numbers in it.
        """
        numbers = tree._makeLineNumbers(1)
        self.assertEqual(numbers.tagName, 'p')
        self.assertEqual(numbers.getAttribute('class'), 'py-linenumber')
        self.assertIsInstance(numbers.firstChild, dom.Text)
        self.assertEqual(numbers.firstChild.nodeValue, '1\n')

        numbers = tree._makeLineNumbers(10)
        self.assertEqual(numbers.tagName, 'p')
        self.assertEqual(numbers.getAttribute('class'), 'py-linenumber')
        self.assertIsInstance(numbers.firstChild, dom.Text)
        self.assertEqual(
            numbers.firstChild.nodeValue,
            ' 1\n 2\n 3\n 4\n 5\n'
            ' 6\n 7\n 8\n 9\n10\n') 
Example #14
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_fontifyPythonNode(self):
        """
        L{tree.fontifyPythonNode} accepts a text node and replaces it in its
        parent with a syntax colored and line numbered version of the Python
        source it contains.
        """
        parent = dom.Element('div')
        source = dom.Text()
        source.data = 'def foo():\n    pass\n'
        parent.appendChild(source)

        tree.fontifyPythonNode(source)

        expected = """\
<div><pre class="python"><p class="py-linenumber">1
2
</p><span class="py-src-keyword">def</span> <span class="py-src-identifier">foo</span>():
    <span class="py-src-keyword">pass</span>
</pre></div>"""

        self.assertEqual(parent.toxml(), expected) 
Example #15
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_fixAPI(self):
        """
        The element passed to L{tree.fixAPI} has all of its children with the
        I{API} class rewritten to contain links to the API which is referred to
        by the text they contain.
        """
        parent = dom.Element('div')
        link = dom.Element('span')
        link.setAttribute('class', 'API')
        text = dom.Text()
        text.data = 'foo'
        link.appendChild(text)
        parent.appendChild(link)

        tree.fixAPI(parent, 'http://example.com/%s')
        self.assertEqual(
            parent.toxml(),
            '<div><span class="API">'
            '<a href="http://example.com/foo" title="foo">foo</a>'
            '</span></div>') 
Example #16
Source File: test_docbook.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_li(self):
        """
        L{DocbookSpitter} wraps any non-I{p} elements found intside any I{li}
        elements with I{p} elements.
        """
        output = []
        spitter = DocbookSpitter(output.append)

        li = Element('li')
        li.appendChild(Element('p'))
        text = Text()
        text.data = 'foo bar'
        li.appendChild(text)

        spitter.visitNode(li)
        self.assertEqual(
            ''.join(output),
            '<listitem><para></para><para>foo bar</para></listitem>') 
Example #17
Source File: test_lore.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_nonASCIIData(self):
        """
        A document which contains non-ascii characters is serialized to a
        file using UTF-8.
        """
        document = dom.Document()
        parent = dom.Element('foo')
        text = dom.Text()
        text.data = u'\N{SNOWMAN}'
        parent.appendChild(text)
        document.appendChild(parent)
        outFile = self.mktemp()
        tree._writeDocument(outFile, document)
        self.assertXMLEqual(
            FilePath(outFile).getContent(),
            u'<foo>\N{SNOWMAN}</foo>'.encode('utf-8')) 
Example #18
Source File: expatbuilder.py    From Imogen with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #19
Source File: expatbuilder.py    From PokemonGo-DesktopMap with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #20
Source File: expatbuilder.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #21
Source File: expatbuilder.py    From unity-python with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #22
Source File: expatbuilder.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #23
Source File: expatbuilder.py    From BinderFilter with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #24
Source File: expatbuilder.py    From pmatic with GNU General Public License v2.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #25
Source File: expatbuilder.py    From android_universal with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            node.data = value
            return
        else:
            node = minidom.Text()
            node.data = data
            node.ownerDocument = self.document
        _append_child(self.curNode, node) 
Example #26
Source File: expatbuilder.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #27
Source File: expatbuilder.py    From Computable with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #28
Source File: expatbuilder.py    From oss-ftp with MIT License 6 votes vote down vote up
def character_data_handler_cdata(self, data):
        childNodes = self.curNode.childNodes
        if self._cdata:
            if (  self._cdata_continue
                  and childNodes[-1].nodeType == CDATA_SECTION_NODE):
                childNodes[-1].appendData(data)
                return
            node = self.document.createCDATASection(data)
            self._cdata_continue = True
        elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            value = node.data + data
            d = node.__dict__
            d['data'] = d['nodeValue'] = value
            return
        else:
            node = minidom.Text()
            d = node.__dict__
            d['data'] = d['nodeValue'] = data
            d['ownerDocument'] = self.document
        _append_child(self.curNode, node) 
Example #29
Source File: test_lore.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_numberDocument(self):
        """
        L{tree.numberDocument} inserts section numbers into the text of each
        header.
        """
        parent = dom.Element('foo')
        section = dom.Element('h2')
        text = dom.Text()
        text.data = 'foo'
        section.appendChild(text)
        parent.appendChild(section)

        tree.numberDocument(parent, '7')

        self.assertEqual(section.toxml(), '<h2>7.1 foo</h2>') 
Example #30
Source File: expatbuilder.py    From jawfish with MIT License 5 votes vote down vote up
def character_data_handler(self, data):
        childNodes = self.curNode.childNodes
        if childNodes and childNodes[-1].nodeType == TEXT_NODE:
            node = childNodes[-1]
            node.data = node.data + data
            return
        node = minidom.Text()
        node.data = node.data + data
        node.ownerDocument = self.document
        _append_child(self.curNode, node)