* improve piksemel implementation a bit
* add newDocument and parse functions to xmlext (kind of for piks compat.) * fix: getNode function was b0rked, xmlext test passes now * switch back to mdom impl. because piks. impl. doesn't work yet
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
|
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
|
||||||
<!-- Project file for project pisi -->
|
<!-- Project file for project pisi -->
|
||||||
<!-- Saved: 2005-11-09, 19:48:27 -->
|
<!-- Saved: 2005-11-09, 22:55:46 -->
|
||||||
<!-- Copyright (C) 2005 PiSi Development Team, -->
|
<!-- Copyright (C) 2005 PiSi Development Team, -->
|
||||||
<Project version="3.8">
|
<Project version="3.8">
|
||||||
<ProgLanguage mixed="0">Python</ProgLanguage>
|
<ProgLanguage mixed="0">Python</ProgLanguage>
|
||||||
@@ -370,32 +370,44 @@
|
|||||||
</Source>
|
</Source>
|
||||||
<Source>
|
<Source>
|
||||||
<Dir>pisi</Dir>
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
<Name>xmlextmdom.py</Name>
|
<Name>xmlextmdom.py</Name>
|
||||||
</Source>
|
</Source>
|
||||||
<Source>
|
<Source>
|
||||||
<Dir>pisi</Dir>
|
<Dir>pisi</Dir>
|
||||||
<Name>xmlext.py</Name>
|
<Dir>xml</Dir>
|
||||||
</Source>
|
|
||||||
<Source>
|
|
||||||
<Dir>pisi</Dir>
|
|
||||||
<Name>xmlextpiks.py</Name>
|
|
||||||
</Source>
|
|
||||||
<Source>
|
|
||||||
<Dir>pisi</Dir>
|
|
||||||
<Name>xmlfile.py</Name>
|
|
||||||
</Source>
|
|
||||||
<Source>
|
|
||||||
<Dir>pisi</Dir>
|
|
||||||
<Name>xmlfilepiks.py</Name>
|
|
||||||
</Source>
|
|
||||||
<Source>
|
|
||||||
<Dir>pisi</Dir>
|
|
||||||
<Name>xmlfilemdom.py</Name>
|
<Name>xmlfilemdom.py</Name>
|
||||||
</Source>
|
</Source>
|
||||||
<Source>
|
<Source>
|
||||||
<Dir>pisi</Dir>
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
|
<Name>xmlextpiks.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
|
<Name>xmlfilepiks.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
|
<Name>xmlext.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
<Name>autoxml.py</Name>
|
<Name>autoxml.py</Name>
|
||||||
</Source>
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
|
<Name>xmlfile.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>pisi</Dir>
|
||||||
|
<Dir>xml</Dir>
|
||||||
|
<Name>__init__.py</Name>
|
||||||
|
</Source>
|
||||||
</Sources>
|
</Sources>
|
||||||
<Forms>
|
<Forms>
|
||||||
</Forms>
|
</Forms>
|
||||||
@@ -438,9 +450,9 @@
|
|||||||
</Vcs>
|
</Vcs>
|
||||||
<FiletypeAssociations>
|
<FiletypeAssociations>
|
||||||
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
||||||
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
|
||||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
|
||||||
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
||||||
|
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
||||||
|
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
||||||
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
||||||
</FiletypeAssociations>
|
</FiletypeAssociations>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@
|
|||||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from xmlextpiks import *
|
#from xmlextpiks import *
|
||||||
|
zimbabwe
|
||||||
except:
|
except:
|
||||||
print 'xmlext: piksemel implementation cannot be loaded, falling back to minidom'
|
print 'xmlext: piksemel implementation cannot be loaded, falling back to minidom'
|
||||||
from xmlextmdom import *
|
from xmlextmdom import *
|
||||||
|
|||||||
+34
-12
@@ -15,11 +15,9 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
xmlext is a helper module for accessing XML files using
|
xmlext is a helper module for accessing XML files using
|
||||||
xml.dom.minidom.
|
xml.dom.minidom . It is a convenient wrapper for some
|
||||||
|
DOM functions, and provides path based get/add functions
|
||||||
XmlFile class further abstracts a dom object using the
|
as in KDE API.
|
||||||
high-level dom functions provided in xmlext module (and sorely lacking
|
|
||||||
in xml.dom :( )
|
|
||||||
|
|
||||||
function names are mixedCase for compatibility with minidom,
|
function names are mixedCase for compatibility with minidom,
|
||||||
an 'old library'
|
an 'old library'
|
||||||
@@ -32,6 +30,7 @@ __trans = gettext.translation('pisi', fallback=True)
|
|||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import xml.dom.minidom as mdom
|
import xml.dom.minidom as mdom
|
||||||
|
from xml.parsers.expat import ExpatError
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
|
|
||||||
@@ -39,6 +38,29 @@ class XmlError(pisi.Error):
|
|||||||
"named this way because the class if mostly used with an import *"
|
"named this way because the class if mostly used with an import *"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Document wrappers
|
||||||
|
|
||||||
|
def newDocument(tag):
|
||||||
|
impl = mdom.getDOMImplementation()
|
||||||
|
dom = impl.createDocument(None, tag, None)
|
||||||
|
return dom.documentElement
|
||||||
|
|
||||||
|
def parse(filename):
|
||||||
|
try:
|
||||||
|
dom = mdom.parse(filename)
|
||||||
|
return dom.documentElement
|
||||||
|
except ExpatError, inst:
|
||||||
|
raise Error(_("File '%s' has invalid XML: %s\n") % (fileName,
|
||||||
|
str(inst)))
|
||||||
|
|
||||||
|
def newNode(node, tag):
|
||||||
|
return node.ownerDocument.createElement(tag)
|
||||||
|
|
||||||
|
def newTextNode(node, text):
|
||||||
|
return node.ownerDocument.createTextNode(text)
|
||||||
|
|
||||||
|
# Node related wrappers
|
||||||
|
|
||||||
def getNodeAttribute(node, attrname):
|
def getNodeAttribute(node, attrname):
|
||||||
"""get named attribute from DOM node"""
|
"""get named attribute from DOM node"""
|
||||||
if not node.hasAttribute(attrname):
|
if not node.hasAttribute(attrname):
|
||||||
@@ -85,10 +107,16 @@ def getNode(node, tagpath):
|
|||||||
|
|
||||||
# iterative code to search for the path
|
# iterative code to search for the path
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
|
currentNode = None
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
if child.nodeType == node.ELEMENT_NODE and child.tagName == tag:
|
if child.nodeType == node.ELEMENT_NODE and child.tagName == tag:
|
||||||
return child
|
currentNode = child
|
||||||
|
break
|
||||||
|
if not currentNode:
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
|
node = currentNode
|
||||||
|
return currentNode
|
||||||
|
|
||||||
def getAllNodes(node, tagPath):
|
def getAllNodes(node, tagPath):
|
||||||
"""retrieve all nodes that match a given tag path."""
|
"""retrieve all nodes that match a given tag path."""
|
||||||
@@ -165,12 +193,6 @@ def addNode(node, tagpath, newnode = None, branch=True):
|
|||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def newNode(node, tag):
|
|
||||||
return node.ownerDocument.createElement(tag)
|
|
||||||
|
|
||||||
def newTextNode(node, text):
|
|
||||||
return node.ownerDocument.createTextNode(text)
|
|
||||||
|
|
||||||
def addText(node, tagPath, text, branch = True):
|
def addText(node, tagPath, text, branch = True):
|
||||||
newnode = newTextNode(node, text)
|
newnode = newTextNode(node, text)
|
||||||
addNode(node, tagPath, newnode, branch)
|
addNode(node, tagPath, newnode, branch)
|
||||||
|
|||||||
@@ -155,11 +155,13 @@ def addNode(node, tagpath, newnode = None, branch=True):
|
|||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def newNode(node, tag):
|
# cannot be implemented with piksemel
|
||||||
return Node(tag)
|
#def newNode(node, tag):
|
||||||
|
# return Node(tag)
|
||||||
|
|
||||||
def newTextNode(node, text):
|
# cannot be implemented with piksemel :(
|
||||||
return Node(text)
|
#def newTextNode(node, text):
|
||||||
|
# return Node(text)
|
||||||
|
|
||||||
def addText(node, tagPath, text, branch = True):
|
def addText(node, tagPath, text, branch = True):
|
||||||
newnode = newTextNode(node, text)
|
newnode = newTextNode(node, text)
|
||||||
|
|||||||
+3
-2
@@ -12,8 +12,9 @@
|
|||||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from xmlextpiks import *
|
#from xmlextpiks import *
|
||||||
from xmlfilepiks import *
|
#from xmlfilepiks import *
|
||||||
|
horagata
|
||||||
except:
|
except:
|
||||||
print 'xmlfile: piksemel implementation cannot be loaded, falling back to minidom'
|
print 'xmlfile: piksemel implementation cannot be loaded, falling back to minidom'
|
||||||
from xmlfilemdom import *
|
from xmlfilemdom import *
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ import gettext
|
|||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import xml.dom.minidom as mdom
|
#import xml.dom.minidom as mdom
|
||||||
|
from xml.parsers.expat import ExpatError
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
@@ -61,7 +62,7 @@ class XmlFile(object):
|
|||||||
try:
|
try:
|
||||||
self.dom = mdom.parse(fileName)
|
self.dom = mdom.parse(fileName)
|
||||||
except ExpatError, inst:
|
except ExpatError, inst:
|
||||||
raise XmlError(_("File '%s' has invalid XML: %s\n") % (fileName,
|
raise Error(_("File '%s' has invalid XML: %s\n") % (fileName,
|
||||||
str(inst)))
|
str(inst)))
|
||||||
|
|
||||||
def writexml(self, fileName):
|
def writexml(self, fileName):
|
||||||
|
|||||||
@@ -42,6 +42,4 @@ class XmlExtTestCase(testcase.TestCase):
|
|||||||
reada = xmlext.getAllNodes(node, 'team/coder')
|
reada = xmlext.getAllNodes(node, 'team/coder')
|
||||||
self.assertEqual(len(reada), 3)
|
self.assertEqual(len(reada), 3)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
suite = unittest.makeSuite(XmlExtTestCase)
|
suite = unittest.makeSuite(XmlExtTestCase)
|
||||||
|
|||||||
Reference in New Issue
Block a user