diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-01-09 11:18:05 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-01-09 11:18:05 +0100 |
commit | f2651f0c26d6716173b05dbc38fb89e79d2d4781 (patch) | |
tree | 396321e6ad017349d0fa8d9fa9d7017c87407054 | |
parent | c0308a32ff35d921e75c5cff68df14aeacd4b9f9 (diff) | |
download | logilab-common-f2651f0c26d6716173b05dbc38fb89e79d2d4781.tar.gz |
[registry]?use register_all when no registration callback defined. Closes #111011
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | registry.py | 29 |
2 files changed, 17 insertions, 14 deletions
@@ -17,6 +17,8 @@ ChangeLog for logilab.common __abstract__ explicitly is better and notion of registered object 'name' is now somewhat fuzzy + - use register_all when no registration callback defined (closes #111011) + * loggin_ext: on windows, use colorama to display colored logs, if available (closes #107436) 2012-11-14 -- 0.58.3 diff --git a/registry.py b/registry.py index 7876085..fec35ad 100644 --- a/registry.py +++ b/registry.py @@ -597,9 +597,10 @@ class RegistryStore(dict): 'modname expected to be a module name (ie string), got %r' % modname for obj in objects: if self.is_registrable(obj) and obj.__module__ == modname and not obj in butclasses: - oid = obj.__regid__ - if oid and not obj.__dict__.get('__abstract__'): - self.register(obj, oid=oid) + if isinstance(obj, type): + self._load_ancestors_then_object(modname, obj, butclasses) + else: + self.register(obj) def register(self, obj, registryname=None, oid=None, clear=False): """register `obj` implementation into `registryname` or @@ -744,17 +745,17 @@ class RegistryStore(dict): if hasattr(module, 'registration_callback'): module.registration_callback(self) else: - for obj in vars(module).values(): - if self.is_registrable(obj) and obj.__module__ == module.__name__: - if isinstance(obj, type): - self._load_ancestors_then_object(module.__name__, obj) - else: - self.register(obj) - - def _load_ancestors_then_object(self, modname, objectcls): + self.register_all(vars(module).itervalues(), module.__name__) + + def _load_ancestors_then_object(self, modname, objectcls, butclasses=()): """handle class registration according to rules defined in :meth:`load_module` """ + # backward compat, we used to allow whatever else than classes + if not isinstance(objectcls, type): + if self.is_registrable(objectcls) and objectcls.__module__ == modname: + self.register(objectcls) + return # imported classes objmodname = objectcls.__module__ if objmodname != modname: @@ -767,15 +768,15 @@ class RegistryStore(dict): self.load_file(self._toloadmods[objmodname], objmodname) return # ensure object hasn't been already processed - clsid = '%s.%s' % (objmodname, objectcls.__name__) + clsid = '%s.%s' % (modname, objectcls.__name__) if clsid in self._loadedmods[modname]: return self._loadedmods[modname][clsid] = objectcls # ensure ancestors are registered for parent in objectcls.__bases__: - self._load_ancestors_then_object(modname, parent) + self._load_ancestors_then_object(modname, parent, butclasses) # ensure object is registrable - if not self.is_registrable(objectcls): + if objectcls in butclasses or not self.is_registrable(objectcls): return # backward compat reg = self.setdefault(obj_registries(objectcls)[0]) |