mercurial/demandload.py
author Thomas Arendsen Hein <thomas@intevation.de>
Tue, 14 Jun 2005 08:01:18 +0100
changeset 347 a0b2758edee7
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Cleaned up show_changeset() -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Cleaned up show_changeset() manifest hash: f9aa30cfa465d7aa096abb652ec04f1a5ec1072f -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCroC+W7P1GVgWeRoRAuheAJsEx7eFaoHoz+YejLIiN4BSfE117ACfYdM6 NQGNTp3ftUSuVpcMLvV8A1U= =8Ihb -----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