no need for a classid class method
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 13 Aug 2009 11:56:49 +0200
changeset 2821 526f44213b70
parent 2820 66b31686d92b
child 2822 f26578339214
no need for a classid class method
appobject.py
vregistry.py
--- a/appobject.py	Thu Aug 13 11:54:19 2009 +0200
+++ b/appobject.py	Thu Aug 13 11:56:49 2009 +0200
@@ -240,11 +240,6 @@
     __select__ = yes()
 
     @classmethod
-    def classid(cls):
-        """returns a unique identifier for the appobject"""
-        return '%s.%s' % (cls.__module__, cls.__name__)
-
-    @classmethod
     def __registered__(cls, registry):
         """called by the registry when the appobject has been registered.
 
--- a/vregistry.py	Thu Aug 13 11:54:19 2009 +0200
+++ b/vregistry.py	Thu Aug 13 11:56:49 2009 +0200
@@ -54,6 +54,10 @@
     return _toload
 
 
+def classid(cls):
+    """returns a unique identifier for an appobject class"""
+    return '%s.%s' % (cls.__module__, cls.__name__)
+
 class Registry(dict):
 
     def __init__(self, config):
@@ -88,11 +92,11 @@
         # XXXFIXME this is a duplication of unregister()
         # remove register_and_replace in favor of unregister + register
         # or simplify by calling unregister then register here
-        if hasattr(replaced, 'classid'):
-            replaced = replaced.classid()
+        if not isinstance(replaced, basestring):
+            replaced = classid(replaced)
         registered_objs = self.get(obj.id, ())
         for index, registered in enumerate(registered_objs):
-            if registered.classid() == replaced:
+            if classid(registered) == replaced:
                 del registered_objs[index]
                 break
         else:
@@ -101,11 +105,11 @@
         self.register(obj)
 
     def unregister(self, obj):
-        oid = obj.classid()
+        oid = classid(obj)
         for registered in self.get(obj.id, ()):
             # use classid() to compare classes because vreg will probably
             # have its own version of the class, loaded through execfile
-            if registered.classid() == oid:
+            if classid(registered) == oid:
                 # XXX automatic reloading management
                 self[obj.id].remove(registered)
                 break