* goddamn foolish cdom
This commit is contained in:
+4
-10
@@ -32,8 +32,6 @@ import types
|
|||||||
import formatter
|
import formatter
|
||||||
import sys
|
import sys
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
#import xml.dom.minidom as mdom
|
|
||||||
#from xml.parsers.expat import ExpatError
|
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
@@ -41,7 +39,6 @@ _ = __trans.ugettext
|
|||||||
|
|
||||||
# PiSi
|
# PiSi
|
||||||
import pisi
|
import pisi
|
||||||
# TODO: find the appropriate xmlext implementation and import from there
|
|
||||||
from pisi.pxml.xmlext import *
|
from pisi.pxml.xmlext import *
|
||||||
from pisi.pxml.xmlfile import XmlFile
|
from pisi.pxml.xmlfile import XmlFile
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
@@ -87,8 +84,7 @@ class LocalText(dict):
|
|||||||
self.tag )
|
self.tag )
|
||||||
else:
|
else:
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
#lang = getNodeAttribute(node, "xml:lang")
|
lang = getNodeAttribute(node, 'xml:lang')
|
||||||
lang = node.getAttributeNS(XML_NS, 'lang')
|
|
||||||
c = getNodeText(node)
|
c = getNodeText(node)
|
||||||
if not c:
|
if not c:
|
||||||
errs.append(where + ': ' + _("'%s' language of tag '%s' is empty") %
|
errs.append(where + ': ' + _("'%s' language of tag '%s' is empty") %
|
||||||
@@ -101,11 +97,9 @@ class LocalText(dict):
|
|||||||
def encode(self, node, errs):
|
def encode(self, node, errs):
|
||||||
assert self.tag != ''
|
assert self.tag != ''
|
||||||
for key in self.iterkeys():
|
for key in self.iterkeys():
|
||||||
newnode = newNode(node, self.tag)
|
newnode = addNode(node, self.tag)
|
||||||
newnode.setAttributeNS(XML_NS, 'xml:lang', key)
|
setNodeAttribute(newnode, 'xml:lang', key)
|
||||||
newtext = newTextNode(node, self[key])
|
addText(newnode, '', self[key])
|
||||||
newnode.appendChild(newtext)
|
|
||||||
node.appendChild(newnode)
|
|
||||||
|
|
||||||
#FIXME: maybe more appropriate for pisi.util
|
#FIXME: maybe more appropriate for pisi.util
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
+1
-5
@@ -23,9 +23,5 @@ except:
|
|||||||
from xmlextcdom import *
|
from xmlextcdom import *
|
||||||
except:
|
except:
|
||||||
#raise Error('cannot find 4suite implementation')
|
#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 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 Ft.Lib
|
||||||
import pisi
|
import pisi
|
||||||
|
|
||||||
|
from xml.dom import XHTML_NAMESPACE, XML_NAMESPACE
|
||||||
|
XHTML_NS = unicode(XHTML_NAMESPACE)
|
||||||
|
XML_NS = unicode(XML_NAMESPACE)
|
||||||
|
|
||||||
class XmlError(pisi.Error):
|
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
|
||||||
@@ -66,10 +70,23 @@ def newTextNode(node, text):
|
|||||||
|
|
||||||
def getNodeAttribute(node, attrname):
|
def getNodeAttribute(node, attrname):
|
||||||
"""get named attribute from DOM node"""
|
"""get named attribute from DOM node"""
|
||||||
if not node.hasAttributeNS(None, attrname):
|
if attrname.startswith('xml:'):
|
||||||
return None
|
if node.hasAttributeNS(XML_NS, attrname[4:]):
|
||||||
|
return node.getAttributeNS(XML_NS, attrname[4:])
|
||||||
|
else:
|
||||||
|
return None
|
||||||
else:
|
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):
|
def getChildElts(node):
|
||||||
"""get only child elements"""
|
"""get only child elements"""
|
||||||
|
|||||||
Reference in New Issue
Block a user