safety belt inside _accept_interfaces() as it might be called on a class that doesn't provide (yet) __select__ tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 17 Feb 2009 23:44:58 +0100
branchtls-sprint
changeset 725 2f3e6afabdb5
parent 724 1ecba333cfb0
child 726 88a74f590986
safety belt inside _accept_interfaces() as it might be called on a class that doesn't provide (yet) __select__
common/registerers.py
--- a/common/registerers.py	Tue Feb 17 23:43:08 2009 +0100
+++ b/common/registerers.py	Tue Feb 17 23:44:58 2009 +0100
@@ -14,10 +14,16 @@
 from cubicweb.selectors import implements
 
 def _accepts_interfaces(obj):
-    impl = obj.__select__.search_selector(implements)
-    if impl:
-        return sorted(impl.expected_ifaces)
-    return sorted(getattr(obj, 'accepts_interfaces', ()))
+    try:
+        return sorted(obj.accepts_interfaces)
+    except AttributeError:
+        try:
+            impl = obj.__select__.search_selector(implements)
+            if impl:
+                return sorted(impl.expected_ifaces)
+        except AttributeError:
+            pass # old-style vobject classes with no accepts_interfaces
+        return ()
 
 
 class priority_registerer(registerer):
@@ -68,7 +74,7 @@
     """
     def do_it_yourself(self, registered):
         # if object is accepting interface, we have register it now and
-        # remove it latter if no object is implementing accepted interfaces
+        # remove it later if no object is implementing accepted interfaces
         if _accepts_interfaces(self.vobject):
             return self.vobject
         self.remove_equivalents(registered)