def content():
"""Return one dictionary that contains all dictionaries of the
module. By making a function rather than part of the namespace,
the content can be updated dynamically. Should not make any
difference in speed for normal use."""
global _contentCache
if _contentCache is not None:
return _contentCache
# import each time by looking at the files
mods = glob.glob1(__path__[0], '*.py')
_contentCache = content = {}
for m in mods:
if m[:2] == '__':
continue
modname = __name__ + '.' + m[:-3]
path = string.split(modname, '.')
module = __import__(modname)
# find the deepest submodule
for modname in path[1:]:
module = getattr(module, modname)
if hasattr(module, 'content'):
content.update(module.content)
continue
else:
if DEBUG:
print __name__, 'submodule ', module, 'misses a content dictionary.'
return content
评论列表
文章目录