From 125fcb6c90e957a57453f002114350e710ab9b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sun, 14 Jun 2026 20:04:30 -0400 Subject: [PATCH] Unify 3.4 and 3.6 --- eng/scripts/generate.py | 7 +++-- eng/scripts/generate_encoding_aliases.py | 28 ++++++++++++++++--- src/core/IronPython/IronPython.csproj | 1 + .../Runtime/Operations/StringOps.Generated.cs | 8 +++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/eng/scripts/generate.py b/eng/scripts/generate.py index eb0489d24..921de6451 100755 --- a/eng/scripts/generate.py +++ b/eng/scripts/generate.py @@ -120,10 +120,13 @@ def finally_block(self): self.writeline("} finally {") self.indent() - def exit_block(self, text=None, **kw): + def exit_block(self, text=None): self.dedent() if text: - self.writeline("} " + text, **kw) + if text == ";": + self.writeline("}" + text) + else: + self.writeline("} " + text) else: self.writeline('}') diff --git a/eng/scripts/generate_encoding_aliases.py b/eng/scripts/generate_encoding_aliases.py index b2bd549bf..9b020e4d0 100644 --- a/eng/scripts/generate_encoding_aliases.py +++ b/eng/scripts/generate_encoding_aliases.py @@ -3,6 +3,8 @@ # See the LICENSE file in the project root for more information. import encodings +import itertools +import sys from generate import generate @@ -10,17 +12,35 @@ def gen_aliases(cw): cw.writeline("// Based on encodings.aliases") cw.enter_block("var d = new Dictionary") - for codec in sorted(set(encodings.aliases.aliases.values())): + aliases = encodings.aliases.aliases + aliases_36 = { + "kz_1048": "kz1048", + "rk1048": "kz1048", + "strk1048_2002": "kz1048", + } + codecs_36 = {v: "PYTHON_36_OR_GREATER" for v in aliases_36.values()} + if sys.version_info >= (3, 6): + for k, v in aliases_36.items(): + assert aliases[k] == v + aliases = {**aliases, **aliases_36} + + sorted_aliases = sorted(aliases.items(), key=lambda kv: (kv[1], kv[0])) + for codec, group in itertools.groupby(sorted_aliases, key=lambda kv: kv[1]): + condition = codecs_36.get(codec) + e = encodings.search_function(codec) - if e is None or not e._is_text_encoding or e.name == "mbcs": + if not condition and (e is None or not e._is_text_encoding or e.name == "mbcs"): continue cw.writeline() - aliases = sorted(alias for alias, aliased_codec in encodings.aliases.aliases.items() if aliased_codec == codec) - for alias in aliases: + if condition: + cw.writeline("#if {0}".format(condition)) + for alias, codec in group: qalias = '"{0}"'.format(alias) qcodec = '"{0}"'.format(codec) cw.writeline('{{ {0:24} , {1:24} }},'.format(qalias, qcodec)) + if condition: + cw.writeline("#endif") cw.exit_block(";") diff --git a/src/core/IronPython/IronPython.csproj b/src/core/IronPython/IronPython.csproj index 8a511ee02..96bd77a1e 100644 --- a/src/core/IronPython/IronPython.csproj +++ b/src/core/IronPython/IronPython.csproj @@ -63,6 +63,7 @@ + diff --git a/src/core/IronPython/Runtime/Operations/StringOps.Generated.cs b/src/core/IronPython/Runtime/Operations/StringOps.Generated.cs index 80275902f..964dcf3f7 100644 --- a/src/core/IronPython/Runtime/Operations/StringOps.Generated.cs +++ b/src/core/IronPython/Runtime/Operations/StringOps.Generated.cs @@ -253,6 +253,12 @@ static partial class CodecsInfo { { "cskoi8r" , "koi8_r" }, + #if PYTHON_36_OR_GREATER + { "kz_1048" , "kz1048" }, + { "rk1048" , "kz1048" }, + { "strk1048_2002" , "kz1048" }, + #endif + { "8859" , "latin_1" }, { "cp819" , "latin_1" }, { "csisolatin1" , "latin_1" }, @@ -316,7 +322,7 @@ static partial class CodecsInfo { { "utf8" , "utf_8" }, { "utf8_ucs2" , "utf_8" }, { "utf8_ucs4" , "utf_8" }, - } ; + }; // *** END GENERATED CODE ***