internal IMember MakeObject(ObjectIdentityHandle obj) { if (obj.IsNull) { return(null); } lock (this) { IMember res; if (_members.TryGetValue(obj, out res)) { return(res); } switch (_remote.GetObjectKind(obj)) { case ObjectKind.Module: res = new IronPythonModule(this, obj); break; case ObjectKind.Type: res = new IronPythonType(this, obj); break; case ObjectKind.ConstructorFunction: res = new IronPythonConstructorFunction(this, _remote.GetConstructorFunctionTargets(obj), GetTypeFromType(_remote.GetConstructorFunctionDeclaringType(obj))); break; case ObjectKind.BuiltinFunction: res = new IronPythonBuiltinFunction(this, obj); break; case ObjectKind.BuiltinMethodDesc: res = new IronPythonBuiltinMethodDescriptor(this, obj); break; case ObjectKind.ReflectedEvent: res = new IronPythonEvent(this, obj); break; case ObjectKind.ReflectedExtensionProperty: res = new IronPythonExtensionProperty(this, obj); break; case ObjectKind.ReflectedField: res = new IronPythonField(this, obj); break; case ObjectKind.ReflectedProperty: res = new IronPythonProperty(this, obj); break; case ObjectKind.TypeGroup: res = new IronPythonTypeGroup(this, obj); break; case ObjectKind.NamespaceTracker: res = new IronPythonNamespace(this, obj); break; case ObjectKind.Constant: res = new IronPythonConstant(this, obj); break; case ObjectKind.ClassMethod: res = new IronPythonGenericMember(this, obj, PythonMemberType.Method); break; case ObjectKind.Method: res = new IronPythonGenericMember(this, obj, PythonMemberType.Method); break; case ObjectKind.PythonTypeSlot: res = new IronPythonGenericMember(this, obj, PythonMemberType.Property); break; case ObjectKind.PythonTypeTypeSlot: res = new IronPythonGenericMember(this, obj, PythonMemberType.Property); break; case ObjectKind.Unknown: res = new PythonObject(this, obj); break; default: throw new InvalidOperationException(); } _members[obj] = res; return(res); } }
private void LoadModules() { var names = _engine.Operations.GetMember <PythonTuple>(_engine.GetSysModule(), "builtin_module_names"); foreach (string modName in names) { PythonModule mod = Importer.Import(_codeContextCls, modName, PythonOps.EmptyTuple, 0) as PythonModule; Debug.Assert(mod != null); _modules[modName] = new IronPythonModule(this, mod, modName); } }
private void LoadModules() { foreach (string modName in Remote.GetBuiltinModuleNames()) { try { var mod = Remote.ImportBuiltinModule(modName); if (modName != "__builtin__") { _modules[modName] = new IronPythonModule(this, mod, modName); } } catch { // importing can throw, ignore that module continue; } } }
private void LoadModules() { if (!string.IsNullOrEmpty(_factory.Configuration.PrefixPath)) { var dlls = PathUtils.GetAbsoluteDirectoryPath(_factory.Configuration.PrefixPath, "DLLs"); if (Directory.Exists(dlls)) { foreach (var dll in PathUtils.EnumerateFiles(dlls, "*.dll", recurse: false)) { try { var assem = Remote.LoadAssemblyFromFileWithPath(dll); if (assem != null) { Remote.AddAssembly(assem); } } catch (Exception ex) { Debug.Fail(ex.ToString()); } } } } foreach (string modName in Remote.GetBuiltinModuleNames()) { try { var mod = Remote.ImportBuiltinModule(modName); if (modName != "__builtin__") { _modules[modName] = new IronPythonModule(this, mod, modName); } } catch { // importing can throw, ignore that module continue; } } }
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); } }
internal IMember MakeObject(ObjectIdentityHandle obj) { if (obj.IsNull) { return null; } lock (this) { IMember res; if (_members.TryGetValue(obj, out res)) { return res; } switch (_remote.GetObjectKind(obj)) { case ObjectKind.Module: res = new IronPythonModule(this, obj); break; case ObjectKind.Type: res = new IronPythonType(this, obj); break; case ObjectKind.BuiltinFunction: res = new IronPythonBuiltinFunction(this, obj); break; case ObjectKind.BuiltinMethodDesc: res = new IronPythonBuiltinMethodDescriptor(this, obj); break; case ObjectKind.ReflectedEvent: res = new IronPythonEvent(this, obj); break; case ObjectKind.ReflectedExtensionProperty: res = new IronPythonExtensionProperty(this, obj); break; case ObjectKind.ReflectedField: res = new IronPythonField(this, obj); break; case ObjectKind.ReflectedProperty: res = new IronPythonProperty(this, obj); break; case ObjectKind.TypeGroup: res = new IronPythonTypeGroup(this, obj); break; case ObjectKind.NamespaceTracker: res = new IronPythonNamespace(this, obj); break; case ObjectKind.Constant: res = new IronPythonConstant(this, obj); break; case ObjectKind.ClassMethod: res = new IronPythonGenericMember(this, obj, PythonMemberType.Method); break; case ObjectKind.Method: res = res = new IronPythonGenericMember(this, obj, PythonMemberType.Method); break; case ObjectKind.PythonTypeSlot: res = new IronPythonGenericMember(this, obj, PythonMemberType.Property); break; case ObjectKind.PythonTypeTypeSlot: res = new IronPythonGenericMember(this, obj, PythonMemberType.Property); break; case ObjectKind.Unknown: res = new PythonObject(this, obj); break; default: throw new InvalidOperationException(); } _members[obj] = res; return res; } }