Exemplo n.º 1
0
def test(tester):

    tester.startGroup('CDATASection')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import CDATASection
        from xml.dom.CDATASection import CDATASection
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    cds = doc.createCDATASection("This is a CDATA Section")
    cds.data="This is a CDATA Section"
    tester.testDone()


    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    cds1 = cds.cloneNode(1)

    if cds1.data != cds.data:
        tester.error("cloneNode does not copy data")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 2
0
def test(tester):

    tester.startGroup('CDATASection')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import CDATASection
        from xml.dom.CDATASection import CDATASection
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    cds = doc.createCDATASection("This is a CDATA Section")
    cds.data = "This is a CDATA Section"
    tester.testDone()

    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    cds1 = cds.cloneNode(1)

    if cds1.data != cds.data:
        tester.error("cloneNode does not copy data")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 3
0
def test(tester):
    tester.startGroup('DocumentFragment')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import DocumentFragment
        from xml.dom.DocumentFragment import DocumentFragment
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    df = doc.createDocumentFragment()
    tester.testDone()


    tester.startTest('Testing cloneNode()')
    df1 = df.cloneNode(1)
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 4
0
def test(tester):

    tester.startGroup('Comment')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Comment
        from xml.dom.Comment import Comment
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    c = doc.createComment("Comment")
    tester.testDone()

    tester.startTest('Test cloneNode()')
    c1 = c.cloneNode(1)
    if c1.data != c.data:
        tester.error("cloneNode does not copy data")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 5
0
 def _initRootNode(self, docElementUri, docElementName):
     if not self._dt:
         self._dt = implementation.createDocumentType(
             docElementName, '', '')
     self._ownerDoc = implementation.createDocument(docElementUri,
                                                    docElementName,
                                                    self._dt)
     before_doctype = 1
     for o_node in self._orphanedNodes:
         if o_node[0] == 'pi':
             pi = self._ownerDoc.createProcessingInstruction(
                 o_node[1], o_node[2])
             if before_doctype:
                 self._ownerDoc.insertBefore(pi, self._dt)
             else:
                 self._ownerDoc.appendChild(pi)
         elif o_node[0] == 'comment':
             comment = self._ownerDoc.createComment(o_node[1])
             if before_doctype:
                 self._ownerDoc.insertBefore(comment, self._dt)
             else:
                 self._ownerDoc.appendChild(comment)
         elif o_node[0] == 'doctype':
             before_doctype = 0
     self._rootNode = self._ownerDoc
     self._nodeStack.append(self._rootNode)
     return
Exemplo n.º 6
0
def test(tester):

    tester.startGroup('EntityReference')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import EntityReference
        from xml.dom.EntityReference import EntityReference
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    entr = doc.createEntityReference("TestEntity")
    tester.testDone()

    tester.startTest('Test cloneNode()')
    entr1 = entr.cloneNode(1)
    if entr1.nodeName != entr.nodeName:
        tester.error("cloneNode failed")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 7
0
def getAkregatorXml(feed_dict):
  # Create an empty DOM tree
  akregator_xml_type = implementation.createDocumentType("AkregatorXML", None, None)
  opml_doc = implementation.createDocument(EMPTY_NAMESPACE, "opml", akregator_xml_type)
  # Get the xml document root
  opml_root = opml_doc.documentElement

  # Create the opml container and body
  opml_root.setAttribute("version", "1.0")
  body = opml_doc.createElement("body")

  # Create a group for each category
  for category in feed_dict.keys():
    group = opml_doc.createElement("outline")
    group.setAttribute("isOpen", "true")
    group.setAttribute("text", category)
    # Transform each feed to XML
    for feed in feed_dict[category]:
      xml_feed = opml_doc.createElement("outline")
      xml_feed.setAttribute("xmlUrl", feed['url'])
      xml_feed.setAttribute("text", feed['name'])
      group.appendChild(xml_feed)
    # Save the group in the body
    body.appendChild(group)

  # Put the main container at the top of the DOM tree
  opml_root.appendChild(body)

  return opml_root
Exemplo n.º 8
0
def test(tester):

    tester.startGroup('Comment')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Comment
        from xml.dom.Comment import Comment
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)
    c = doc.createComment("Comment")
    tester.testDone()

    tester.startTest('Test cloneNode()')
    c1 = c.cloneNode(1)
    if c1.data != c.data:
        tester.error("cloneNode does not copy data")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 9
0
def test(tester):

    tester.startGroup('EntityReference')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import EntityReference
        from xml.dom.EntityReference import EntityReference
    except:
        tester.error('Error in syntax',1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    entr = doc.createEntityReference("TestEntity")
    tester.testDone()

    tester.startTest('Test cloneNode()')
    entr1 = entr.cloneNode(1)
    if entr1.nodeName != entr.nodeName:
        tester.error("cloneNode failed")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 10
0
def test(tester):

    tester.startGroup('Text')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Text
        from xml.dom.Text import Text
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    t = doc.createTextNode("ONETWO")
    tester.testDone()


    tester.startTest('Testing splitText()')
    t2 = t.splitText(3)
    if t.data != 'ONE':
        tester.error('splitText did not properly split first half')
    if t2.data != 'TWO':
        tester.error('splitText did not properly split second half')
    try:
        t.splitText(100)
    except DOMException, x:
        if x.code != INDEX_SIZE_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected INDEX_SIZE_ERR" % name)
Exemplo n.º 11
0
 def startDTD(self, doctype, publicID, systemID):
     if not self._rootNode:
         self._dt = implementation.createDocumentType(doctype, publicID, systemID)
         self._orphanedNodes.append(('doctype'))
     else:
         raise 'Illegal DocType declaration'
     return
Exemplo n.º 12
0
 def _initRootNode(self, docElementUri, docElementName):
     if not self._dt:
         self._dt = implementation.createDocumentType(docElementName,'','')
     self._ownerDoc = implementation.createDocument(docElementUri, docElementName, self._dt)
     before_doctype = 1
     for o_node in self._orphanedNodes:
         if o_node[0] == 'pi':
             pi = self._ownerDoc.createProcessingInstruction(
                 o_node[1],
                 o_node[2]
                 )
             if before_doctype:
                 self._ownerDoc.insertBefore(pi, self._dt)
             else:
                 self._ownerDoc.appendChild(pi)
         elif o_node[0] == 'comment':
             comment = self._ownerDoc.createComment(o_node[1])
             if before_doctype:
                 self._ownerDoc.insertBefore(comment, self._dt)
             else:
                 self._ownerDoc.appendChild(comment)
         elif o_node[0] == 'doctype':
             before_doctype = 0
     self._rootNode = self._ownerDoc
     self._nodeStack.append(self._rootNode)
     return
Exemplo n.º 13
0
def test(tester):

    tester.startGroup('ProcessingInstruction')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import ProcessingInstruction
        from xml.dom.ProcessingInstruction import ProcessingInstruction
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)
    pi = doc.createProcessingInstruction("xml", 'version = "1.0"')
    tester.testDone()

    tester.startTest('Testing attributes')
    if pi.target != 'xml':
        tester.error('Problems with target')
    if pi.data != 'version = "1.0"':
        tester.error('Problems with data')
    tester.testDone()

    tester.startTest('Test cloneNode()')
    pi1 = pi.cloneNode(1)
    if pi1.target != pi.target:
        tester.error("cloneNode fails on target")
    if pi1.data != pi.data:
        tester.error("cloneNode fails on data")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 14
