[CalendarServer-changes] [1359]
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/
Twisted
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 12 10:16:00 PDT 2007
Revision: 1359
http://trac.macosforge.org/projects/calendarserver/changeset/1359
Author: cdaboo at apple.com
Date: 2007-03-12 10:16:00 -0700 (Mon, 12 Mar 2007)
Log Message:
-----------
Speed up XML processing by only validating XML when reading data from the client.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.base.patch
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.parser.patch
Added Paths:
-----------
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc2518.patch
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc3744.patch
CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.util.patch
Modified: CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.base.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.base.patch 2007-03-09 22:21:43 UTC (rev 1358)
+++ CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.base.patch 2007-03-12 17:16:00 UTC (rev 1359)
@@ -2,8 +2,69 @@
===================================================================
--- twisted/web2/dav/element/base.py (revision 19773)
+++ twisted/web2/dav/element/base.py (working copy)
-@@ -145,21 +145,20 @@
+@@ -45,7 +45,7 @@
+ ]
+ import string
+-import StringIO
++import cStringIO as StringIO
+ import xml.dom.minidom
+
+ import datetime
+@@ -90,6 +90,35 @@
+ raise NotImplementedError("WebDAVElement subclass %s is not implemented."
+ % (self.__class__.__name__,))
+
++ my_children = []
++
++ allowPCDATA = self.allowed_children.has_key(PCDATAElement)
++
++ for child in children:
++ if child is None:
++ continue
++
++ if isinstance(child, (str, unicode)):
++ child = PCDATAElement(child)
++
++ if isinstance(child, PCDATAElement) and not allowPCDATA:
++ continue
++
++ my_children.append(child)
++
++ self.children = tuple(my_children)
++
++ self.attributes = attributes
++
++ def validate(self):
++
++ children = self.children
++ attributes = self.attributes
++
++ if self.allowed_children is None:
++ raise NotImplementedError("WebDAVElement subclass %s is not implemented."
++ % (self.__class__.__name__,))
++
+ #
+ # Validate that children are of acceptable types
+ #
+@@ -102,13 +131,10 @@
+ my_children = []
+
+ for child in children:
+- if child is None:
+- continue
+
+- if isinstance(child, (str, unicode)):
+- child = PCDATAElement(child)
+-
+ assert isinstance(child, (WebDAVElement, PCDATAElement)), "Not an element: %r" % (child,)
++
++ child.validate()
+
+ for allowed, (min, max) in allowed_children.items():
+ if type(allowed) == type and isinstance(child, allowed):
+@@ -145,21 +171,20 @@
+
if self.allowed_attributes:
for name in attributes:
- if name in self.allowed_attributes:
@@ -31,7 +92,7 @@
self.attributes = my_attributes
-@@ -190,14 +189,93 @@
+@@ -190,14 +215,93 @@
return child in self.children
def writeXML(self, output):
@@ -129,7 +190,17 @@
def element(self, document):
element = document.createElementNS(self.namespace, self.name)
-@@ -324,6 +402,22 @@
+@@ -285,6 +389,9 @@
+
+ self.data = data
+
++ def validate(self):
++ pass
++
+ def __str__(self):
+ return str(self.data)
+
+@@ -324,6 +431,22 @@
log.err("Invalid PCDATA: %r" % (self.data,))
raise
Modified: CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.parser.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.parser.patch 2007-03-09 22:21:43 UTC (rev 1358)
+++ CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.parser.patch 2007-03-12 17:16:00 UTC (rev 1359)
@@ -2,6 +2,15 @@
===================================================================
--- twisted/web2/dav/element/parser.py (revision 19773)
+++ twisted/web2/dav/element/parser.py (working copy)
+@@ -37,7 +37,7 @@
+ "WebDAVDocument",
+ ]
+
+-import StringIO
++import cStringIO as StringIO
+ import xml.dom.minidom
+ import xml.sax
+
@@ -106,6 +106,26 @@
"children" : [],
}]
@@ -59,3 +68,12 @@
self.stack.append({
"name" : name,
+@@ -194,6 +219,8 @@
+ except xml.sax.SAXParseException, e:
+ raise ValueError(e)
+
++ #handler.dom.root_element.validate()
++
+ return handler.dom
+
+ return parse
Added: CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc2518.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc2518.patch (rev 0)
+++ CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc2518.patch 2007-03-12 17:16:00 UTC (rev 1359)
@@ -0,0 +1,37 @@
+Index: twisted/web2/dav/element/rfc2518.py
+===================================================================
+--- twisted/web2/dav/element/rfc2518.py (revision 19773)
++++ twisted/web2/dav/element/rfc2518.py (working copy)
+@@ -59,8 +59,8 @@
+ """
+ name = "depth"
+
+- def __init__(self, *children, **attributes):
+- super(Depth, self).__init__(*children, **attributes)
++ def validate(self):
++ super(Depth, self).validate()
+
+ depth = str(self)
+ if depth not in ("0", "1", "infinity"):
+@@ -382,8 +382,8 @@
+ PCDATAElement: (0, 1),
+ }
+
+- def __init__(self, *children, **attributes):
+- super(KeepAlive, self).__init__(*children, **attributes)
++ def validate(self):
++ super(KeepAlive, self).validate()
+
+ type = None
+
+@@ -450,8 +450,8 @@
+ (dav_namespace, "prop" ): (0, 1),
+ }
+
+- def __init__(self, *children, **attributes):
+- super(PropertyFind, self).__init__(*children, **attributes)
++ def validate(self):
++ super(PropertyFind, self).validate()
+
+ if len(self.children) != 1:
+ raise ValueError(
Added: CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc3744.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc3744.patch (rev 0)
+++ CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.element.rfc3744.patch 2007-03-12 17:16:00 UTC (rev 1359)
@@ -0,0 +1,74 @@
+Index: twisted/web2/dav/element/rfc3744.py
+===================================================================
+--- twisted/web2/dav/element/rfc3744.py (revision 19773)
++++ twisted/web2/dav/element/rfc3744.py (working copy)
+@@ -131,8 +131,8 @@
+ (dav_namespace, "self" ): (0, 1),
+ }
+
+- def __init__(self, *children, **attributes):
+- super(Principal, self).__init__(*children, **attributes)
++ def validate(self):
++ super(Principal, self).validate()
+
+ if len(self.children) > 1:
+ raise ValueError(
+@@ -385,9 +385,14 @@
+ self.inherited = None
+ self.protected = False
+
++ my_children = []
++
+ for child in self.children:
+ namespace, name = child.qname()
+
++ if isinstance(child, PCDATAElement):
++ continue
++
+ if (namespace == dav_namespace):
+ if name in ("principal", "invert"):
+ if self.principal is not None:
+@@ -417,6 +422,10 @@
+ elif name == "protected":
+ self.protected = True
+
++ my_children.append(child)
++
++ self.children = tuple(my_children)
++
+ if self.principal is None:
+ raise ValueError(
+ "One of DAV:principal or DAV:invert is required in %s, got: %s"
+@@ -551,8 +560,8 @@
+ (dav_namespace, "property" ): (0, None),
+ }
+
+- def __init__(self, *children, **attributes):
+- super(RequiredPrincipal, self).__init__(*children, **attributes)
++ def validate(self):
++ super(RequiredPrincipal, self).validate()
+
+ type = None
+
+@@ -628,8 +637,8 @@
+
+ allowed_children = { WebDAVElement: (0, None) }
+
+- def __init__(self, *children, **attributes):
+- super(ACLPrincipalPropSet, self).__init__(*children, **attributes)
++ def validate(self):
++ super(ACLPrincipalPropSet, self).validate()
+
+ prop = False
+
+@@ -656,8 +665,8 @@
+ (dav_namespace, "prop" ): (0, 1),
+ }
+
+- def __init__(self, *children, **attributes):
+- super(PrincipalMatch, self).__init__(*children, **attributes)
++ def validate(self):
++ super(PrincipalMatch, self).validate()
+
+ # This element can be empty when uses in supported-report-set
+ if not len(self.children):
Added: CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.util.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.util.patch (rev 0)
+++ CalendarServer/branches/users/cdaboo/performance-1354/lib-patches/Twisted/twisted.web2.dav.util.patch 2007-03-12 17:16:00 UTC (rev 1359)
@@ -0,0 +1,15 @@
+Index: twisted/web2/dav/util.py
+===================================================================
+--- twisted/web2/dav/util.py (revision 19773)
++++ twisted/web2/dav/util.py (working copy)
+@@ -76,7 +76,9 @@
+
+ def parse(xml):
+ try:
+- return davxml.WebDAVDocument.fromString(xml)
++ doc = davxml.WebDAVDocument.fromString(xml)
++ doc.root_element.validate()
++ return doc
+ except ValueError:
+ log.err("Bad XML:\n%s" % (xml,))
+ raise
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070312/7ae311f0/attachment.html
More information about the calendarserver-changes
mailing list