mercurial/demandload.py
author chad.netzer@gmail.com
Sun, 10 Jul 2005 16:14:56 -0800
changeset 674 6513ba7d858a
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Make consistent use of str.startswith() in conditionals. # HG changeset patch # User chad.netzer@gmail.com # Node ID 45db196de89a15fd045cd789f701b0180fd276f1 # Parent fafc16f705b6cb413897577b67918af55e1baafe Make consistent use of str.startswith() in conditionals.

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