view mercurial/demandload.py @ 471:4c7f687e4313

Minor annotate performance tweaks -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Minor annotate performance tweaks manifest hash: 2edd508182c7b3dfb2e0b9b90baebdd364cb29f0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCvfQeywK+sNU5EO8RAsYSAJ0R8SuWnyQxVgauoaEuezOe3Taq/wCbBnEs +VG0LNrXnQM9khQyc0+pCeg= =U5gX -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sat, 25 Jun 2005 16:17:34 -0800
parents 3db700146536
children f3abe0bdccdd
line wrap: on
line source

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