/// <summary> /// Returns the sequence of results to display as children of this object in various debugger data views (Locals window etc). /// Unnamed results are displayed as [0], [1], .... /// </summary> /// <remarks> /// The default implementation enumerates object fields specified via either __dict__ or __slots__. Most derived classes /// will want to keep that as is, except for collections. /// </remarks> public virtual IEnumerable <PythonEvaluationResult> GetDebugChildren(ReprOptions reprOptions) { var children = GetDebugChildrenFromSlots(); var maybeDictProxy = __dict__; if (maybeDictProxy != null) { var dictProxy = maybeDictProxy.Value; if (!dictProxy.IsNull) { yield return(new PythonEvaluationResult(dictProxy, "__dict__")); PyDictObject dict = dictProxy.TryRead() as PyDictObject; if (dict != null) { children = children.Concat(GetDebugChildrenFromDict(dict)); } } } children = children.OrderBy(pair => pair.Name); foreach (var pair in children) { yield return(pair); } }
private IEnumerable <PythonEvaluationResult> GetDebugChildrenFromDict(PyDictObject dict) { foreach (var pair in dict.ReadElements()) { IPyBaseStringObject name = pair.Key as IPyBaseStringObject; if (name != null && !pair.Value.IsNull) { yield return(new PythonEvaluationResult(pair.Value, name.ToString())); } } }
private void LoadInitialPythonModules() { foreach (var interp in PyInterpreterState.GetInterpreterStates(_process)) { var modules = interp.modules.TryRead(); if (modules == null) { continue; } foreach (var moduleEntry in modules.ReadElements()) { PyModuleObject module = moduleEntry.Value.TryRead() as PyModuleObject; if (module == null) { continue; } PyDictObject md_dict = module.md_dict.TryRead(); if (md_dict == null) { continue; } foreach (var entry in md_dict.ReadElements()) { var name = (entry.Key as IPyBaseStringObject).ToStringOrNull(); if (name == "__file__") { var fileName = (entry.Value.TryRead() as IPyBaseStringObject).ToStringOrNull(); if (fileName != null && !fileName.EndsWithOrdinal(".pyd", ignoreCase: true)) { // Unlike co_filename, __file__ usually reflects the actual name of the file from which the module // was created, which will be .pyc rather than .py if it was available, so fix that up. if (fileName.EndsWithOrdinal(".pyc", ignoreCase: true)) { fileName = fileName.Substring(0, fileName.Length - 1); } new RemoteComponent.CreateModuleRequest { ModuleId = Guid.NewGuid(), FileName = fileName }.SendLower(_process); } } } } } }
/// <summary> /// Unwraps from <see cref="IPyObject"/> wrapper. /// </summary> /// <param name="pyDict"></param> /// <returns></returns> public static IDictionary <object, object> UnPy(this PyDictObject pyDict) => pyDict.Value.ToDictionary(kv => kv.Key.UnPy(), kv => kv.Value.UnPy());