mercurial/demandload.py
author Thomas Arendsen Hein <thomas@intevation.de>
Thu, 16 Jun 2005 06:22:14 +0100
changeset 379 c8bd9793446d
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Updated TODO -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Updated TODO manifest hash: ee511d64271017729839799c4ea066b2046579d9 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCsQyGW7P1GVgWeRoRAifOAJ9hUcsM2+OPfjichr083EAhKfMSSACeIhtK d3QXNNmPpmk6lLFFFujImEU= =kCMx -----END PGP SIGNATURE-----

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