示例#1
0
        private static object ImportNested(PythonModule mod, string name)
        {
            object ret;

            if (mod.TryGetAttr(mod, SymbolTable.StringToId(name), out ret))
            {
                return(ret);
            }

            string baseName;
            List   path     = ResolveSearchPath(mod, out baseName);
            string fullName = CreateFullName(baseName, name);

            if (TryGetExistingModule(mod.SystemState, fullName, out ret))
            {
                return(ret);
            }

            if (path != null)
            {
                ret = ImportFromPath(mod.SystemState, name, fullName, path);
                if (ret != null)
                {
                    mod.SetAttr(mod, SymbolTable.StringToId(name), ret);
                    return(ret);
                }
            }

            throw Ops.ImportError("cannot import {0} from {1}", name, mod.ModuleName);
        }
示例#2
0
        private static object LoadPackageFromSource(SystemState state, string fullName, string dirname)
        {
            string       fullPath = Path.GetFullPath(dirname);
            List         __path__ = Ops.MakeList(fullPath);
            PythonModule mod      = LoadFromSource(state, fullName, Path.Combine(dirname, "__init__.py"));

            mod.SetAttr(DefaultContext.Default, SymbolTable.Path, __path__);
            return(InitializeModule(fullName, mod));
        }
示例#3
0
        private static object ImportTopFrom(PythonModule mod, string name)
        {
            string baseName;
            List   path = ResolveSearchPath(mod, out baseName);

            if (path == null)
            {
                return(null);
            }

            object ret = ImportFromPath(mod.SystemState, name, CreateFullName(baseName, name), path);

            if (ret != null)
            {
                mod.SetAttr(mod, SymbolTable.StringToId(name), ret);
                return(ret);
            }
            return(null);
        }