0
def test(tester):

    tester.startGroup('Text')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Text
        from xml.dom.Text import Text
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    t = doc.createTextNode("ONETWO")
    tester.testDone()

    tester.startTest('Testing splitText()')
    t2 = t.splitText(3)
    if t.data != 'ONE':
        tester.error('splitText did not properly split first half')
    if t2.data != 'TWO':
        tester.error('splitText did not properly split second half')
    try:
        t.splitText(100)
    except DOMException, x:
        if x.code != INDEX_SIZE_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected INDEX_SIZE_ERR" %
                         name)
Exemplo n.º 15
0
 def startDTD(self, doctype, publicID, systemID):
     if not self._rootNode:
         self._dt = implementation.createDocumentType(
             doctype, publicID, systemID)
         self._orphanedNodes.append(('doctype'))
     else:
         raise 'Illegal DocType declaration'
     return
Exemplo n.º 16
0
def test(tester):

    tester.startGroup('Attr')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import Attr
        from xml.dom.Attr import Attr
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    try:
        from xml.dom import implementation
        dt = implementation.createDocumentType('','','')
        doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    except:
        tester.error('Error creating document')

    a = doc.createAttribute('TestNode');
    e = doc.createElement('TestElement')
    tester.testDone()


    tester.startTest('Testing attributes')
    if a.name != 'TestNode':
        tester.error("name failed")
    if a.specified != 0:
        tester.error("specified failed")
    a.value = 'Test Value'
    if a.value != 'Test Value':
        tester.error("Error getting/seeting value")
    if a.specified != 1:
        tester.error("Assigning to value does not set specified")
    tester.testDone()


    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    a1 = a.cloneNode(1)

    if a1.value != a.value:
        tester.error("cloneNode fails on value")

    if a1.name != a.name:
        tester.error("cloneNode fails on name")

    if a1.specified != a.specified:
        tester.error("cloneNode fails on specified")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 17
0
    def create(self):
        from xml.dom import implementation
        dt = implementation.createDocumentType('','','')
        doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

        #We cannot use just plain old nodes, we need to use Elements
        self.pNode = doc.createElement('PARENT')

        self.nodes = []
        for ctr in range(3):
            n = doc.createElement('Child %d' % ctr)
            self.nodes.append(n);
Exemplo n.º 18
0
def test(tester):

    tester.startGroup('Attr')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import Attr
        from xml.dom.Attr import Attr
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    try:
        from xml.dom import implementation
        dt = implementation.createDocumentType('', '', '')
        doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)
    except:
        tester.error('Error creating document')

    a = doc.createAttribute('TestNode')
    e = doc.createElement('TestElement')
    tester.testDone()

    tester.startTest('Testing attributes')
    if a.name != 'TestNode':
        tester.error("name failed")
    if a.specified != 0:
        tester.error("specified failed")
    a.value = 'Test Value'
    if a.value != 'Test Value':
        tester.error("Error getting/seeting value")
    if a.specified != 1:
        tester.error("Assigning to value does not set specified")
    tester.testDone()

    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    a1 = a.cloneNode(1)

    if a1.value != a.value:
        tester.error("cloneNode fails on value")

    if a1.name != a.name:
        tester.error("cloneNode fails on name")

    if a1.specified != a.specified:
        tester.error("cloneNode fails on specified")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 19
0
def test(tester):
    tester.startGroup('CharacterData')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import CharacterData
        from xml.dom.CharacterData import CharacterData
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    #shouldn't try to instantiate a CharacterData node, so test it through Text
    t1 = doc.createTextNode("")
    t2 = doc.createTextNode('SUBSTRING')
    t3 = doc.createTextNode('APPEND')
    t4 = doc.createTextNode('INSERT')
    t5 = doc.createTextNode('DELETE')
    t6 = doc.createTextNode('TEST')
    tester.testDone()


    tester.startTest('Testing attributes')
    t1.data = 'TEST';
    if t1.data != 'TEST':
        tester.error('Get/set data doesn\'t match')

    if t1.length != 4:
        tester.error('length returned wrong size')
    tester.testDone()


    tester.startTest('Testing substringData()')
    if t2.substringData(1,2) != 'UB':
        tester.error('substringData returns wrong section')
    if t2.substringData(5,100) != 'RING':
        tester.error('substringData fails on oversized \'count\'')
    try:
        t2.substringData(100,2)
    except DOMException, x:
        if x.code != INDEX_SIZE_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected INDEX_SIZE_ERR" % name)
Exemplo n.º 20
0
def test(tester):

    tester.startGroup('NodeList')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import NodeList
        from xml.dom.NodeList import NodeList
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating the test environment')
    try:
        from xml.dom import implementation
        dt = implementation.createDocumentType('', '', '')
        doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)
    except:
        tester.error('Error creating document')

    nodes = []
    try:
        for ctr in range(3):
            nodes.append(doc.createElement('Node%d' % ctr))
    except:
        tester.error("Error creating nodes")

    e = doc.createElement('PARENT')
    try:
        for n in nodes:
            e.appendChild(n)
    except:
        tester.error('Error appending nodes')
    nl = e.childNodes
    tester.testDone()

    tester.startTest("Testing attributes")
    if nl.length != 3:
        tester.error('length reports wrong amount')
    try:
        nl.length = 5
    except DOMException, x:
        if x.code != NO_MODIFICATION_ALLOWED_ERR:
            name = get_exception_name(x.code)
            tester.error(
                "Wrong exception '%s', expected NOMODIFICATION_ALLOWED_ERR" %
                name)
