[CalendarServer-changes] [2282] CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.element. parser.patch

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 3 16:29:08 PDT 2008


Revision: 2282
          http://trac.macosforge.org/projects/calendarserver/changeset/2282
Author:   wsanchez at apple.com
Date:     2008-04-03 16:29:07 -0700 (Thu, 03 Apr 2008)

Log Message:
-----------
Get rid of nested subclasses of WebDAVElement.

Modified Paths:
--------------
    CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.element.parser.patch

Modified: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.element.parser.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.element.parser.patch	2008-04-03 22:28:04 UTC (rev 2281)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.element.parser.patch	2008-04-03 23:29:07 UTC (rev 2282)
@@ -11,7 +11,7 @@
  import xml.dom.minidom
  import xml.sax
  
-@@ -106,6 +106,26 @@
+@@ -106,6 +106,12 @@
              "children"   : [],
          }]
  
@@ -21,54 +21,42 @@
 +        # multiple times in a document.
 +        self.unknownElementClasses = {}
 +
-+        # New-style classes keep weak references to all subclasses.
-+        # As a result, the subclasses we create continue to effect the
-+        # footprint of WebDAVUnknownElement even after they are
-+        # deallocated, up to the maximum number of subclasses that exist
-+        # simultaneously.  The number of such weak references doesn't appear
-+        # to decrease.  In order to avoid growing it unneccessarily, create a
-+        # subclass for use by this document, subclass the new class instead,
-+        # and then delete it when we're done, thereby adding only one weak
-+        # reference to WebDAVUnknownElement's list.
-+        # http://trac.macosforge.org/projects/calendarserver/ticket/101
-+        class UnknownElement (WebDAVUnknownElement):
-+            pass
-+        self.unknownElementClass = UnknownElement
-+
      def endDocument(self):
          top = self.stack[-1]
  
-@@ -115,6 +135,8 @@
+@@ -115,6 +121,7 @@
          assert len(top["children"]) is 1, "Must have exactly one root element, got %d" % len(top["children"])
  
          self.dom = WebDAVDocument(top["children"][0])
 +        del(self.unknownElementClasses)
-+        del(self.unknownElementClass)
  
      def startElementNS(self, name, qname, attributes):
          attributes_dict = {}
-@@ -125,13 +147,16 @@
+@@ -125,13 +132,17 @@
  
          tag_namespace, tag_name = name
  
 -        if (name not in elements_by_tag_name):
 -            class UnknownElement (WebDAVUnknownElement):
+-                namespace = tag_namespace
+-                name      = tag_name
+-            element_class = UnknownElement
 +        if name in elements_by_tag_name:
 +            element_class = elements_by_tag_name[name]
 +        elif name in self.unknownElementClasses:
 +            element_class = self.unknownElementClasses[name]
-+        else:
-+            class UnknownElement (self.unknownElementClass):
-                 namespace = tag_namespace
-                 name      = tag_name
-             element_class = UnknownElement
--        else:
+         else:
 -            element_class = elements_by_tag_name[name]
-+            self.unknownElementClasses[name] = UnknownElement
++            def element_class(*args, **kwargs):
++                element = WebDAVUnknownElement(*args, **kwargs)
++                element.namespace = tag_namespace
++                element.name      = tag_name
++                return element
++            self.unknownElementClasses[name] = element_class
  
          self.stack.append({
              "name"       : name,
-@@ -158,7 +183,12 @@
+@@ -158,7 +169,12 @@
          self.stack[-1]["children"].append(element)
  
      def characters(self, content):
@@ -82,7 +70,7 @@
  
      def ignorableWhitespace(self, whitespace):
          self.characters(self, whitespace)
-@@ -194,6 +224,8 @@
+@@ -194,6 +210,8 @@
              except xml.sax.SAXParseException, e:
                  raise ValueError(e)
  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080403/379a99f7/attachment.html


More information about the calendarserver-changes mailing list