mercurial/demandload.py
author Edouard Gomez <ed.gomez@free.fr>
Tue, 09 Aug 2005 09:36:34 -0800
changeset 859 6390c377a9e6
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Trap OSError when deleting env vars On the other OS, it seems that case insensitivity for environment vars can bite users when using some unknown combination of python 2.4.1 and win2kSP4+minsys (and probably other vversions of these softwares). The best way to avoid problems in those weird cases is to ignore OSError exception during env var deletion.

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