Exemplo n.º 21
0
 def _initRootNode(self, docElementUri, docElementName):
     if not self._dt:
         self._dt = implementation.createDocumentType(docElementName,'','')
     self._ownerDoc = implementation.createDocument(docElementUri, docElementName, self._dt)
     if self._xmlDecl:
         decl_data = 'version="%s"' % (
                 self._xmlDecl['version']
                 )
         if self._xmlDecl['encoding']:
             decl_data = decl_data + ' encoding="%s"'%(
                 self._xmlDecl['encoding']
                 )
         if self._xmlDecl['standalone']:
             decl_data = decl_data + ' standalone="%s"'%(
                 self._xmlDecl['standalone']
                 )
         xml_decl_node = self._ownerDoc.createProcessingInstruction(
             'xml',
             decl_data
             )
         self._ownerDoc.insertBefore(xml_decl_node, self._ownerDoc.docType)
     before_doctype = 1
     for o_node in self._orphanedNodes:
         if o_node[0] == 'pi':
             pi = self._ownerDoc.createProcessingInstruction(
                 o_node[1],
                 o_node[2]
                 )
             if before_doctype:
                 self._ownerDoc.insertBefore(pi, self._dt)
             else:
                 self._ownerDoc.appendChild(pi)
         elif o_node[0] == 'comment':
             comment = self._ownerDoc.createComment(o_node[1])
             if before_doctype:
                 self._ownerDoc.insertBefore(comment, self._dt)
             else:
                 self._ownerDoc.appendChild(comment)
         elif o_node[0] == 'doctype':
             before_doctype = 0
         elif o_node[0] == 'unparsedentitydecl':
             apply(self.unparsedEntityDecl, o_node[1:])
         else:
             raise Exception("Unknown orphaned node:"+o_node[0])
     self._rootNode = self._ownerDoc
     self._nodeStack.append(self._rootNode)
     return
Exemplo n.º 22
0
def test(tester):

    tester.startGroup('NodeList')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import NodeList
        from xml.dom.NodeList import NodeList
    except:
        tester.error('Error in syntax',1)
    tester.testDone()


    tester.startTest('Creating the test environment')
    try:
        from xml.dom import implementation
        dt = implementation.createDocumentType('','','')
        doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    except:
        tester.error('Error creating document')

    nodes = []
    try:
        for ctr in range(3):
            nodes.append(doc.createElement('Node%d' %ctr))
    except:
        tester.error("Error creating nodes")

    e = doc.createElement('PARENT')
    try:
        for n in nodes:
            e.appendChild(n)
    except:
        tester.error('Error appending nodes')
    nl = e.childNodes
    tester.testDone()


    tester.startTest("Testing attributes")
    if nl.length != 3:
        tester.error('length reports wrong amount')
    try:
        nl.length = 5
    except DOMException, x:
        if x.code != NO_MODIFICATION_ALLOWED_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected NOMODIFICATION_ALLOWED_ERR" % name)
Exemplo n.º 23
0
def test(tester):

    tester.startGroup('DocumentType')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import DocumentType
        from xml.dom.DocumentType import DocumentType
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('TEST','PublicID','SystemID')
    tester.testDone()


    tester.startTest('Testing attributes')
    if dt.name != 'TEST':
        tester.error('name is incorrect')
    if dt.publicId != 'PublicID':
        tester.error('publicId is incorrect')
    if dt.systemId != 'SystemID':
        tester.error('systemId is incorrect')
    tester.testDone()


    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    dt1 = dt.cloneNode(1)
    if dt1.name != dt.name:
        tester.error("cloneNode failed on name")
    if dt1.entities.length != dt.entities.length:
        tester.error("cloneNode did not copy all entities")
    if dt1.notations.length != dt.notations.length:
        tester.error("cloneNode did not copy all notations")
    if dt1.publicId != dt.publicId:
        tester.error("cloneNode fails on publicId")
    if dt1.systemId != dt.systemId:
        tester.error("cloneNode fails on systemId")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 24
0
    def initState(self, ownerDoc=None):
        """
        If None is passed in as the doc, set up an empty document to act
        as owner and also add all elements to this document
        """
        if ownerDoc == None:
            dt = implementation.createDocumentType('', '', '')
            self._ownerDoc = implementation.createDocument('', None, dt)
            self._rootNode = self._ownerDoc
        else:
            self._ownerDoc = ownerDoc
            #Create a docfrag to hold all the generated nodes.
            self._rootNode = self._ownerDoc.createDocumentFragment()

        #Set up the stack which keeps track of the nesting of DOM nodes.
        self._nodeStack = []
        self._nodeStack.append(self._rootNode)
        self._currText = ''
        return
Exemplo n.º 25
0
    def initState(self, ownerDoc=None):
        """
        If None is passed in as the doc, set up an empty document to act
        as owner and also add all elements to this document
        """
        if ownerDoc == None:
            dt = implementation.createDocumentType('', '', '')
            self._ownerDoc = implementation.createDocument('', None, dt)
            self._rootNode = self._ownerDoc
        else:
            self._ownerDoc = ownerDoc
            #Create a docfrag to hold all the generated nodes.
            self._rootNode = self._ownerDoc.createDocumentFragment()

        #Set up the stack which keeps track of the nesting of DOM nodes.
        self._nodeStack = []
        self._nodeStack.append(self._rootNode)
        self._currText = ''
        return
Exemplo n.º 26
0
def test(tester):

    tester.startGroup('DocumentType')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import DocumentType
        from xml.dom.DocumentType import DocumentType
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('TEST', 'PublicID', 'SystemID')
    tester.testDone()

    tester.startTest('Testing attributes')
    if dt.name != 'TEST':
        tester.error('name is incorrect')
    if dt.publicId != 'PublicID':
        tester.error('publicId is incorrect')
    if dt.systemId != 'SystemID':
        tester.error('systemId is incorrect')
    tester.testDone()

    tester.startTest('Testing cloneNode()')
    #Should always be done deep
    dt1 = dt.cloneNode(1)
    if dt1.name != dt.name:
        tester.error("cloneNode failed on name")
    if dt1.entities.length != dt.entities.length:
        tester.error("cloneNode did not copy all entities")
    if dt1.notations.length != dt.notations.length:
        tester.error("cloneNode did not copy all notations")
    if dt1.publicId != dt.publicId:
        tester.error("cloneNode fails on publicId")
    if dt1.systemId != dt.systemId:
        tester.error("cloneNode fails on systemId")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 27
0
def test(tester):

    tester.startGroup('Element')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Element
        from xml.dom.Element import Element
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import DOMException
    from xml.dom import INVALID_CHARACTER_ERR
    from xml.dom import WRONG_DOCUMENT_ERR
    from xml.dom import INUSE_ATTRIBUTE_ERR
    from xml.dom import NOT_FOUND_ERR
    from xml.dom import NO_MODIFICATION_ALLOWED_ERR
    from xml.dom import implementation

    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    doc_nons = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    ns = 'www.fourthought.com'
    e_ns = doc.createElementNS(ns, 'TEST')
    e = doc.createElement('TEST')
    tester.testDone()


    tester.startTest('Testing attributes')
    if e.tagName != 'TEST':
        tester.error("tagName failed")
    try:
        e.tagName = "test"
    except DOMException, exc:
        if exc.code != NO_MODIFICATION_ALLOWED_ERR:
            tester.error('Wrong exception on read-only violation')
