mercurial/demandload.py
author mpm@selenic.com
Wed, 08 Jun 2005 10:47:10 -0800
changeset 278 777e388c06d6
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
unidiff: handle empty diffs more gracefully -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 unidiff: handle empty diffs more gracefully manifest hash: e2030f7e55dc333ba0cd5b0847d1f1a08e3c5d64 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCpz0uywK+sNU5EO8RAnt4AJ9pyaS6/xNnlhCUocq3m0HbCwHJ/gCgrP/H IvBJtq1eXvRedfitF25vBgw= =pd5n -----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