mercurial/demandload.py
author mpm@selenic.com
Wed, 08 Jun 2005 17:38:46 -0800
changeset 292 09364bcebdf0
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Make most file opening binary -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Make most file opening binary This should make Windows happier manifest hash: 4a906f7c55d8af4e962385c645852d0b3d858b42 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp52mywK+sNU5EO8RAtOzAJwK8MOtl3B0MDAXyJDnDFt9mHNINwCfVdRG 8z35hXvIJhz3sRo0ogdUZ0s= =eM45 -----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