Exemplo n.º 28
0
def test(tester):
    tester.startGroup('Document')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import Document
        from xml.dom.Document import Document
    except:
        tester.error('Error in syntax' ,1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    from xml.dom import DOMException
    from xml.dom import INVALID_CHARACTER_ERR
    from xml.dom import NOT_SUPPORTED_ERR
    from xml.dom import HIERARCHY_REQUEST_ERR

    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,None,dt);
    tester.testDone()


    tester.startTest('Testing ownerDocument')
    if doc.ownerDocument.nodeName != doc.nodeName:
        tester.error('ownerDocument failed')
    tester.testDone()


    tester.startTest('Testing createElement()')
    e = doc.createElement('ELEMENT')
    if e.ownerDocument.nodeName != doc.nodeName:
        tester.error('createElement does not set ownerDocument')
    if e.tagName != 'ELEMENT':
        tester.error('createElement does not set tagName')
    try:
        e2 = doc.createElement('BAD<NAME');
    except DOMException, data:
        if data.code != INVALID_CHARACTER_ERR:
            tester.error('createElement throws wrong exception')
Exemplo n.º 29
0
def test(tester):

    tester.startGroup('Entity')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Entity
        from xml.dom.Entity import Entity
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)

    ent = doc._4dom_createEntity("-//FOURTHOUGHT//EN", "/tmp/entity", "")
    tester.testDone()


    tester.startTest('Testing attributes')
    if ent.publicId != '-//FOURTHOUGHT//EN':
        tester.error('publicId is incorrect')
    if ent.systemId != '/tmp/entity':
        tester.error('systemId is incorrect')
    tester.testDone()


    tester.startTest('Test cloneNode()')
    ent1 = ent.cloneNode(1)
    if ent1.publicId != ent.publicId:
        tester.error("cloneNode fails on publicId")

    if ent1.systemId != ent.systemId:
        tester.error("cloneNode fails on systemId")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 30
0
def test(tester):

    tester.startGroup('Element')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Element
        from xml.dom.Element import Element
    except:
        tester.tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import DOMException
    from xml.dom import INVALID_CHARACTER_ERR
    from xml.dom import WRONG_DOCUMENT_ERR
    from xml.dom import INUSE_ATTRIBUTE_ERR
    from xml.dom import NOT_FOUND_ERR
    from xml.dom import NO_MODIFICATION_ALLOWED_ERR
    from xml.dom import implementation

    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    doc_nons = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    ns = 'www.fourthought.com'
    e_ns = doc.createElementNS(ns, 'TEST')
    e = doc.createElement('TEST')
    tester.testDone()

    tester.startTest('Testing attributes')
    if e.tagName != 'TEST':
        tester.error("tagName failed")
    try:
        e.tagName = "test"
    except DOMException, exc:
        if exc.code != NO_MODIFICATION_ALLOWED_ERR:
            tester.error('Wrong exception on read-only violation')
Exemplo n.º 31
0
def test(tester):

    tester.startGroup('Notation')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Notation
        from xml.dom.Notation import Notation
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    nota = doc._4dom_createNotation("-//FOURTHOUGHT//EN", "/tmp/notation",
                                    "TestNotation")
    tester.testDone()

    tester.startTest('Testing attributes')
    if nota.publicId != '-//FOURTHOUGHT//EN':
        tester.error('publicId is incorrect')
    if nota.systemId != '/tmp/notation':
        tester.error('systemId is incorrect')
    tester.testDone()

    tester.startTest('Test cloneNode()')
    nota1 = nota.cloneNode(1)
    if nota1.publicId != nota.publicId:
        tester.error("cloneNode fails on publicId")

    if nota1.systemId != nota.systemId:
        tester.error("cloneNode fails on systemId")
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 32
0
def test(tester):
    tester.startGroup('Document')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import Document
        from xml.dom.Document import Document
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    from xml.dom import DOMException
    from xml.dom import INVALID_CHARACTER_ERR
    from xml.dom import NOT_SUPPORTED_ERR
    from xml.dom import HIERARCHY_REQUEST_ERR

    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, None, dt)
    tester.testDone()

    tester.startTest('Testing ownerDocument')
    if doc.ownerDocument.nodeName != doc.nodeName:
        tester.error('ownerDocument failed')
    tester.testDone()

    tester.startTest('Testing createElement()')
    e = doc.createElement('ELEMENT')
    if e.ownerDocument.nodeName != doc.nodeName:
        tester.error('createElement does not set ownerDocument')
    if e.tagName != 'ELEMENT':
        tester.error('createElement does not set tagName')
    try:
        e2 = doc.createElement('BAD<NAME')
    except DOMException, data:
        if data.code != INVALID_CHARACTER_ERR:
            tester.error('createElement throws wrong exception')
Exemplo n.º 33
0
def test(tester):

    tester.startGroup('Entity')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Entity
        from xml.dom.Entity import Entity
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    ent = doc._4dom_createEntity("-//FOURTHOUGHT//EN", "/tmp/entity", "")
    tester.testDone()

    tester.startTest('Testing attributes')
    if ent.publicId != '-//FOURTHOUGHT//EN':
        tester.error('publicId is incorrect')
    if ent.systemId != '/tmp/entity':
        tester.error('systemId is incorrect')
    tester.testDone()

    tester.startTest('Test cloneNode()')
    ent1 = ent.cloneNode(1)
    if ent1.publicId != ent.publicId:
        tester.error("cloneNode fails on publicId")

    if ent1.systemId != ent.systemId:
        tester.error("cloneNode fails on systemId")
    tester.testDone()

    return tester.groupDone()
