Commit a5981724 authored by Nicolas Delaby's avatar Nicolas Delaby

* rename file variable to file_object

* use expatreader to parse xml trees for better performances 
parent 022e2bc0
......@@ -11,8 +11,8 @@ Patched by Nicolas Delaby nicolas@nexedi.com to support namespaces
# 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 @@ class Unmarshaller(ElementTreeContentHandler):
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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment