From 45c15175809198ebf2c1807698ded6ca94b1568c Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 10 Jan 2010 13:54:55 +0100 Subject: [PATCH] porting latest apipkg --HG-- branch : trunk --- py/apipkg.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/py/apipkg.py b/py/apipkg.py index 97b611a5e..602376aaa 100644 --- a/py/apipkg.py +++ b/py/apipkg.py @@ -55,7 +55,8 @@ class ApiModule(ModuleType): return '' % (self.__name__, " ".join(l)) return '' % (self.__name__,) - def __getattr__(self, name): + def __makeattr(self, name): + """lazily compute value for name or raise AttributeError if unknown.""" target = None if '__onfirstaccess__' in self.__map__: target = self.__map__.pop('__onfirstaccess__') @@ -73,6 +74,8 @@ class ApiModule(ModuleType): del self.__map__[name] return result + __getattr__ = __makeattr + def __dict__(self): # force all the content of the module to be loaded when __dict__ is read dictdescr = ModuleType.__dict__['__dict__'] @@ -80,6 +83,9 @@ class ApiModule(ModuleType): if dict is not None: hasattr(self, 'some') for name in self.__all__: - hasattr(self, name) # force attribute load, ignore errors + try: + self.__makeattr(name) + except AttributeError: + pass return dict __dict__ = property(__dict__)