def test(tester):

    tester.startGroup('ProcessingInstruction')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import ProcessingInstruction
        from xml.dom.ProcessingInstruction import ProcessingInstruction
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    pi = doc.createProcessingInstruction("xml", 'version = "1.0"')
    tester.testDone()

    tester.startTest('Testing attributes')
    if pi.target != 'xml':
        tester.error('Problems with target')
    if pi.data != 'version = "1.0"':
        tester.error('Problems with data')
    tester.testDone()

    tester.startTest('Test cloneNode()')
    pi1 = pi.cloneNode(1)
    if pi1.target != pi.target:
        tester.error("cloneNode fails on target")
    if pi1.data != pi.data:
        tester.error("cloneNode fails on data")
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 35
0
def test(tester):

    tester.startGroup('Node')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Node
        from xml.dom.FtNode import FtNode
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating the test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    # We cannot use just plain old nodes, we need to use Elements
    p = doc.createElement('PARENT')

    nodes = []
    for ctr in range(3):
        n = doc.createElement('Child%d' % ctr)
        nodes.append(n)
    tester.testDone()

    tester.startTest("Testing attributes")
    if p.nodeName != 'PARENT':
        tester.error("Error getting nodeName")
    p.nodeValue = 'NodeValue'
    if p.nodeValue != 'NodeValue':
        tester.error('Error getting/setting nodeValue')
    if p.nodeType != Node.ELEMENT_NODE:
        tester.error('Error getting nodeType')
    if p.parentNode != None:
        tester.error('Error getting parentNode')
    p._4dom_setParentNode(None)
    if p.firstChild != None:
        tester.error('Error getting firstChild')
    if p.lastChild != None:
        tester.error('Error getting lastChild')
    if p.nextSibling != None:
        tester.error('Error getting nextSibling')
    if p.previousSibling != None:
        tester.error('Error getting previousSibling')
    if p.attributes == None:
        tester.error('Error getting attributes')
    if p.ownerDocument.nodeName != doc.nodeName:
        tester.error('Error getting ownerDocument')
    if p.namespaceURI != None:
        tester.error('Error getting namespaceURI')
    if p.prefix != None:
        tester.error('Error getting')
    if p.localName != None:
        tester.error('Error getting localName')
    tester.testDone()

    tester.startTest("Testing insertBefore()")
    if p.insertBefore(nodes[0], None).nodeName != nodes[0].nodeName:
        tester.error("Error inserting")

    if p.firstChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed")
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed")

    if p.insertBefore(nodes[1], nodes[0]).nodeName != nodes[1].nodeName:
        tester.error("Error inserting")

    if p.firstChild.nodeName != nodes[1].nodeName:
        tester.error("Error insert failed")
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed")

    if nodes[0].nextSibling != None:
        tester.error("Error insert failed")
    if nodes[0].previousSibling.nodeName != nodes[1].nodeName:
        tester.error("Error insert failed")
    if nodes[1].nextSibling.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed")
    if nodes[1].previousSibling != None:
        tester.error("Error insert failed")

    if p.removeChild(nodes[1]).nodeName != nodes[1].nodeName:
        tester.error("Error Removing")
    if p.firstChild.nodeName != nodes[0].nodeName:
        tester.error("Error Remove Failed")
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error RemoveFailed")
    if nodes[1].nextSibling != None:
        tester.error("Error Remove Failed")
    if nodes[1].previousSibling != None:
        tester.error("Error Remove Failed")
    if nodes[0].nextSibling != None:
        tester.error("Error Remove Failed")
    if nodes[0].previousSibling != None:
        tester.error("Error Remove Failed")

    try:
        p.insertBefore(nodes[2], nodes[1])
    except DOMException, x:
        if x.code != NOT_FOUND_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected NOT_FOUND_ERR" % name)
Exemplo n.º 36
0
def test(tester):

    tester.startGroup('NamedNodeMap')

    tester.startTest('Checking syntax')
    try:
        from xml.dom import NamedNodeMap
        from xml.dom.NamedNodeMap import NamedNodeMap
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest("Creating test environment")
    nodes = []
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)

    try:
        for ctr in range(3):
            n = doc.createElement('Node%d' % (ctr + 1))
            nodes.append(n)
    except:
        tester.error("Unable to create test nodes")
    nm = doc.createElement('TEST').attributes
    tester.testDone()

    tester.startTest("Testing setNamedItem()")
    if nm.setNamedItem(nodes[0]) != None:
        tester.error("setNamedItem failed")
    if nm.length != 1:
        tester.error("setNamedItem failed")

    nodes[2] = doc.createElement('Node1')

    if nm.setNamedItem(nodes[2]).nodeName != nodes[0].nodeName:
        tester.error("setNamedItem failed on replace")
    if nm.length != 1:
        tester.error("setNamedItem failed")
    tester.testDone()

    tester.startTest("Testing getNamedItem()")
    if nm.getNamedItem(nodes[2].nodeName).nodeName != nodes[2].nodeName:
        tester.error("getNamedItem returns wrong Node")
    if nm.getNamedItem(nodes[1].nodeName) != None:
        tester.error("getNamedItem returns a Node instead of null")
    tester.testDone()

    tester.startTest("Testing removeNamedItem()")
    nodes[0] = doc.createElement("NewNode1")
    nm.setNamedItem(nodes[0])

    if nm.length != 2:
        tester.error("setNamedItem failed")

    if nm.removeNamedItem(nodes[0].nodeName).nodeName != nodes[0].nodeName:
        tester.error("removeNamedItem failed")

    if nm.length != 1:
        tester.error("removeNamedItem failed")

    from xml.dom import DOMException
    from xml.dom import NOT_FOUND_ERR
    try:
        nm.removeNamedItem(nodes[0].nodeName)
    except DOMException, err:
        if err.code != NOT_FOUND_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected NOT_FOUND_ERR" % name)
Exemplo n.º 37
0
def test(tester):

    tester.startGroup('TreeWalker')

    tester.startTest('Checking syntax')
    from xml.dom.TreeWalker import TreeWalker
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    from xml.dom.NodeFilter import NodeFilter
    from xml.dom.ext.reader import Sax

    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,None,dt);

    xml_string = '<a><b><c/><d/></b><e><f/><g/></e></a>'
    doc = Sax.FromXml(xml_string)
    from xml.dom.ext import PrettyPrint
    tw = TreeWalker(doc.documentElement, NodeFilter.SHOW_ELEMENT, None, 1)
    tester.testDone()


    tester.startTest('Testing attributes')
    if tw.root != doc.documentElement:
        tester.error('root was not set')
    if tw.whatToShow != NodeFilter.SHOW_ELEMENT:
        tester.error('whatToShow was not set')
    if tw.filter != None:
        tester.error('filter was not set')
    if tw.expandEntityReferences != 1:
        tester.error('expandEntityReferences was not set')
    tw.currentNode = doc.documentElement.lastChild
    if tw.currentNode != doc.documentElement.lastChild:
        tester.error('currentNode does not set/get properly')
    tester.testDone()


    tester.startTest("Navigating in document order")
    tw.currentNode = tw.root
    if tw.currentNode.nodeName != 'a':
        tester.error('currentNode failed')
    t = doc.createTextNode('Text')
