view mercurial/demandload.py @ 325:ad87e19854a6

mdiff: reinstate new algorithm -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 mdiff: reinstate new algorithm This unreverts the new algorithm with a fix from Chris (s/len/lena) and adds some comments on what it's doing. manifest hash: 75fc1acee1926e57d495f67a44cd88d9555f2356 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCrf4UywK+sNU5EO8RAoRzAKCA2vpUAGNqTkDeba3YHo6XXht7VgCfXQK0 /j5yv5cucnsYezCdclpftOA= =FNMD -----END PGP SIGNATURE-----
author mpm@selenic.com
date Mon, 13 Jun 2005 13:43:48 -0800
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