/// <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); }
public string[] GetModuleFilenames() { List <string> res = new List <string>(); PythonDictionary dict = (object)_engine.GetSysModule().GetVariable("modules") as PythonDictionary; if (dict != null) { foreach (var kvp in dict) { string key = kvp.Key as string; PythonModule module = kvp.Value as PythonModule; if (key != null && module != null) { var modDict = module.Get__dict__(); object file; if (modDict.TryGetValue("__file__", out file) && file != null) { res.Add(key); } } } } return(res.ToArray()); }
internal IMember MakeObject(object obj) { if (obj == null) { return(null); } lock (this) { IMember res; if (!_members.TryGetValue(obj, out res)) { PythonModule mod = obj as PythonModule; if (mod != null) { // FIXME: name object name; if (!mod.Get__dict__().TryGetValue("__name__", out name) || !(name is string)) { name = ""; } _members[obj] = res = new IronPythonModule(this, mod, (string)name); } PythonType type = obj as PythonType; if (type != null) { _members[obj] = res = GetTypeFromType(type.__clrtype__()); } BuiltinFunction func = obj as BuiltinFunction; if (func != null) { _members[obj] = res = new IronPythonBuiltinFunction(this, func); } BuiltinMethodDescriptor methodDesc = obj as BuiltinMethodDescriptor; if (methodDesc != null) { _members[obj] = res = new IronPythonBuiltinMethodDescriptor(this, methodDesc); } ReflectedField field = obj as ReflectedField; if (field != null) { return(new IronPythonField(this, field)); } ReflectedProperty prop = obj as ReflectedProperty; if (prop != null) { _members[obj] = res = new IronPythonProperty(this, prop); } ReflectedExtensionProperty extProp = obj as ReflectedExtensionProperty; if (extProp != null) { _members[obj] = res = new IronPythonExtensionProperty(this, extProp); } NamespaceTracker ns = obj as NamespaceTracker; if (ns != null) { _members[obj] = res = new IronPythonNamespace(this, ns); } Method method = obj as Method; if (method != null) { _members[obj] = res = new IronPythonGenericMember(this, method, PythonMemberType.Method); } var classMethod = obj as ClassMethodDescriptor; if (classMethod != null) { _members[obj] = res = new IronPythonGenericMember(this, classMethod, PythonMemberType.Method); } var typeSlot = obj as PythonTypeTypeSlot; if (typeSlot != null) { _members[obj] = res = new IronPythonGenericMember(this, typeSlot, PythonMemberType.Property); } ReflectedEvent eventObj = obj as ReflectedEvent; if (eventObj != null) { return(new IronPythonEvent(this, eventObj)); } if (res == null) { var genericTypeSlot = obj as PythonTypeSlot; if (genericTypeSlot != null) { _members[obj] = res = new IronPythonGenericMember(this, genericTypeSlot, PythonMemberType.Property); } } TypeGroup tg = obj as TypeGroup; if (tg != null) { _members[obj] = res = new PythonObject <TypeGroup>(this, tg); } var attrType = (obj != null) ? obj.GetType() : typeof(DynamicNull); if (attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) || attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double) || attrType.IsEnum || obj == null) { _members[obj] = res = new IronPythonConstant(this, obj); } if (res == null) { Debug.Assert(!(obj is bool)); _members[obj] = res = new PythonObject <object>(this, obj); } } return(res); } }
ExecInModule(string code, PythonModule module) { SourceUnit script = this.python.CreateSnippet(code, SourceCodeKind.Statements); script.Execute(new Scope(new DictionaryWrapper((IDictionary <object, object>)module.Get__dict__()))); }
PyModule_GetDict(IntPtr modulePtr) { PythonModule module = (PythonModule)this.Retrieve(modulePtr); return(this.Store(module.Get__dict__())); }
PyEval_GetBuiltins() { PythonModule __builtin__ = this.GetModule("__builtin__"); return(this.Store(__builtin__.Get__dict__())); }
ExecInModule(string code, PythonModule module) { SourceUnit script = this.python.CreateSnippet(code, SourceCodeKind.Statements); script.Execute(new Scope(module.Get__dict__())); }