mercurial/demandload.py
author mpm@selenic.com
Wed, 08 Jun 2005 14:45:06 -0800
changeset 285 5a1e6d27f399
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
ui: add configuration file support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 ui: add configuration file support manifest hash: 2d0768a6f3797d4ccc870170b874bfd7aeb2f787 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp3TyywK+sNU5EO8RArYYAJ4+wWQmO7HIXewuGwB3a5DjiWGHwgCcDpeF Pz2lScnpVZPPbDQiS+VnBnM= =ffwc -----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