#    tw.currentNode.insertBefore(t,tw.firstChild())
    if tw.firstChild().nodeName != 'b':
        tester.error('Wrong firstChild')
    if tw.nextSibling().nodeName != 'e':
        tester.error('Wrong nextSibling')
    if tw.nextSibling() != None:
        tester.error('nextSibling returns a value; should be (null)')
    if tw.parentNode().nodeName != 'a':
        tester.error('Wrong parentNode')
    if tw.lastChild().nodeName != 'e':
        tester.error('Wrong lastChild')
    if tw.nextNode().nodeName != 'f':
        tester.error('Wrong nextNode')
    # See if whatToShow works
    tw.currentNode.appendChild(t)
    if tw.firstChild() != None:
        tester.error('whatToShow failed in firstChild()')
    if tw.previousSibling() != None:
        tester.error('previousSibling returns a value; should be (null)')
    if tw.previousNode().nodeName != 'e':
        tester.error('Wrong previousNode')
    tw.currentNode.appendChild(t)
    # See if whatToShow works
    if tw.lastChild().nodeName != 'g':
        tester.error('whatToShow failed in lastChlid()')
    tester.testDone()


#    tester.startTest('Printing hierarchy')
#    xml.dom.ext.PrettyPrint(tw.root)
#    tw.currentNode = tw.root
#    printer(tester, tw, '')
#    tester.testDone()


    return tester.groupDone()
Exemplo n.º 38
0
"""
A basic example of using the DOM to create an XML document from scratch.
"""


from xml.dom import ext
from xml.dom import implementation

if __name__ == '__main__':

    #Create a doctype using document type name, sysid and pubid
    dt = implementation.createDocumentType('mydoc', '', '')

    #Create a document using document element namespace URI, doc element
    #name and doctype.  This automatically creates a document element
    #which is the single element child of the document
    doc = implementation.createHTMLDocument('', 'mydoc', dt)

    #Get the document element
    doc_elem = doc.documentElement

    #Create an element: the Document instanmce acts as a factory
    new_elem = doc.createElementNS('', 'spam')

    #Create an attribute on the new element
    new_elem.setAttributeNS('', 'eggs', 'sunnysideup')

    #Create a text node
    new_text = doc.createTextNode('some text here...')

    #Add the new text node to the new element
Exemplo n.º 39
0
 def startDTD(self, doctype, publicID, systemID):
     self._dt = implementation.createDocumentType(doctype, publicID,
                                                  systemID)
     self._orphanedNodes.append(('doctype', ))
     return
Exemplo n.º 40
0
def test(tester):
    tester.startGroup('DOM Structure Model')

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('dt1', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, None, dt)
    df = doc.createDocumentFragment()
    element = doc.createElement('TestElement')

    Nodes = {
        'Document' : implementation.createDocument(EMPTY_NAMESPACE,'ROOT2', dt),
        'DocType' : implementation.createDocumentType('dt2', '', ''),
        'Element' : doc.createElement('tagName1'),
        'Text' : doc.createTextNode('data'),
        'Comment' : doc.createComment('data'),
        'CDATA' : doc.createCDATASection('data'),
        'ProcInstruct' : doc.createProcessingInstruction('target', 'data'),
        'Attr' : doc.createAttribute('name'),
        'EntityRef' : doc.createEntityReference('name'),
        }
    tester.testDone()


    tester.startTest('Testing Document')
    good = ['Element',
            'ProcInstruct',
            'Comment',
            ]

    # Add duplicate Element & DocType
    Nodes['Element2'] = doc.createElement('tagName2')

    testRestriction(tester, doc, Nodes, doc, good)

    # Remove added items
    del Nodes['Element2']
    tester.testDone()


    tester.startTest('Testing DocumentFragment')
    good = ['Element',
            'ProcInstruct',
            'Comment',
            'Text',
            'CDATA',
            'EntityRef',
            ]

    testRestriction(tester, doc, Nodes, df, good)
    tester.testDone()


    tester.startTest('Testing DocumentType')
    good = [
            ]
    testRestriction(tester, doc, Nodes, dt, good)
    tester.testDone()


    tester.startTest('Testing EntityReference')
    good = ['Element',
            'ProcInstruct',
            'Comment',
            'Text',
            'CDATA',
            'EntityRef'
            ]

    ref = doc.createEntityReference('test')
    testRestriction(tester, doc, Nodes, ref, good)
    tester.testDone()


    tester.startTest('Testing Element')
    good = ['Element',
            'ProcInstruct',
            'Comment',
            'Text',
            'CDATA',
            'EntityRef',
            ]

    testRestriction(tester, doc, Nodes, element, good)
    tester.testDone()


    tester.startTest('Testing Attr')
    good = ['Text',
            'EntityRef',
            ]

    testRestriction(tester, doc, Nodes, Nodes['Attr'], good)
    tester.testDone()


    tester.startTest('Testing Comment')
    good = [
            ]

    testRestriction(tester, doc, Nodes, Nodes['Comment'], good)
    tester.testDone()


    tester.startTest('Testing Text')
    good = [
            ]

    testRestriction(tester, doc, Nodes, Nodes['Text'], good)
    tester.testDone()


    tester.startTest('Testing CDATASection')
    good = [
            ]

    testRestriction(tester, doc, Nodes, Nodes['CDATA'], good)
    tester.testDone()


    return tester.groupDone()
Exemplo n.º 41
0
def test(tester):

    tester.startGroup("NamedNodeMap")

    tester.startTest("Checking syntax")
    try:
        from xml.dom import NamedNodeMap
        from xml.dom.NamedNodeMap import NamedNodeMap
    except:
        tester.error("Error in syntax", 1)
    tester.testDone()

    tester.startTest("Creating test environment")
    nodes = []
    from xml.dom import implementation

    dt = implementation.createDocumentType("", "", "")
    doc = implementation.createDocument(EMPTY_NAMESPACE, "ROOT", dt)

    try:
        for ctr in range(3):
            n = doc.createElement("Node%d" % (ctr + 1))
            nodes.append(n)
    except:
        tester.error("Unable to create test nodes")
    nm = doc.createElement("TEST").attributes
    tester.testDone()

    tester.startTest("Testing setNamedItem()")
    if nm.setNamedItem(nodes[0]) != None:
        tester.error("setNamedItem failed")
    if nm.length != 1:
        tester.error("setNamedItem failed")

    nodes[2] = doc.createElement("Node1")

    if nm.setNamedItem(nodes[2]).nodeName != nodes[0].nodeName:
        tester.error("setNamedItem failed on replace")
    if nm.length != 1:
        tester.error("setNamedItem failed")
    tester.testDone()

    tester.startTest("Testing getNamedItem()")
    if nm.getNamedItem(nodes[2].nodeName).nodeName != nodes[2].nodeName:
        tester.error("getNamedItem returns wrong Node")
    if nm.getNamedItem(nodes[1].nodeName) != None:
        tester.error("getNamedItem returns a Node instead of null")
    tester.testDone()

    tester.startTest("Testing removeNamedItem()")
    nodes[0] = doc.createElement("NewNode1")
    nm.setNamedItem(nodes[0])

    if nm.length != 2:
        tester.error("setNamedItem failed")

    if nm.removeNamedItem(nodes[0].nodeName).nodeName != nodes[0].nodeName:
        tester.error("removeNamedItem failed")

    if nm.length != 1:
        tester.error("removeNamedItem failed")

    from xml.dom import DOMException
    from xml.dom import NOT_FOUND_ERR

    try:
        nm.removeNamedItem(nodes[0].nodeName)
    except DOMException, err:
        if err.code != NOT_FOUND_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected NOT_FOUND_ERR" % name)
