mercurial/demandload.py
author mpm@selenic.com
Wed, 08 Jun 2005 11:01:18 -0800
changeset 282 97d83e7fbf2f
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
mpatch: properly NULL out return in lalloc -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 mpatch: properly NULL out return in lalloc From: K Thananchayan <thananck@yahoo.com> manifest hash: 69952cb34e184eff19e3abff7638eb3a446f4dca -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp0B+ywK+sNU5EO8RAuGdAJ4iZOnxExpZuhTjO0fcOFE9mNn/IACgjXbw 7mVqfBJeLbxViBorImLE12k= =A1Vj -----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