diff --git a/pisi.e3p b/pisi.e3p
index 473042db..e9197b6b 100644
--- a/pisi.e3p
+++ b/pisi.e3p
@@ -1,7 +1,7 @@
-
+
Python
@@ -174,10 +174,6 @@
pisi
build.py
-
- pisi
- xmlfile.py
-
pisi
packagedb.py
@@ -376,6 +372,30 @@
pisi
xmlextmdom.py
+
+ pisi
+ xmlext.py
+
+
+ pisi
+ xmlextpiks.py
+
+
+ pisi
+ xmlfile.py
+
+
+ pisi
+ xmlfilepiks.py
+
+
+ pisi
+ xmlfilemdom.py
+
+
+ pisi
+ autoxml.py
+
@@ -418,9 +438,9 @@
-
-
-
+
+
+
diff --git a/pisi/xml/xmlext.py b/pisi/xml/xmlext.py
index e21dffa4..9b86f462 100644
--- a/pisi/xml/xmlext.py
+++ b/pisi/xml/xmlext.py
@@ -11,4 +11,8 @@
#
# Authors: Eray Ozkural
-from xmlextmdom import *
+try:
+ from xmlextpiks import *
+except:
+ print 'xmlext: piksemel implementation cannot be loaded, falling back to minidom'
+ from xmlextmdom import *
diff --git a/pisi/xml/xmlextpiks.py b/pisi/xml/xmlextpiks.py
index b4cdb926..9ae35ffc 100644
--- a/pisi/xml/xmlextpiks.py
+++ b/pisi/xml/xmlextpiks.py
@@ -27,7 +27,7 @@ __trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi
-import piksemel as iks
+from piksemel import *
class XmlError(pisi.Error):
"named this way because the class if mostly used with an import *"
@@ -35,31 +35,28 @@ class XmlError(pisi.Error):
def getNodeAttribute(node, attrname):
"""get named attribute from DOM node"""
- if not node.hasAttribute(attrname):
- return None
return node.getAttribute(attrname)
def getChildElts(node):
"""get only child elements"""
- return filter(lambda x:x.nodeType == x.ELEMENT_NODE, node.childNodes)
+ return [x for x in parent.childNodes if x.type == TAG ]
def getTagByName(parent, childName):
- return [x for x in parent.childNodes
- if x.nodeType == x.ELEMENT_NODE and x.tagName == childName]
+ return [x for x in parent if x.type == TAG and x.name == childName]
def getNodeText(node, tagpath = ""):
"""get the first child and expect it to be text!"""
if tagpath!="":
node = getNode(node, tagpath)
try:
- child = node.childNodes[0]
+ child = node.firstChild()
except IndexError:
return None
except AttributeError: # no node by that name
return None
- if child.nodeType == child.TEXT_NODE:
+ if child.nodeType == CDATA: #FIXME: ??? TEXT type?
# in any case, strip whitespaces...
- return child.data.strip()
+ return child.getTagData().strip()
else:
raise XmlError(_("getNodeText: Expected text node, got something else!"))
@@ -79,8 +76,8 @@ def getNode(node, tagpath):
# iterative code to search for the path
for tag in tags:
- for child in node.childNodes:
- if child.nodeType == node.ELEMENT_NODE and child.tagName == tag:
+ for child in node:
+ if child.type == TAG and child.name == tag:
return child
return None
@@ -112,16 +109,15 @@ def createTagPath(node, tags):
no matter what"""
if len(tags)==0:
return node
- dom = node.ownerDocument
for tag in tags:
- node = node.appendChild(dom.createElement(tag))
+ node = node.appendTag(Node(tag))
return node
def addTagPath(node, tags, newnode=None):
"""add newnode at the end of a tag chain, smart one"""
node = createTagPath(node, tags)
if newnode: # node to add specified
- node.appendChild(newnode)
+ node.appendTag(newnode)
return node
def addNode(node, tagpath, newnode = None, branch=True):
@@ -160,10 +156,10 @@ def addNode(node, tagpath, newnode = None, branch=True):
return node
def newNode(node, tag):
- return node.ownerDocument.createElement(tag)
+ return Node(tag)
def newTextNode(node, text):
- return node.ownerDocument.createTextNode(text)
+ return Node(text)
def addText(node, tagPath, text, branch = True):
newnode = newTextNode(node, text)
diff --git a/pisi/xml/xmlfile.py b/pisi/xml/xmlfile.py
index d6f2bd05..39276b08 100644
--- a/pisi/xml/xmlfile.py
+++ b/pisi/xml/xmlfile.py
@@ -11,4 +11,9 @@
#
# Authors: Eray Ozkural
-from xmlfilemdom import *
+try:
+ from xmlextpiks import *
+ from xmlfilepiks import *
+except:
+ print 'xmlfile: piksemel implementation cannot be loaded, falling back to minidom'
+ from xmlfilemdom import *
diff --git a/tests/xmlexttests.py b/tests/xmlexttests.py
index fe4eec6b..96f863d8 100644
--- a/tests/xmlexttests.py
+++ b/tests/xmlexttests.py
@@ -10,16 +10,12 @@
import unittest
import os
-import xml.dom.minidom as mdom
-from xml.parsers.expat import ExpatError
-import types
import pisi
import pisi.api
-from pisi import xmlfile
import pisi.context as ctx
import pisi.util as util
-from pisi.xmlext import *
+from pisi.xml import xmlext
import testcase
@@ -29,22 +25,21 @@ class XmlExtTestCase(testcase.TestCase):
testcase.TestCase.setUp(self, database=False)
def testGet(self):
- self.a = mdom.parse('tests/a.xml')
- self.doc = self.a.documentElement
- self.assertEqual(getNodeText(self.doc, 'Number'), '868')
- self.assertEqual(getNodeText(self.doc, 'OtherInfo/BirthDate'), '18071976')
- codeswith = getAllNodes(self.doc, 'OtherInfo/CodesWith/Person')
+ self.doc = xmlext.parse('tests/a.xml')
+ #self.doc = self.a.documentElement
+ self.assertEqual(xmlext.getNodeText(self.doc, 'Number'), '868')
+ self.assertEqual(xmlext.getNodeText(self.doc, 'OtherInfo/BirthDate'), '18071976')
+ codeswith = xmlext.getAllNodes(self.doc, 'OtherInfo/CodesWith/Person')
self.assertEqual(len(codeswith), 4)
- self.assertEqual(getNodeText(codeswith[2]), 'Caglar')
+ self.assertEqual(xmlext.getNodeText(codeswith[2]), 'Caglar')
def testAdd(self):
- impl = mdom.getDOMImplementation()
- a = impl.createDocument(None, 'team', None)
- node = a.documentElement
- addText(node, 'team/coder', 'zibidi1')
- addText(node, 'team/coder', 'zibidi2')
- addText(node, 'team/coder', 'zibidi3')
- reada = getAllNodes(node, 'team/coder')
+ node = xmlext.newDocument('team')
+ #node = a.documentElement
+ xmlext.addText(node, 'team/coder', 'zibidi1')
+ xmlext.addText(node, 'team/coder', 'zibidi2')
+ xmlext.addText(node, 'team/coder', 'zibidi3')
+ reada = xmlext.getAllNodes(node, 'team/coder')
self.assertEqual(len(reada), 3)
pass