Exemplo n.º 42
0
 def startDTD(self, doctype, publicID, systemID):
     self._dt = implementation.createDocumentType(doctype, publicID, systemID)
     self._orphanedNodes.append(('doctype',))
     return
Exemplo n.º 43
0
def test(tester):
    tester.startGroup('Python Representation')

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('', '', '')
    doc = implementation.createDocument(EMPTY_NAMESPACE, 'ROOT', dt)
    c = doc.createComment("Comment")
    tester.testDone()

    tester.startTest('Test Attribute')
    a = doc.createAttribute('ATTR_NAME')
    a.value = 'ATTR_VALUE'
    tester.message(str(a))
    tester.testDone()

    tester.startTest('Testing CDATASection')
    c1 = doc.createCDATASection('Short String')
    tester.message(str(c1))
    c2 = doc.createCDATASection(
        'This is a much longer string, over 20 characters')
    tester.message(str(c2))
    tester.testDone()

    tester.startTest('Testing Comment')
    c1 = doc.createComment('Short Comment')
    tester.message(str(c1))
    c2 = doc.createComment('This is a much longer comment, over 20 characters')
    tester.message(str(c2))
    tester.testDone()

    tester.startTest('Testing Document')
    tester.message(str(doc))
    tester.testDone()

    tester.startTest('Testing Document Fragment')
    df = doc.createDocumentFragment()
    tester.message(str(df))
    tester.testDone()

    tester.startTest('Testing Element')
    e = doc.createElement('ELEMENT')
    tester.message(str(e))
    tester.testDone()

    tester.startTest('Testing Entity')
    e = doc._4dom_createEntity("ID1", "ID2", "NAME")
    tester.message(str(e))
    tester.testDone()

    tester.startTest('Testing Entity Reference')
    e = doc.createEntityReference('E-Ref')
    tester.message(str(e))
    tester.testDone()

    tester.startTest('Testing NamedNodeMap')
    nnm = implementation._4dom_createNamedNodeMap()
    tester.message(str(nnm))
    tester.testDone()

    tester.startTest('Testing NodeList')
    nl = implementation._4dom_createNodeList([e])
    tester.message(str(nl))
    tester.testDone()

    tester.startTest('Testing Notation')
    n = doc._4dom_createNotation("ID1", "ID2", "NAME")
    tester.message(str(n))
    tester.testDone()

    tester.startTest('Testing ProcessingInstruction')
    p = doc.createProcessingInstruction('This-is-a-long-target', 'short data')
    tester.message(str(p))
    tester.testDone()

    tester.startTest('Testing Text')
    t = doc.createTextNode('This is a very long text string')
    tester.message(str(t))
    tester.testDone()

    return tester.groupDone()
