From 79a1deffe9281c187858d788b80141ffb73fd40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sun, 7 May 2006 19:01:49 +0000 Subject: [PATCH] * goddamn foolish cdom --- pisi/pxml/autoxml.py | 14 ++++---------- pisi/pxml/xmlext.py | 6 +----- pisi/pxml/xmlextcdom.py | 23 ++++++++++++++++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index cd5b61b6..883ced68 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -32,8 +32,6 @@ import types import formatter import sys from StringIO import StringIO -#import xml.dom.minidom as mdom -#from xml.parsers.expat import ExpatError import gettext __trans = gettext.translation('pisi', fallback=True) @@ -41,7 +39,6 @@ _ = __trans.ugettext # PiSi import pisi -# TODO: find the appropriate xmlext implementation and import from there from pisi.pxml.xmlext import * from pisi.pxml.xmlfile import XmlFile import pisi.context as ctx @@ -87,8 +84,7 @@ class LocalText(dict): self.tag ) else: for node in nodes: - #lang = getNodeAttribute(node, "xml:lang") - lang = node.getAttributeNS(XML_NS, 'lang') + lang = getNodeAttribute(node, 'xml:lang') c = getNodeText(node) if not c: errs.append(where + ': ' + _("'%s' language of tag '%s' is empty") % @@ -101,11 +97,9 @@ class LocalText(dict): def encode(self, node, errs): assert self.tag != '' for key in self.iterkeys(): - newnode = newNode(node, self.tag) - newnode.setAttributeNS(XML_NS, 'xml:lang', key) - newtext = newTextNode(node, self[key]) - newnode.appendChild(newtext) - node.appendChild(newnode) + newnode = addNode(node, self.tag) + setNodeAttribute(newnode, 'xml:lang', key) + addText(newnode, '', self[key]) #FIXME: maybe more appropriate for pisi.util @staticmethod diff --git a/pisi/pxml/xmlext.py b/pisi/pxml/xmlext.py index 43ca897c..0497cb0d 100644 --- a/pisi/pxml/xmlext.py +++ b/pisi/pxml/xmlext.py @@ -23,9 +23,5 @@ except: from xmlextcdom import * except: #raise Error('cannot find 4suite implementation') - print 'xmlext: cDomlette/piksemel implementation cannot be loaded, falling back to minidom' + print 'xmlext: piksemel or cDomlette implementation cannot be loaded, falling back to minidom' from xmlextmdom import * - -from xml.dom import XHTML_NAMESPACE, XML_NAMESPACE -XHTML_NS = unicode(XHTML_NAMESPACE) -XML_NS = unicode(XML_NAMESPACE) diff --git a/pisi/pxml/xmlextcdom.py b/pisi/pxml/xmlextcdom.py index 4fb5a11d..6ca19564 100644 --- a/pisi/pxml/xmlextcdom.py +++ b/pisi/pxml/xmlextcdom.py @@ -37,6 +37,10 @@ from Ft.Xml.Domlette import NoExtDtdReader import Ft.Lib import pisi +from xml.dom import XHTML_NAMESPACE, XML_NAMESPACE +XHTML_NS = unicode(XHTML_NAMESPACE) +XML_NS = unicode(XML_NAMESPACE) + class XmlError(pisi.Error): "named this way because the class if mostly used with an import *" pass @@ -66,10 +70,23 @@ def newTextNode(node, text): def getNodeAttribute(node, attrname): """get named attribute from DOM node""" - if not node.hasAttributeNS(None, attrname): - return None + if attrname.startswith('xml:'): + if node.hasAttributeNS(XML_NS, attrname[4:]): + return node.getAttributeNS(XML_NS, attrname[4:]) + else: + return None else: - return node.getAttributeNS(None, attrname) + if not node.hasAttributeNS(None, attrname): + return None + else: + return node.getAttributeNS(None, attrname) + +def setNodeAttribute(node, attrname, value): + """get named attribute from DOM node""" + if attrname.startswith('xml:'): + node.setAttributeNS(XML_NS, attrname, value) + else: + node.setAttributeNS(None, attrname, value) def getChildElts(node): """get only child elements"""