fix exception class, simply print warning when calling register_and_replace with an unregistered view stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 May 2009 18:22:24 +0200
branchstable
changeset 1943 fb557b616c80
parent 1942 84c8f54ec15a
child 1944 a1b1d4f8482c
fix exception class, simply print warning when calling register_and_replace with an unregistered view
vregistry.py
--- a/vregistry.py	Tue May 26 17:27:43 2009 +0200
+++ b/vregistry.py	Tue May 26 18:22:24 2009 +0200
@@ -237,7 +237,7 @@
                 # XXX automatic reloading management
                 try:
                     registry[obj.id].remove(registered)
-                except ValueError:
+                except KeyError:
                     self.warning('can\'t remove %s, no id %s in the %s registry',
                                  removed_id, obj.id, registryname)
                 except ValueError:
@@ -254,11 +254,14 @@
             replaced = replaced.classid()
         registryname = registryname or obj.__registry__
         registry = self.registry(registryname)
-        registered_objs = registry[obj.id]
+        registered_objs = registry.get(obj.id, ())
         for index, registered in enumerate(registered_objs):
             if registered.classid() == replaced:
                 del registry[obj.id][index]
                 break
+        else:
+            self.warning('trying to replace an unregistered view %s by %s',
+                         replaced, obj)
         self.register(obj, registryname=registryname)
 
     # dynamic selection methods ###############################################