[Checkins] SVN: Sandbox/malthe/chameleon.core/ Use a custom simple BufferIO class for the lxml.etree parser instead of standard StringIO.
Hanno Schlichting
plone at hannosch.info
Thu Nov 20 09:59:59 EST 2008
Log message for revision 93157:
Use a custom simple BufferIO class for the lxml.etree parser instead of standard StringIO.
Changed:
U Sandbox/malthe/chameleon.core/CHANGES.txt
U Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py
-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-20 14:52:25 UTC (rev 93156)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-20 14:59:58 UTC (rev 93157)
@@ -4,6 +4,9 @@
HEAD
~~~~
+- Use a custom simple BufferIO class for the lxml.etree parser instead of
+ standard StringIO. [hannosch]
+
- This was the wrong fix, however; what needed to be changed is that
the class of the marker isntance must be available at
module-scope. [malthe]
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py 2008-11-20 14:52:25 UTC (rev 93156)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/etree.py 2008-11-20 14:59:58 UTC (rev 93157)
@@ -1,14 +1,12 @@
import htmlentitydefs
import config
import utils
-import cgi
-import copy
import base64
import xml.parsers.expat
-from StringIO import StringIO
from cPickle import dumps, loads
+
def import_elementtree():
try:
import xml.etree.ElementTree as ET
@@ -65,6 +63,18 @@
XMLSyntaxError = lxml.etree.XMLSyntaxError
+ class BufferIO(list):
+ write = list.append
+
+ def __init__(self, value):
+ self.append(value)
+
+ def tell(self):
+ return 0
+
+ def getvalue(self):
+ return ''.join(self)
+
class ElementBase(lxml.etree.ElementBase):
def tostring(self):
return lxml.etree.tostring(self)
@@ -208,8 +218,8 @@
for key, mapping in element_mapping.items():
ns_lookup(key).update(mapping)
-
- tree = lxml.etree.parse(StringIO(body), parser)
+
+ tree = lxml.etree.parse(BufferIO(body), parser)
root = tree.getroot()
convert_cdata_section(root)
More information about the Checkins
mailing list