* goddamn foolish cdom
This commit is contained in:
+4
-10
@@ -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
|
||||
|
||||
+1
-5
@@ -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)
|
||||
|
||||
+20
-3
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user