PyModule_New(string name) { PythonModule module = new PythonModule(); module.Get__dict__()["__name__"] = name; module.Get__dict__()["__doc__"] = ""; return this.Store(module); }
Py_InitModule4(string name, IntPtr methodsPtr, string doc, IntPtr selfPtr, int apiver) { name = this.FixImportName(name); PythonDictionary methodTable = new PythonDictionary(); PythonModule module = new PythonModule(); this.AddModule(name, module); this.CreateModulesContaining(name); PythonDictionary __dict__ = module.Get__dict__(); __dict__["__doc__"] = doc; __dict__["__name__"] = name; string __file__ = this.importFiles.Peek(); __dict__["__file__"] = __file__; List __path__ = new List(); if (__file__ != null) { __path__.append(Path.GetDirectoryName(__file__)); } __dict__["__path__"] = __path__; __dict__["_dispatcher"] = new Dispatcher(this, methodTable, selfPtr); StringBuilder moduleCode = new StringBuilder(); moduleCode.Append(CodeSnippets.USEFUL_IMPORTS); CallableBuilder.GenerateFunctions(moduleCode, methodsPtr, methodTable); this.ExecInModule(moduleCode.ToString(), module); return this.Store(module); }
public BuiltinModule(PythonModule module, ProjectState projectState, bool showClr) : base(new LazyDotNetDict(new object[] { module }, projectState, showClr)) { object name; if (!module.Get__dict__().TryGetValue("__name__", out name) || !(name is string)) { _name = String.Empty; } else { _name = name as string; } }
/// <summary> /// List all of the members in a PythonModule /// </summary> /// <param name="module">A reference to the module</param> /// <param name="name">The name of the module</param> /// <returns>A list of completion data for the module</returns> public List<IronPythonCompletionData> EnumerateMembers(PythonModule module, string name) { var items = new List<IronPythonCompletionData>(); var d = module.Get__dict__(); foreach (var member in d) { if ( member.Value is BuiltinFunction ) { items.Add(new IronPythonCompletionData( (string) member.Key, name, false, IronPythonCompletionData.CompletionType.METHOD, this)); } else { items.Add(new IronPythonCompletionData((string)member.Key, name, false, IronPythonCompletionData.CompletionType.FIELD, this)); } } return items; }
CreateModule(string name) { PythonModule module = this.GetModule(name); if (module == null) { module = new PythonModule(); module.Get__dict__()["__name__"] = name; this.AddModule(name, module); } return module; }
ExecInModule(string code, PythonModule module) { SourceUnit script = this.python.CreateSnippet(code, SourceCodeKind.Statements); script.Execute(new Scope(module.Get__dict__())); }