mercurial/demandload.py
author mpm@selenic.com
Fri, 10 Jun 2005 09:36:38 -0800
changeset 306 f06a4a3b86a7
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Merge with TAH -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Merge with TAH manifest hash: 9ce3631dbbe2070e6e0b8a72e197790c911896e2 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCqc+mywK+sNU5EO8RAshrAJ4rqQXCJqB1rqgDQ5ujwOhFqqRuuQCdEUsK wpBCgWEm3xr9mxQ6rLLsihU= =Ozg9 -----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