[CMF-checkins] CVS: CMF/CMFCollector - util.py:1.16

Ken Manheimer klm@zope.com
Mon, 24 Dec 2001 11:50:04 -0500


Update of /cvs-repository/CMF/CMFCollector
In directory cvs.zope.org:/tmp/cvs-serv29226

Modified Files:
	util.py 
Log Message:
safeGetProperty(): Make it actually catch the various value-oriented
exceptions that MemberData.getProperty() may raise.  (We can't just
itemize the possible candidate exceptions because one is a string with
spaces, which isn't interned and hence object id won't match.)


=== CMF/CMFCollector/util.py 1.15 => 1.16 ===
     """Defaulting user.getProperty(), allowing for variant user folders."""
     try:
-        return userobj.getProperty(property, default)
-    except TypeError:
-        try:
-            # Some (eg, our LDAP user folder) support getProperty but not
-            # defaulting:
-            return userobj.getProperty(property)
-        except:
-            return default
-    except AttributeError:
-        # Some don't support getProperty:
-        return getattr(userobj, property, default)
+        if not hasattr(userobj, 'getProperty'):
+            return getattr(userobj, property, default)
+        else:
+            return userobj.getProperty(property, default)
+    except:
+        # We can't just itemize the possible candidate exceptions because one
+        # is a string with spaces, which isn't interned and hence object id
+        # won't match.  Sigh.
+        import sys
+        exc = sys.exc_info()[0]
+        if (exc == 'Property not found'
+            or isinstance(exc, TypeError)
+            or isinstance(exc, AttributeError)
+            or isinstance(exc, LookupError)):
+            try:
+                # Some (eg, our old LDAP user folder) support getProperty but
+                # not defaulting:
+                return userobj.getProperty(property)
+            except:
+                return default
+        else:
+            raise
 
 ##############################
 # WebText processing utilities