Exemplo n.º 1
0
        public static object load_module(CodeContext /*!*/ context, string name, PythonFile file, string filename, PythonTuple /*!*/ description)
        {
            if (description == null)
            {
                throw PythonOps.TypeError("load_module() argument 4 must be 3-item sequence, not None");
            }
            else if (description.__len__() != 3)
            {
                throw PythonOps.TypeError("load_module() argument 4 must be sequence of length 3, not {0}", description.__len__());
            }

            PythonContext pythonContext = PythonContext.GetContext(context);

            // already loaded? do reload()
            PythonModule module = pythonContext.GetModuleByName(name);

            if (module != null)
            {
                Importer.ReloadModule(context, module, file);
                return(module);
            }

            int type = PythonContext.GetContext(context).ConvertToInt32(description[2]);

            switch (type)
            {
            case PythonSource:
                return(LoadPythonSource(pythonContext, name, file, filename));

            case CBuiltin:
                return(LoadBuiltinModule(context, name));

            case PackageDirectory:
                return(LoadPackageDirectory(pythonContext, name, filename));

            default:
                throw PythonOps.TypeError("don't know how to import {0}, (type code {1}", name, type);
            }
        }