def import_module(self, em, name=None, fn=None):
        assert not (name and fn)
        assert name or fn
        if name and name in BUILTIN_MODULES:
            return BUILTIN_MODULES[name].dup({})

        if name:
            assert '.' not in name
            fns = [os.path.join(dirname, name + ".py") for dirname in self._pythonpath]
        else:
            fns = [fn]
            assert fn.endswith(".py")
            name = os.path.basename(fn)[:-3]

        assert name
        for fn in fns:
            if os.path.exists(fn):
                if fn not in self._loaded_modules:
                    source = open(fn).read()
                    node = ast_utils.parse(source, fn)

                    self._load_module(em, node, name, fn)

                rtn = self._loaded_modules[fn]
                rtn.t.load(em)
                return rtn.dup({})

        raise Exception("don't know how to import '%s'" % name)