Exemplo n.º 44
0
def test(tester):

    tester.startGroup('Node')

    tester.startTest('Testing syntax')
    try:
        from xml.dom import Node
        from xml.dom.FtNode import FtNode
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()


    tester.startTest('Creating the test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt);

    # We cannot use just plain old nodes, we need to use Elements
    p = doc.createElement('PARENT')

    nodes = []
    for ctr in range(3):
        n = doc.createElement('Child%d' % ctr)
        nodes.append(n)
    tester.testDone()


    tester.startTest("Testing attributes")
    if p.nodeName != 'PARENT':
        tester.error("Error getting nodeName");
    p.nodeValue = 'NodeValue';
    if p.nodeValue != 'NodeValue':
        tester.error('Error getting/setting nodeValue');
    if p.nodeType != Node.ELEMENT_NODE:
        tester.error('Error getting nodeType');
    if p.parentNode != None:
        tester.error('Error getting parentNode');
    p._4dom_setParentNode(None)
    if p.firstChild != None:
        tester.error('Error getting firstChild');
    if p.lastChild != None:
        tester.error('Error getting lastChild');
    if p.nextSibling != None:
        tester.error('Error getting nextSibling');
    if p.previousSibling != None:
        tester.error('Error getting previousSibling');
    if p.attributes == None:
        tester.error('Error getting attributes');
    if p.ownerDocument.nodeName != doc.nodeName:
        tester.error('Error getting ownerDocument');
    if p.namespaceURI != None:
        tester.error('Error getting namespaceURI')
    if p.prefix != None:
        tester.error('Error getting')
    if p.localName != None:
        tester.error('Error getting localName')
    tester.testDone()


    tester.startTest("Testing insertBefore()")
    if p.insertBefore(nodes[0],None).nodeName != nodes[0].nodeName:
        tester.error("Error inserting");

    if p.firstChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed");
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed");

    if p.insertBefore(nodes[1],nodes[0]).nodeName != nodes[1].nodeName:
        tester.error("Error inserting");

    if p.firstChild.nodeName != nodes[1].nodeName:
        tester.error("Error insert failed");
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed");

    if nodes[0].nextSibling != None:
        tester.error("Error insert failed");
    if nodes[0].previousSibling.nodeName != nodes[1].nodeName:
        tester.error("Error insert failed");
    if nodes[1].nextSibling.nodeName != nodes[0].nodeName:
        tester.error("Error insert failed");
    if nodes[1].previousSibling != None:
        tester.error("Error insert failed");

    if p.removeChild(nodes[1]).nodeName != nodes[1].nodeName:
        tester.error("Error Removing")
    if p.firstChild.nodeName != nodes[0].nodeName:
        tester.error("Error Remove Failed")
    if p.lastChild.nodeName != nodes[0].nodeName:
        tester.error("Error RemoveFailed")
    if nodes[1].nextSibling != None:
        tester.error("Error Remove Failed");
    if nodes[1].previousSibling != None:
        tester.error("Error Remove Failed");
    if nodes[0].nextSibling != None:
        tester.error("Error Remove Failed");
    if nodes[0].previousSibling != None:
        tester.error("Error Remove Failed");

    try:
        p.insertBefore(nodes[2],nodes[1]);
    except DOMException, x:
        if x.code != NOT_FOUND_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected NOT_FOUND_ERR" % name)
Exemplo n.º 45
0
        def toXml(self, filename='', compress=False):
            """drawing.toXml()        ---->to the screen
            drawing.toXml(filename)---->to the file
            writes a svg drawing to the screen or to a file
            compresses if filename ends with svgz or if compress is true
            """
            doctype = implementation.createDocumentType(
                'svg', "-//W3C//DTD SVG 1.0//EN""", 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd ')

            global root
            # root is defined global so it can be used by the appender. Its also possible to use it as an arugument but
            # that is a bit messy.
            root = implementation.createDocument(None, None, doctype)
            # Create the xml document.
            global appender

            def appender(element, elementroot):
                """This recursive function appends elements to an element and sets the attributes
                and type. It stops when alle elements have been appended"""
                if element.namespace:
                    e = root.createElementNS(element.namespace, element.type)
                else:
                    e = root.createElement(element.type)
                if element.text:
                    textnode = root.createTextNode(element.text)
                    e.appendChild(textnode)
                # in element.attributes is supported from python 2.2
                for attribute in list(element.attributes.keys()):
                    e.setAttribute(
                        attribute, str(element.attributes[attribute]))
                if element.elements:
                    for el in element.elements:
                        e = appender(el, e)
                elementroot.appendChild(e)
                return elementroot
            root = appender(self.svg, root)
            if not filename:
                xml = StringIO()
                PrettyPrint(root, xml)
                if compress:
                    import gzip
                    f = StringIO()
                    zf = gzip.GzipFile(fileobj=f, mode='wb')
                    zf.write(xml.getvalue())
                    zf.close()
                    f.seek(0)
                    return f.read()
                else:
                    return xml.getvalue()
            else:
                try:
                    if filename[-4:] == 'svgz':
                        import gzip
                        xml = StringIO()
                        PrettyPrint(root, xml)
                        f = gzip.GzipFile(
                            filename=filename, mode='wb', compresslevel=9)
                        f.write(xml.getvalue())
                        f.close()
                    else:
                        f = open(filename, 'w')
                        PrettyPrint(root, f)
                        f.close()
                except:
                    print("Cannot write SVG file: " + filename)
Exemplo n.º 46
0
 def toXml(self,filename='',compress=False):
     """drawing.toXml()        ---->to the screen
     drawing.toXml(filename)---->to the file
     writes a svg drawing to the screen or to a file
     compresses if filename ends with svgz or if compress is true
     """
     doctype = implementation.createDocumentType('svg',"-//W3C//DTD SVG 1.0//EN""",'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd ')
 
     global root
     #root is defined global so it can be used by the appender. Its also possible to use it as an arugument but
     #that is a bit messy.
     root=implementation.createDocument(None,None,doctype)
     #Create the xml document.
     global appender
     def appender(element,elementroot):
         """This recursive function appends elements to an element and sets the attributes
         and type. It stops when alle elements have been appended"""
         if element.namespace:
             e=root.createElementNS(element.namespace,element.type)
         else:
             e=root.createElement(element.type)
         if element.text:
             textnode=root.createTextNode(element.text)
             e.appendChild(textnode)
         for attribute in element.attributes.keys():   #in element.attributes is supported from python 2.2
             e.setAttribute(attribute,str(element.attributes[attribute]))
         if element.elements:
             for el in element.elements:
                 e=appender(el,e)
         elementroot.appendChild(e)
         return elementroot
     root=appender(self.svg,root)
     if not filename:
         import cStringIO
         xml=cStringIO.StringIO()
         PrettyPrint(root,xml)
         if compress:
             import gzip
             f=cStringIO.StringIO()
             zf=gzip.GzipFile(fileobj=f,mode='wb')
             zf.write(xml.getvalue())
             zf.close()
             f.seek(0)
             return f.read()
         else:
             return xml.getvalue()
     else:
         try:
             if filename[-4:]=='svgz':
                 import gzip
                 import cStringIO
                 xml=cStringIO.StringIO()
                 PrettyPrint(root,xml)
                 f=gzip.GzipFile(filename=filename,mode='wb',compresslevel=9)
                 f.write(xml.getvalue())
                 f.close()
             else:
                 f=open(filename,'w')
                 PrettyPrint(root,f)
                 f.close()
         except:
             print "Cannot write SVG file: " + filename
Exemplo n.º 47
0
def test(tester):
    tester.startGroup('Python Representation')

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument(EMPTY_NAMESPACE,'ROOT',dt)
    c = doc.createComment("Comment")
    tester.testDone()


    tester.startTest('Test Attribute')
    a = doc.createAttribute('ATTR_NAME')
    a.value = 'ATTR_VALUE'
    tester.message(str(a))
    tester.testDone()


    tester.startTest('Testing CDATASection')
    c1 = doc.createCDATASection('Short String')
    tester.message(str(c1))
    c2 = doc.createCDATASection('This is a much longer string, over 20 characters')
    tester.message(str(c2))
    tester.testDone()


    tester.startTest('Testing Comment')
    c1 = doc.createComment('Short Comment')
    tester.message(str(c1))
    c2 = doc.createComment('This is a much longer comment, over 20 characters')
    tester.message(str(c2))
    tester.testDone()


    tester.startTest('Testing Document')
    tester.message(str(doc))
    tester.testDone()


    tester.startTest('Testing Document Fragment')
    df = doc.createDocumentFragment()
    tester.message(str(df))
    tester.testDone()


    tester.startTest('Testing Element')
    e = doc.createElement('ELEMENT')
    tester.message(str(e))
    tester.testDone()


    tester.startTest('Testing Entity')
    e = doc._4dom_createEntity("ID1","ID2","NAME")
    tester.message(str(e))
    tester.testDone()


    tester.startTest('Testing Entity Reference')
    e = doc.createEntityReference('E-Ref')
    tester.message(str(e))
    tester.testDone()


    tester.startTest('Testing NamedNodeMap')
    nnm = implementation._4dom_createNamedNodeMap()
    tester.message(str(nnm))
    tester.testDone()


    tester.startTest('Testing NodeList')
    nl = implementation._4dom_createNodeList([e])
    tester.message(str(nl))
    tester.testDone()


    tester.startTest('Testing Notation')
    n = doc._4dom_createNotation("ID1","ID2","NAME")
    tester.message(str(n))
    tester.testDone()


    tester.startTest('Testing ProcessingInstruction')
    p = doc.createProcessingInstruction('This-is-a-long-target', 'short data')
    tester.message(str(p))
    tester.testDone()


    tester.startTest('Testing Text')
    t = doc.createTextNode('This is a very long text string')
    tester.message(str(t))
    tester.testDone()


    return tester.groupDone()