Esempio n. 1
0
        public static object load_source(CodeContext /*!*/ context, string /*!*/ name, string /*!*/ pathname)
        {
            if (name == null)
            {
                throw PythonOps.TypeError("load_source() argument 1 must be string, not None");
            }
            if (pathname == null)
            {
                throw PythonOps.TypeError("load_source() argument 2 must be string, not None");
            }

            // TODO: is this supposed to open PythonFile with Python-specific behavior?
            // we may need to insert additional layer to SourceUnit content provider if so
            PythonContext pc = PythonContext.GetContext(context);

            if (!pc.DomainManager.Platform.FileExists(pathname))
            {
                throw PythonOps.IOError("Couldn't find file: {0}", pathname);
            }

            SourceUnit sourceUnit = pc.CreateFileUnit(pathname, pc.DefaultEncoding, SourceCodeKind.File);

            return(pc.CompileModule(pathname, name, sourceUnit, ModuleOptions.Initialize));
        }
Esempio n. 2
0
        private static PythonModule /*!*/ LoadPythonSource(PythonContext /*!*/ context, string /*!*/ name, PythonFile /*!*/ file, string /*!*/ fileName)
        {
            SourceUnit sourceUnit = context.CreateSnippet(file.read(), String.IsNullOrEmpty(fileName) ? null : fileName, SourceCodeKind.File);

            return(context.CompileModule(fileName, name, sourceUnit, ModuleOptions.Initialize));
        }