view mercurial/demandload.py @ 695:085a8145e151

Fixed tests. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Fixed tests. manifest hash: f6f36e6f95ea99efccc84dfa1d0af63d414a0eba -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFC1hsCW7P1GVgWeRoRAtbyAJoDpbSygoutryu3P/miCpX2Q/LA8gCgiClo P+1ZpH0gycio/V4CKmj5Hlo= =JVBT -----END PGP SIGNATURE-----
author Thomas Arendsen Hein <thomas@intevation.de>
date Thu, 14 Jul 2005 08:57:54 +0100
parents 3db700146536
children f3abe0bdccdd
line wrap: on
line source

def demandload(scope, modules):
    class d:
        def __getattr__(self, name):
            mod = self.__dict__["mod"]
            scope = self.__dict__["scope"]
            scope[mod] = __import__(mod, scope, scope, [])
            return getattr(scope[mod], name)

    for m in modules.split():
        dl = d()
        dl.mod = m
        dl.scope = scope
        scope[m] = dl