[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/rotterdam/ Don't break the whole tree if we can't get the length of some branch

Shane Hathaway shane at zope.com
Tue Nov 16 16:38:04 EST 2004


Log message for revision 28464:
  Don't break the whole tree if we can't get the length of some branch
  

Changed:
  U   Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml
  U   Zope3/trunk/src/zope/app/rotterdam/xmlobject.py

-=-
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml	2004-11-16 21:36:59 UTC (rev 28463)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml	2004-11-16 21:38:04 UTC (rev 28464)
@@ -1 +1 @@
-<?xml version="1.0" ?><children><collection name="" length="2" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""><collection name="folder1_1" length="2" icon_url=""><collection name="folder1_1_1" length="1" icon_url=""></collection><collection name="folder1_1_2" length="0" icon_url=""/><item name="++etc++site" /></collection><collection name="folder1_2" length="1" icon_url=""/><item name="++etc++site" /></collection><collection name="folder2" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>
+<?xml version="1.0" ?><children><collection name="" length="2" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""><collection name="folder1_1" length="2" icon_url=""><collection name="folder1_1_1" length="1" icon_url=""></collection><collection name="folder1_1_2" length="0" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder1_2" length="1" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder2" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>

Modified: Zope3/trunk/src/zope/app/rotterdam/xmlobject.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/xmlobject.py	2004-11-16 21:36:59 UTC (rev 28463)
+++ Zope3/trunk/src/zope/app/rotterdam/xmlobject.py	2004-11-16 21:38:04 UTC (rev 28464)
@@ -21,6 +21,7 @@
 from zope.app.container.interfaces import IReadContainer
 from zope.app.traversing.api import getParents, getParent, traverse
 from zope.interface import Interface
+from zope.security.interfaces import Unauthorized, Forbidden
 from rfc822 import formatdate, time
 from xml.sax.saxutils import quoteattr
 
@@ -54,6 +55,15 @@
             result = icon.url()
         return result
 
+    def getLengthOf(self, item):
+        res = -1
+        if IReadContainer.providedBy(item):
+            try:
+                res = len(item)
+            except (Unauthorized, Forbidden):
+                pass
+        return res
+
     def children_utility(self, container):
         """Return an XML document that contains the children of an object."""
         result = []
@@ -71,10 +81,11 @@
                 continue
 
             iconUrl = self.getIconUrl(item)
-            if IReadContainer.providedBy(item):
+            item_len = self.getLengthOf(item)
+            if item_len >= 0:
                 result.append(xmlEscape(
                     '<collection name=%s length=%s icon_url=%s/>',
-                    name, len(item), iconUrl))
+                    name, item_len, iconUrl))
             else:
                 result.append(xmlEscape(
                     '<item name=%s icon_url=%s/>',
@@ -118,21 +129,23 @@
             for name in keys:
                 # Only include items we can traverse to
                 subItem = traverse(item, name, None)
-                if IReadContainer.providedBy(subItem):
-                    iconUrl = self.getIconUrl(subItem)
+                iconUrl = self.getIconUrl(subItem)
+                subitem_len = self.getLengthOf(subItem)
+                if subitem_len >= 0:
                     # the test below seems to be browken with the ++etc++site case
                     if subItem == oldItem:
                         subItems.append(xmlEscapeWithCData(
                             '<collection name=%s length=%s '
                             'icon_url=%s>%s</collection>', 
-                            name, len(subItem), iconUrl, result))
+                            name, subitem_len, iconUrl, result))
                     else:
                         subItems.append(xmlEscape(
                             '<collection name=%s length=%s '
                             'icon_url=%s/>',
-                            name, len(subItem), iconUrl))
+                            name, subitem_len, iconUrl))
                 else:
-                    subItems.append(xmlEscape('<item name=%s />', name))
+                    subItems.append(xmlEscape(
+                        '<item name=%s icon_url=%s />', name, iconUrl))
 
             result = ' '.join(subItems)
             oldItem = item



More information about the Zope3-Checkins mailing list