twisted.web.microdom.parseString - python examples

Here are the examples of the python api twisted.web.microdom.parseString taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

85 Examples 7

3 View Complete Implementation : nevowlore.py
Copyright MIT License
Author : adde88
def parseStringAndReport(s):
    try:
        return microdom.parseString(s)
    except microdom.MismatchedTags, e:
        raise process.ProcessingFailure(
              "%s:%s: begin mismatched tags <%s>/</%s>" %
               (e.begLine, e.begCol, e.got, e.expect),
              "%s:%s: end mismatched tags <%s>/</%s>" %
               (e.endLine, e.endCol, e.got, e.expect))
    except microdom.ParseError, e:
        raise process.ProcessingFailure("%s:%s:%s" % (e.line, e.col, e.message))
    except IOError, e:
        raise process.ProcessingFailure(e.strerror)

3 View Complete Implementation : marmalade.py
Copyright MIT License
Author : adde88
def unjellyFromXML(stringOrFile):
    """I convert a string or the contents of an XML file into a Python object.
    """
    if hasattr(stringOrFile, "read"):
        docameent = parse(stringOrFile)
    else:
        docameent = parseString(stringOrFile)
    return unjellyFromDOM(docameent)

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_get(self):
        doc1=microdom.parseString('<a><b id="bar"/><c clast="foo"/></a>')
        node=domhelpers.get(doc1, "foo")
        actual=node.toxml()
        expected='<c clast="foo"></c>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

        node=domhelpers.get(doc1, "bar")
        actual=node.toxml()
        expected='<b id="bar"></b>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

        self.astertRaises(domhelpers.NodeLookupError, 
                          domhelpers.get, 
                          doc1, 
                          "pzork")

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_getIfExists(self):
        doc1=microdom.parseString('<a><b id="bar"/><c clast="foo"/></a>')
        node=domhelpers.getIfExists(doc1, "foo")
        actual=node.toxml()
        expected='<c clast="foo"></c>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

        node=domhelpers.getIfExists(doc1, "pzork")
        astert node==None, 'expected None, didn\'t get None'

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_getAndClear(self):
        doc1=microdom.parseString('<a><b id="foo"><c></c></b></a>')
        node=domhelpers.getAndClear(doc1, "foo")
        actual=node.toxml()
        expected='<b id="foo"></b>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_locateNodes(self):
        doc1=microdom.parseString('<a><b foo="olive"><c foo="olive"/></b><d foo="poopy"/></a>')
        node_list=domhelpers.locateNodes(doc1.childNodes, 'foo', 'olive',
                                         noNesting=1)
        actual=''.join([node.toxml() for node in node_list])
        expected='<b foo="olive"><c foo="olive"></c></b>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

        node_list=domhelpers.locateNodes(doc1.childNodes, 'foo', 'olive',
                                         noNesting=0)
        actual=''.join([node.toxml() for node in node_list])
        expected='<b foo="olive"><c foo="olive"></c></b><c foo="olive"></c>'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_getParents(self):
        doc1=microdom.parseString('<a><b><c><d/></c><e/></b><f/></a>')
        node_list=domhelpers.getParents(doc1.childNodes[0].childNodes[0].childNodes[0])
        actual=''.join([node.tagName for node in node_list
                        if hasattr(node, 'tagName')])
        expected='cba'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_findElementsWithAttribute(self):
        doc1=microdom.parseString('<a foo="1"><b foo="2"/><c foo="1"/><d/></a>')
        node_list=domhelpers.findElementsWithAttribute(doc1, 'foo')
        actual=''.join([node.tagName for node in node_list])
        expected='abc'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

        node_list=domhelpers.findElementsWithAttribute(doc1, 'foo', '1')
        actual=''.join([node.tagName for node in node_list])
        expected='ac'
        astert actual==expected, 'expected %s, got %s' % (expected, actual)

3 View Complete Implementation : test_domhelpers.py
Copyright MIT License
Author : adde88
    def test_findNodesNamed(self):
        doc1=microdom.parseString('<doc><foo/><bar/><foo>a</foo></doc>')
        node_list=domhelpers.findNodesNamed(doc1, 'foo')
        actual=len(node_list)
        expected=2
        astert actual==expected, 'expected %d, got %d' % (expected, actual)

3 View Complete Implementation : test_woven.py
Copyright MIT License
Author : adde88
    def setUp(self):
        self.m = self.modelFactory()
        self.t = self.resourceFactory(self.m)
        self.r = test_web.DummyRequest([''])
        self.r.prepath = ['']
        self.prerender()
        self.t.render(self.r)
        
        self.channel = "a fake channel"
        self.output = ''.join(self.r.written)
        astert self.output, "No output was generated by the test."
        global outputNum
        open("wovenTestOutput%s.html" % (outputNum + 1), 'w').write(self.output)
        outputNum += 1
        self.d = microdom.parseString(self.output)