mercurial/demandload.py
author mpm@selenic.com
Wed, 15 Jun 2005 21:23:07 -0800
changeset 380 c72ccad3e3b8
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Merge with TAH -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Merge with TAH manifest hash: 18cf61cc2b6611d74ffc490b6b733537b879d69e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCsQy7ywK+sNU5EO8RAoi/AKCC0XbK73oemLr52KOQWEK4WlE9pgCgkk/8 C/m6MZJqlOKhIT4jazPwngU= =ECGy -----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