[Erp5-report] r31260 nicolas - /erp5/trunk/utils/xml_marshaller/xml_marshaller/
nobody at svn.erp5.org
nobody at svn.erp5.org
Sat Dec 12 14:21:36 CET 2009
Author: nicolas
Date: Sat Dec 12 14:21:36 2009
New Revision: 31260
URL: http://svn.erp5.org?rev=31260&view=rev
Log:
* rename file variable to file_object
* use expatreader to parse xml trees for better performances
Modified:
erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py
Modified: erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py?rev=31260&r1=31259&r2=31260&view=diff
==============================================================================
--- erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] Sat Dec 12 14:21:36 2009
@@ -11,8 +11,8 @@
# dumps(value), loads(string)
from types import ClassType
import sys
+from xml.sax import make_parser
from xml.sax.saxutils import escape, unescape
-import lxml.sax
from lxml.sax import ElementTreeContentHandler
from lxml import etree
from lxml.builder import ElementMaker
@@ -293,31 +293,31 @@
self.kw = {}
self.accumulating_chars = 0
- def load(self, file):
+ def load(self, file_object):
"Unmarshal one value, reading it from a file-like object"
# Instantiate a new object; unmarshalling isn't thread-safe
# because it modifies attributes on the object.
m = self.__class__()
- return m._load(file)
+ return m._load(file_object)
def loads(self, string):
"Unmarshal one value from a string"
# Instantiate a new object; unmarshalling isn't thread-safe
# because it modifies attributes on the object.
m = self.__class__()
- file = StringIO(string)
- return m._load(file)
+ file_object = StringIO(string)
+ return m._load(file_object)
# Basic unmarshalling routine; it creates a SAX XML parser,
# registers self as the SAX handler, parses it, and returns
# the only thing on the data stack.
- def _load(self, file):
+ def _load(self, file_object):
"Read one value from the open file"
- lxml.sax.saxify(lxml.etree.parse(file), self)
- #p = saxexts.make_parser()
- #p.setDocumentHandler(self)
- #p.parseFile(file)
+ parser = make_parser()
+ parser.setFeature('http://xml.org/sax/features/namespaces', True)
+ parser.setContentHandler(self)
+ parser.parse(file_object)
assert len(self.data_stack) == 1
# leave the instance in a steady state
result = self.data_stack[0]
More information about the Erp5-report
mailing list