mercurial/demandload.py
author mpm@selenic.com
Thu, 30 Jun 2005 08:44:22 -0800
changeset 531 0e9234a1a3f6
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Hashing speed-up -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hashing speed-up - From Chris Mason manifest hash: c10091676647015b907a3ddce4dc629cb485de36 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCxCFmywK+sNU5EO8RAjiEAJ98eBaomWIUtT7DAm5dCbcAOe1I7gCdFl/E AvepXnn+tLC2Grk9et2sL3M= =spZz -----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