upgrade apipkg.py to fix a potential recursive import issue

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-21 20:06:50 +01:00
parent 14feeb9ca1
commit aa6d2a37e6
2 changed files with 11 additions and 5 deletions

View File

@ -2,6 +2,8 @@ Changes between 1.2.1 and 1.2.0
=====================================
- fix issue63: assume <40 columns to be a bogus terminal width, default to 80
- update apipkg.py to fix an issue where recursive imports might
unnecessarily break importing
- fix plugin links
Changes between 1.2 and 1.1.1

View File

@ -8,16 +8,17 @@ see http://pypi.python.org/pypi/apipkg
import sys
from types import ModuleType
__version__ = "1.0b4"
__version__ = "1.0b6"
def initpkg(pkgname, exportdefs):
""" initialize given package from the export definitions. """
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname)
oldmod = sys.modules[pkgname]
mod.__file__ = getattr(oldmod, '__file__', None)
mod.__version__ = getattr(oldmod, '__version__', None)
mod.__path__ = getattr(oldmod, '__path__', None)
mod.__loader__ = getattr(oldmod, '__loader__', None)
mod.__version__ = getattr(oldmod, '__version__', '0')
for name in ('__path__', '__loader__'):
if hasattr(oldmod, name):
setattr(mod, name, getattr(oldmod, name))
sys.modules[pkgname] = mod
def importobj(modpath, attrname):
@ -71,7 +72,10 @@ class ApiModule(ModuleType):
else:
result = importobj(modpath, attrname)
setattr(self, name, result)
del self.__map__[name]
try:
del self.__map__[name]
except KeyError:
pass # in a recursive-import situation a double-del can happen
return result
__getattr__ = __makeattr