common/registerers.py
branchtls-sprint
changeset 717 54b873918b48
parent 694 520661be60e4
child 718 f7011679437a
equal deleted inserted replaced
715:83228d379cbe 717:54b873918b48
    95             return True
    95             return True
    96         except AttributeError:
    96         except AttributeError:
    97             return False
    97             return False
    98 
    98 
    99 
    99 
   100 class id_registerer(priority_registerer):
       
   101     """register according to the "id" attribute of the wrapped class,
       
   102     refering to an entity type.
       
   103     
       
   104     * if the type is not Any and is not defined the application'schema,
       
   105       skip the wrapped class
       
   106     * if an object previously registered has the same .id attribute,
       
   107       kick it out
       
   108     * register
       
   109     """
       
   110     def do_it_yourself(self, registered):
       
   111         etype = self.vobject.id
       
   112         if etype != 'Any' and not self.schema.has_entity(etype):
       
   113             self.skip()
       
   114             return
       
   115         self.remove_equivalents(registered)
       
   116         return self.vobject
       
   117     
       
   118     def equivalent(self, other):
       
   119         return other.id == self.vobject.id
       
   120     
       
   121 
       
   122 __all__ = [cls.__name__ for cls in globals().values()
   100 __all__ = [cls.__name__ for cls in globals().values()
   123            if isinstance(cls, type) and issubclass(cls, registerer)
   101            if isinstance(cls, type) and issubclass(cls, registerer)
   124            and not cls is registerer]
   102            and not cls is registerer]