[CalendarServer-changes] [7284] CalendarServer/trunk/twext/web2/dav/element/parser.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 4 09:42:29 PDT 2011
Revision: 7284
http://trac.macosforge.org/projects/calendarserver/changeset/7284
Author: cdaboo at apple.com
Date: 2011-04-04 09:42:28 -0700 (Mon, 04 Apr 2011)
Log Message:
-----------
Handle large chunks of multi-line character data more efficiently.
Modified Paths:
--------------
CalendarServer/trunk/twext/web2/dav/element/parser.py
Modified: CalendarServer/trunk/twext/web2/dav/element/parser.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/element/parser.py 2011-04-02 00:07:02 UTC (rev 7283)
+++ CalendarServer/trunk/twext/web2/dav/element/parser.py 2011-04-04 16:42:28 UTC (rev 7284)
@@ -96,6 +96,10 @@
def setDocumentLocator(self, locator): self.locator = locator
locator = None
+ def __init__(self):
+ xml.sax.handler.ContentHandler.__init__(self)
+ self._characterBuffer = None
+
def location(self):
return "line %d, column %d" % (self.locator.getLineNumber(), self.locator.getColumnNumber())
@@ -125,6 +129,12 @@
del(self.unknownElementClasses)
def startElementNS(self, name, qname, attributes):
+
+ if self._characterBuffer is not None:
+ pcdata = PCDATAElement("".join(self._characterBuffer))
+ self.stack[-1]["children"].append(pcdata)
+ self._characterBuffer = None
+
attributes_dict = {}
if attributes.getLength() is not 0:
@@ -153,6 +163,12 @@
})
def endElementNS(self, name, qname):
+
+ if self._characterBuffer is not None:
+ pcdata = PCDATAElement("".join(self._characterBuffer))
+ self.stack[-1]["children"].append(pcdata)
+ self._characterBuffer = None
+
# Pop the current element from the stack...
top = self.stack[-1]
del(self.stack[-1])
@@ -170,12 +186,11 @@
self.stack[-1]["children"].append(element)
def characters(self, content):
- # Coalesce adjacent PCDATAElements
- pcdata = PCDATAElement(content)
- if len(self.stack[-1]["children"]) and isinstance(self.stack[-1]["children"][-1], PCDATAElement):
- self.stack[-1]["children"][-1] = self.stack[-1]["children"][-1] + pcdata
- else:
- self.stack[-1]["children"].append(pcdata)
+
+ # Stash character data away in a list that we will "".join() when done
+ if self._characterBuffer is None:
+ self._characterBuffer = []
+ self._characterBuffer.append(content)
def ignorableWhitespace(self, whitespace):
self.characters(self, whitespace)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110404/a51b111e/attachment.html>
More information about the calendarserver-changes
mailing list