diff --git a/pisi/xml/autoxml.py b/pisi/xml/autoxml.py index cc6d1c40..7b74d6e5 100644 --- a/pisi/xml/autoxml.py +++ b/pisi/xml/autoxml.py @@ -462,7 +462,7 @@ class autoxml(oo.autosuper, oo.autoprop): tag_type = spec[0] assert type(tag_type) == type(type) def readtext(node, blah): - node.normalize() + #node.normalize() # piksemel doesn't have this return getNodeText(node) def writetext(node, blah, text): addText(node, "", text) @@ -687,6 +687,7 @@ class autoxml(oo.autosuper, oo.autoprop): dummy = node.ownerDocument.createElement("Dummy") dummy.appendChild(node) l.append(decode_item(dummy, errs, where + unicode("[%s]" % ix))) + #l.append(decode_item(node, errs, where + unicode("[%s]" % ix))) ix += 1 return l @@ -699,6 +700,7 @@ class autoxml(oo.autosuper, oo.autoprop): else: listnode = node encode_item(listnode, item, errs) + #encode_item(node, item, errs) else: if req is mandatory: errs.append(_('Mandatory list empty')) diff --git a/pisi/xml/xmlext.py b/pisi/xml/xmlext.py index 3c209836..e7133ba7 100644 --- a/pisi/xml/xmlext.py +++ b/pisi/xml/xmlext.py @@ -12,7 +12,7 @@ # Authors: Eray Ozkural try: - #zimbabwe # comment out to disable piks + zimbabwe # comment out to disable piks from xmlextpiks import * except: print 'xmlext: piksemel implementation cannot be loaded, falling back to minidom' diff --git a/pisi/xml/xmlfile.py b/pisi/xml/xmlfile.py index f544e5f2..bb58a4c5 100644 --- a/pisi/xml/xmlfile.py +++ b/pisi/xml/xmlfile.py @@ -12,7 +12,7 @@ # Authors: Eray Ozkural try: - #horagata # comment out to disable piks + horagata # comment out to disable piks from xmlextpiks import * from xmlfilepiks import * except: diff --git a/pisi/xml/xmlfilepiks.py b/pisi/xml/xmlfilepiks.py index 71e3ffd6..721c1e90 100644 --- a/pisi/xml/xmlfilepiks.py +++ b/pisi/xml/xmlfilepiks.py @@ -25,6 +25,7 @@ __trans = gettext.translation('pisi', fallback=True) _ = __trans.ugettext import pisi +from piksemel import * class Error(pisi.Error): "named this way because the class if mostly used with an import *" @@ -39,27 +40,26 @@ class XmlFile(object): def newDOM(self): """clear DOM""" - impl = mdom.getDOMImplementation() - self.dom = impl.createDocument(None, self.rootTag, None) + self.doc = newDocument(self.rootTag) def unlink(self): """deallocate DOM structure""" - self.dom.unlink() + pass # piksemel is garbage collected! def rootNode(self): """returns root document element""" - return self.dom.documentElement + return self.doc def readxml(self, fileName): try: - self.dom = mdom.parse(fileName) - except ExpatError, inst: + self.doc = parse(fileName) + except ParseError, inst: raise XmlError(_("File '%s' has invalid XML: %s\n") % (fileName, str(inst))) def writexml(self, fileName): f = codecs.open(fileName,'w', "utf-8") - f.write(self.dom.toprettyxml()) + f.write(self.doc.toPrettyString()) f.close() def verifyRootTag(self): @@ -70,21 +70,21 @@ class XmlFile(object): # construction helpers - def newNode(self, tag): - return self.dom.createElement(tag) + #def newNode(self, tag): + # return self.dom.createElement(tag) - def newTextNode(self, text): - return self.dom.createTextNode(text) + #def newTextNode(self, text): + # return self.dom.createTextNode(text) - def newAttribute(self, attr): - return self.dom.createAttribute(attr) + #def newAttribute(self, attr): + # return self.dom.createAttribute(attr) # read helpers def getNode(self, tagPath = ""): """returns the *first* matching node for given tag path.""" self.verifyRootTag() - return getNode(self.dom.documentElement, tagPath) + return getNode(self.doc, tagPath) def getNodeText(self, tagPath): """returns the text of *first* matching node for given tag path.""" @@ -96,36 +96,24 @@ class XmlFile(object): def getAllNodes(self, tagPath): """returns all nodes matching a given tag path.""" self.verifyRootTag() - return getAllNodes(self.dom.documentElement, tagPath) + return getAllNodes(self.doc, tagPath) def getChildren(self, tagpath): """ returns the children of the given path""" node = self.getNode(tagpath) - return node.childNodes - - # get only elements of a given type - #FIXME: this doesn't work - def getChildrenWithType(self, tagpath, type): - """ returns the children of the given path, only with given type """ - node = self.getNode(tagpath) - return filter(lambda x:x.nodeType == type, node.childNodes) + return [x for x in parent.childNodes] # get only child elements def getChildElts(self, tagpath): """ returns the children of the given path, only with given type """ - node = self.getNode(tagpath) - try: - return filter(lambda x:x.nodeType == x.ELEMENT_NODE, - node.childNodes) - except AttributeError: - return None + return getChildElts(self.getNode(tagpath)) # write helpers def addNode(self, tagPath, newnode = None): "this adds the newnode under given tag path" self.verifyRootTag() - return addNode(self.dom.documentElement, tagPath, newnode) + return addNode(self.doc, tagPath, newnode) def addNodeUnder(self, node, tagPath, newnode = None): "this adds the new stuff under node and then following tag path" @@ -138,13 +126,16 @@ class XmlFile(object): def addText(self, node, text): "add text to node" - node.appendChild(self.newTextNode(text)) + raise Error('NOT IMPLEMENTED') + #node.appendChild(self.newTextNode(text)) def addTextNode(self, tagPath, text): "add a text node with given tag path" - node = self.addNode(tagPath, self.newTextNode(text)) - return node + raise Error('NOT IMPLEMENTED') + #node = self.addNode(tagPath, self.newTextNode(text)) + #return node def addTextNodeUnder(self, node, tagPath, text): "add a text node under given node with tag path (phew)" - return self.addNodeUnder(node, tagPath, self.newTextNode(text)) + raise Error('NOT IMPLEMENTED') + #return self.addNodeUnder(node, tagPath, self.newTextNode(text))