From 95f4ef224ad298b0f375c9329a37d07bfb52b06c Mon Sep 17 00:00:00 2001 From: trgiangvu Date: Sun, 12 May 2024 13:25:10 +0700 Subject: [PATCH] Update: Pyrevit Compatible stubs --- Src/IronPython.Modules/ResourceMetaPathImporter.cs | 9 +++++++-- Src/IronPython/Runtime/Operations/PythonOps.cs | 13 +++++++++++++ Src/IronPython/Runtime/Operations/StringOps.cs | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Src/IronPython.Modules/ResourceMetaPathImporter.cs b/Src/IronPython.Modules/ResourceMetaPathImporter.cs index a3c444e2d..1353de8b8 100644 --- a/Src/IronPython.Modules/ResourceMetaPathImporter.cs +++ b/Src/IronPython.Modules/ResourceMetaPathImporter.cs @@ -69,6 +69,11 @@ fully qualified (dotted) module name. It returns the importer with the importer protocol." )] public object find_module(CodeContext /*!*/ context, string fullname, params object[] args) { + PythonContext pc = context.LanguageContext; + + if (pc.BuiltinModules.TryGetValue(fullname, out Type type)) + return null; + var packedName = MakeFilename(fullname); foreach (var entry in SearchOrder) { @@ -106,7 +111,7 @@ public object load_module(CodeContext /*!*/ context, string fullname) { ModuleOptions.None, out script); var dict = mod.__dict__; - // we do these here because we don't want CompileModule to initialize the module until we've set + // we do these here because we don't want CompileModule to initialize the module until we've set // up some additional stuff dict.Add("__name__", fullname); dict.Add("__loader__", this); @@ -174,7 +179,7 @@ private byte[] GetCodeFromData(CodeContext /*!*/ context, bool isbytecode, Packe if (data != null) { if (isbytecode) { - // would put in code to unmarshal the bytecode here... + // would put in code to unmarshal the bytecode here... } else { code = data; diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index 689e9ebf2..a6f507ec9 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -1673,6 +1673,19 @@ public static PythonList MakeEmptyList() { return new PythonList(); } + /// + /// Python runtime helper to create an instance of Python List object. + /// + /// List has the initial provided capacity. + /// + /// Initial list capacity + /// + [NoSideEffects] + [EditorBrowsable(EditorBrowsableState.Never)] + public static PythonList MakeEmptyList(int capacity) { + return new PythonList(capacity); + } + /// /// Python runtime helper to create an instance of Tuple /// diff --git a/Src/IronPython/Runtime/Operations/StringOps.cs b/Src/IronPython/Runtime/Operations/StringOps.cs index 9a3e98a7c..fd8d02c4b 100644 --- a/Src/IronPython/Runtime/Operations/StringOps.cs +++ b/Src/IronPython/Runtime/Operations/StringOps.cs @@ -391,6 +391,11 @@ public static string capitalize([NotNone] this string self) { return Char.ToUpper(self[0], CultureInfo.InvariantCulture) + self.Substring(1).ToLower(CultureInfo.InvariantCulture); } + /// + /// Returns a copy of this string converted to lowercase + /// + public static string casefold([NotNone] this string self) => lower(self); + // default fillchar (padding char) is a space public static string center([NotNone] this string self, int width) { return center(self, width, ' ');