mercurial/demandload.py
author mpm@selenic.com
Tue, 21 Jun 2005 19:07:13 -0800
changeset 413 a3b5347c22cd
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
remove double assignment -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 remove double assignment spotted by Goffredo Baroncelli manifest hash: a0406a618ce5b2b9b10073b29960d594094aa3ed -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuNXhywK+sNU5EO8RAh9yAJ0aVTnxsumDAdF3JORp1pDebxeE8wCgisdG vf/JwxHbQEqGrefU1nbs928= =NDGW -----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