]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99482: remove `jython` compatibility parts from stdlib and tests (#99484)
authorNikita Sobolev <mail@sobolevn.me>
Fri, 23 Dec 2022 20:17:24 +0000 (23:17 +0300)
committerGitHub <noreply@github.com>
Fri, 23 Dec 2022 20:17:24 +0000 (14:17 -0600)
20 files changed:
Doc/whatsnew/3.12.rst
Lib/copy.py
Lib/pickle.py
Lib/platform.py
Lib/site.py
Lib/test/support/__init__.py
Lib/test/support/os_helper.py
Lib/test/test___all__.py
Lib/test/test_codeop.py
Lib/test/test_exceptions.py
Lib/test/test_import/__init__.py
Lib/test/test_platform.py
Lib/test/test_strftime.py
Lib/test/test_unicode.py
Lib/types.py
Lib/unittest/loader.py
Lib/xml/sax/__init__.py
Lib/xml/sax/_exceptions.py
Lib/xml/sax/expatreader.py
Misc/NEWS.d/next/Library/2022-11-14-19-58-36.gh-issue-99482.XmZyUr.rst [new file with mode: 0644]

index 617fadd83f8fd3fc6751ee4013b1e8ceef86ade3..69f97debd694083b794ec49196b12c1c9d50f9a5 100644 (file)
@@ -955,6 +955,9 @@ Removed
   ``SSTATE_INTERNED_IMMORTAL`` macro.
   (Contributed by Victor Stinner in :gh:`85858`.)
 
+* Remove ``Jython`` compatibility hacks from several stdlib modules and tests.
+  (Contributed by Nikita Sobolev in :gh:`99482`.)
+
 * Remove ``_use_broken_old_ctypes_structure_semantics_`` flag
   from :mod:`ctypes` module.
   (Contributed by Nikita Sobolev in :gh:`99285`.)
index 1b276afe08121ecaca04a199446c22e77dd19bf4..6e8c19bc652d126014d3e2e9d2d54059ad742387 100644 (file)
@@ -56,11 +56,6 @@ class Error(Exception):
     pass
 error = Error   # backward compatibility
 
-try:
-    from org.python.core import PyStringMap
-except ImportError:
-    PyStringMap = None
-
 __all__ = ["Error", "copy", "deepcopy"]
 
 def copy(x):
@@ -120,9 +115,6 @@ d[dict] = dict.copy
 d[set] = set.copy
 d[bytearray] = bytearray.copy
 
-if PyStringMap is not None:
-    d[PyStringMap] = PyStringMap.copy
-
 del d, t
 
 def deepcopy(x, memo=None, _nil=[]):
@@ -231,8 +223,6 @@ def _deepcopy_dict(x, memo, deepcopy=deepcopy):
         y[deepcopy(key, memo)] = deepcopy(value, memo)
     return y
 d[dict] = _deepcopy_dict
-if PyStringMap is not None:
-    d[PyStringMap] = _deepcopy_dict
 
 def _deepcopy_method(x, memo): # Copy instance methods
     return type(x)(x.__func__, deepcopy(x.__self__, memo))
@@ -301,4 +291,4 @@ def _reconstruct(x, memo, func, args,
                 y[key] = value
     return y
 
-del types, weakref, PyStringMap
+del types, weakref
index f027e0432045b762f9661a90d380ebb9f8c1d8d8..15fa5f6e5799321add3e1b154dad164ad5ea8759 100644 (file)
@@ -98,12 +98,6 @@ class _Stop(Exception):
     def __init__(self, value):
         self.value = value
 
-# Jython has PyStringMap; it's a dict subclass with string keys
-try:
-    from org.python.core import PyStringMap
-except ImportError:
-    PyStringMap = None
-
 # Pickle opcodes.  See pickletools.py for extensive docs.  The listing
 # here is in kind-of alphabetical order of 1-character pickle code.
 # pickletools groups them by purpose.
@@ -972,8 +966,6 @@ class _Pickler:
         self._batch_setitems(obj.items())
 
     dispatch[dict] = save_dict
-    if PyStringMap is not None:
-        dispatch[PyStringMap] = save_dict
 
     def _batch_setitems(self, items):
         # Helper to batch up SETITEMS sequences; proto >= 1 only
index 6745321e31c279e458b279bb0980cfb3ed9cb33f..b018046f5268d1ee585ee1f7e97f21d735346a1f 100755 (executable)
@@ -1290,7 +1290,7 @@ def platform(aliased=0, terse=0):
         else:
             platform = _platform(system, release, version, csd)
 
-    elif system in ('Linux',):
+    elif system == 'Linux':
         # check for libc vs. glibc
         libcname, libcversion = libc_ver()
         platform = _platform(system, release, machine, processor,
index 69670d9d7f22300c8694528c44594b6328888d1f..7faf1c6f6af22315dc875c816bb2fe0b05525db8 100644 (file)
@@ -404,12 +404,7 @@ def setquit():
 def setcopyright():
     """Set 'copyright' and 'credits' in builtins"""
     builtins.copyright = _sitebuiltins._Printer("copyright", sys.copyright)
-    if sys.platform[:4] == 'java':
-        builtins.credits = _sitebuiltins._Printer(
-            "credits",
-            "Jython is maintained by the Jython developers (www.jython.org).")
-    else:
-        builtins.credits = _sitebuiltins._Printer("credits", """\
+    builtins.credits = _sitebuiltins._Printer("credits", """\
     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
     for supporting Python development.  See www.python.org for more information.""")
     files, dirs = [], []
index b7186057990ac12755b4759a705f1a00f448fde8..ff736f1c2db8e2acddc70ea8a1e9cb5c59fc1f4a 100644 (file)
@@ -505,6 +505,7 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
 requires_legacy_unicode_capi = unittest.skipUnless(unicode_legacy_string,
                         'requires legacy Unicode C API')
 
+# Is not actually used in tests, but is kept for compatibility.
 is_jython = sys.platform.startswith('java')
 
 is_android = hasattr(sys, 'getandroidapilevel')
@@ -736,8 +737,6 @@ def gc_collect():
     """
     import gc
     gc.collect()
-    if is_jython:
-        time.sleep(0.1)
     gc.collect()
     gc.collect()
 
index f37a442aa0e6c8e64bdd4d06e42c6c5fd4db2c9f..2d4356a1191b1e04ce59f09f3f3450875041d983 100644 (file)
@@ -11,11 +11,7 @@ import warnings
 
 
 # Filename used for testing
-if os.name == 'java':
-    # Jython disallows @ in module names
-    TESTFN_ASCII = '$test'
-else:
-    TESTFN_ASCII = '@test'
+TESTFN_ASCII = '@test'
 
 # Disambiguate TESTFN for parallel testing, while letting it remain a valid
 # module name.
index 1ec83cb0b1440158efc2a7cdeba208d5a52e7015..ecf73b3ad1beb571869583804a3eb5c062b7a983 100644 (file)
@@ -100,10 +100,9 @@ class AllTest(unittest.TestCase):
             '__future__',
         ])
 
-        if not sys.platform.startswith('java'):
-            # In case _socket fails to build, make this test fail more gracefully
-            # than an AttributeError somewhere deep in CGIHTTPServer.
-            import _socket
+        # In case _socket fails to build, make this test fail more gracefully
+        # than an AttributeError somewhere deep in CGIHTTPServer.
+        import _socket
 
         ignored = []
         failed_imports = []
index d7b51be642e46f72bdcf4d8490d5c256e9bee5c0..6966c2ffd811b87db5315137dc0199bf8b96893a 100644 (file)
@@ -2,47 +2,18 @@
    Test cases for codeop.py
    Nick Mathewson
 """
-import sys
 import unittest
 import warnings
-from test import support
 from test.support import warnings_helper
 
 from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
-import io
-
-if support.is_jython:
-
-    def unify_callables(d):
-        for n,v in d.items():
-            if hasattr(v, '__call__'):
-                d[n] = True
-        return d
 
 class CodeopTests(unittest.TestCase):
 
     def assertValid(self, str, symbol='single'):
         '''succeed iff str is a valid piece of code'''
-        if support.is_jython:
-            code = compile_command(str, "<input>", symbol)
-            self.assertTrue(code)
-            if symbol == "single":
-                d,r = {},{}
-                saved_stdout = sys.stdout
-                sys.stdout = io.StringIO()
-                try:
-                    exec(code, d)
-                    exec(compile(str,"<input>","single"), r)
-                finally:
-                    sys.stdout = saved_stdout
-            elif symbol == 'eval':
-                ctx = {'a': 2}
-                d = { 'value': eval(code,ctx) }
-                r = { 'value': eval(str,ctx) }
-            self.assertEqual(unify_callables(r),unify_callables(d))
-        else:
-            expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
-            self.assertEqual(compile_command(str, "<input>", symbol), expected)
+        expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
+        self.assertEqual(compile_command(str, "<input>", symbol), expected)
 
     def assertIncomplete(self, str, symbol='single'):
         '''succeed iff str is the start of a valid piece of code'''
@@ -62,16 +33,12 @@ class CodeopTests(unittest.TestCase):
         av = self.assertValid
 
         # special case
-        if not support.is_jython:
-            self.assertEqual(compile_command(""),
-                             compile("pass", "<input>", 'single',
-                                     PyCF_DONT_IMPLY_DEDENT))
-            self.assertEqual(compile_command("\n"),
-                             compile("pass", "<input>", 'single',
-                                     PyCF_DONT_IMPLY_DEDENT))
-        else:
-            av("")
-            av("\n")
+        self.assertEqual(compile_command(""),
+                            compile("pass", "<input>", 'single',
+                                    PyCF_DONT_IMPLY_DEDENT))
+        self.assertEqual(compile_command("\n"),
+                            compile("pass", "<input>", 'single',
+                                    PyCF_DONT_IMPLY_DEDENT))
 
         av("a = 1")
         av("\na = 1")
index 65a3a8a48a880951f5a4d047b3e0ddb95203d76c..f629321458d8aeb5fcc2f2557054dfa15fda0146 100644 (file)
@@ -360,10 +360,9 @@ class ExceptionTests(unittest.TestCase):
             self.assertRaises(SystemError, _testcapi.raise_exception,
                               InvalidException, 1)
 
-        if not sys.platform.startswith('java'):
-            test_capi1()
-            test_capi2()
-            test_capi3()
+        test_capi1()
+        test_capi2()
+        test_capi3()
 
     def test_WindowsError(self):
         try:
index 6c5b80bcee6c24a45e6d8687b0872830d72f0a86..1e4429ed7efe1340a478f884ef074e7768806a61 100644 (file)
@@ -20,7 +20,7 @@ from unittest import mock
 
 from test.support import os_helper
 from test.support import (
-    STDLIB_DIR, is_jython, swap_attr, swap_item, cpython_only, is_emscripten,
+    STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
     is_wasi)
 from test.support.import_helper import (
     forget, make_legacy_pyc, unlink, unload, DirsOnSysPath, CleanImport)
@@ -163,10 +163,7 @@ class ImportTests(unittest.TestCase):
         def test_with_extension(ext):
             # The extension is normally ".py", perhaps ".pyw".
             source = TESTFN + ext
-            if is_jython:
-                pyc = TESTFN + "$py.class"
-            else:
-                pyc = TESTFN + ".pyc"
+            pyc = TESTFN + ".pyc"
 
             with open(source, "w", encoding='utf-8') as f:
                 print("# This tests Python's ability to import a",
index 3992faf8e5cd5bf0002a13952938e9c6db330149..72942dda3424181b0e973fbafd5093b18494e770 100644 (file)
@@ -329,7 +329,7 @@ class PlatformTest(unittest.TestCase):
 
     def test_java_ver(self):
         res = platform.java_ver()
-        if sys.platform == 'java':
+        if sys.platform == 'java':  # Is never actually checked in CI
             self.assertTrue(all(res))
 
     def test_win32_ver(self):
index be43c49e40aa50f2f22813da64b86a677bb8e6e8..cebfc8927862a72735fa17040937bc2d67731a6c 100644 (file)
@@ -54,14 +54,10 @@ class StrftimeTest(unittest.TestCase):
         self.now = now
 
     def setUp(self):
-        try:
-            import java
-            java.util.Locale.setDefault(java.util.Locale.US)
-        except ImportError:
-            from locale import setlocale, LC_TIME
-            saved_locale = setlocale(LC_TIME)
-            setlocale(LC_TIME, 'C')
-            self.addCleanup(setlocale, LC_TIME, saved_locale)
+        from locale import setlocale, LC_TIME
+        saved_locale = setlocale(LC_TIME)
+        setlocale(LC_TIME, 'C')
+        self.addCleanup(setlocale, LC_TIME, saved_locale)
 
     def test_strftime(self):
         now = time.time()
index 5465d35534f111f8a3db420226aa8eb41be6673b..79360f5549e42d9ca04cc069f72e21737cc89d93 100644 (file)
@@ -94,88 +94,86 @@ class UnicodeTest(string_tests.CommonTest,
         self.assertNotEqual(r"\u0020", " ")
 
     def test_ascii(self):
-        if not sys.platform.startswith('java'):
-            # Test basic sanity of repr()
-            self.assertEqual(ascii('abc'), "'abc'")
-            self.assertEqual(ascii('ab\\c'), "'ab\\\\c'")
-            self.assertEqual(ascii('ab\\'), "'ab\\\\'")
-            self.assertEqual(ascii('\\c'), "'\\\\c'")
-            self.assertEqual(ascii('\\'), "'\\\\'")
-            self.assertEqual(ascii('\n'), "'\\n'")
-            self.assertEqual(ascii('\r'), "'\\r'")
-            self.assertEqual(ascii('\t'), "'\\t'")
-            self.assertEqual(ascii('\b'), "'\\x08'")
-            self.assertEqual(ascii("'\""), """'\\'"'""")
-            self.assertEqual(ascii("'\""), """'\\'"'""")
-            self.assertEqual(ascii("'"), '''"'"''')
-            self.assertEqual(ascii('"'), """'"'""")
-            latin1repr = (
-                "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
-                "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
-                "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
-                "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
-                "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
-                "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
-                "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9"
-                "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7"
-                "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5"
-                "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3"
-                "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1"
-                "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef"
-                "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd"
-                "\\xfe\\xff'")
-            testrepr = ascii(''.join(map(chr, range(256))))
-            self.assertEqual(testrepr, latin1repr)
-            # Test ascii works on wide unicode escapes without overflow.
-            self.assertEqual(ascii("\U00010000" * 39 + "\uffff" * 4096),
-                             ascii("\U00010000" * 39 + "\uffff" * 4096))
-
-            class WrongRepr:
-                def __repr__(self):
-                    return b'byte-repr'
-            self.assertRaises(TypeError, ascii, WrongRepr())
+        # Test basic sanity of repr()
+        self.assertEqual(ascii('abc'), "'abc'")
+        self.assertEqual(ascii('ab\\c'), "'ab\\\\c'")
+        self.assertEqual(ascii('ab\\'), "'ab\\\\'")
+        self.assertEqual(ascii('\\c'), "'\\\\c'")
+        self.assertEqual(ascii('\\'), "'\\\\'")
+        self.assertEqual(ascii('\n'), "'\\n'")
+        self.assertEqual(ascii('\r'), "'\\r'")
+        self.assertEqual(ascii('\t'), "'\\t'")
+        self.assertEqual(ascii('\b'), "'\\x08'")
+        self.assertEqual(ascii("'\""), """'\\'"'""")
+        self.assertEqual(ascii("'\""), """'\\'"'""")
+        self.assertEqual(ascii("'"), '''"'"''')
+        self.assertEqual(ascii('"'), """'"'""")
+        latin1repr = (
+            "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
+            "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
+            "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
+            "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
+            "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
+            "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
+            "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9"
+            "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7"
+            "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5"
+            "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3"
+            "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1"
+            "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef"
+            "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd"
+            "\\xfe\\xff'")
+        testrepr = ascii(''.join(map(chr, range(256))))
+        self.assertEqual(testrepr, latin1repr)
+        # Test ascii works on wide unicode escapes without overflow.
+        self.assertEqual(ascii("\U00010000" * 39 + "\uffff" * 4096),
+                            ascii("\U00010000" * 39 + "\uffff" * 4096))
+
+        class WrongRepr:
+            def __repr__(self):
+                return b'byte-repr'
+        self.assertRaises(TypeError, ascii, WrongRepr())
 
     def test_repr(self):
-        if not sys.platform.startswith('java'):
-            # Test basic sanity of repr()
-            self.assertEqual(repr('abc'), "'abc'")
-            self.assertEqual(repr('ab\\c'), "'ab\\\\c'")
-            self.assertEqual(repr('ab\\'), "'ab\\\\'")
-            self.assertEqual(repr('\\c'), "'\\\\c'")
-            self.assertEqual(repr('\\'), "'\\\\'")
-            self.assertEqual(repr('\n'), "'\\n'")
-            self.assertEqual(repr('\r'), "'\\r'")
-            self.assertEqual(repr('\t'), "'\\t'")
-            self.assertEqual(repr('\b'), "'\\x08'")
-            self.assertEqual(repr("'\""), """'\\'"'""")
-            self.assertEqual(repr("'\""), """'\\'"'""")
-            self.assertEqual(repr("'"), '''"'"''')
-            self.assertEqual(repr('"'), """'"'""")
-            latin1repr = (
-                "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
-                "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
-                "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
-                "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
-                "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
-                "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
-                "\\x9c\\x9d\\x9e\\x9f\\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9"
-                "\xaa\xab\xac\\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
-                "\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5"
-                "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
-                "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1"
-                "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
-                "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd"
-                "\xfe\xff'")
-            testrepr = repr(''.join(map(chr, range(256))))
-            self.assertEqual(testrepr, latin1repr)
-            # Test repr works on wide unicode escapes without overflow.
-            self.assertEqual(repr("\U00010000" * 39 + "\uffff" * 4096),
-                             repr("\U00010000" * 39 + "\uffff" * 4096))
-
-            class WrongRepr:
-                def __repr__(self):
-                    return b'byte-repr'
-            self.assertRaises(TypeError, repr, WrongRepr())
+        # Test basic sanity of repr()
+        self.assertEqual(repr('abc'), "'abc'")
+        self.assertEqual(repr('ab\\c'), "'ab\\\\c'")
+        self.assertEqual(repr('ab\\'), "'ab\\\\'")
+        self.assertEqual(repr('\\c'), "'\\\\c'")
+        self.assertEqual(repr('\\'), "'\\\\'")
+        self.assertEqual(repr('\n'), "'\\n'")
+        self.assertEqual(repr('\r'), "'\\r'")
+        self.assertEqual(repr('\t'), "'\\t'")
+        self.assertEqual(repr('\b'), "'\\x08'")
+        self.assertEqual(repr("'\""), """'\\'"'""")
+        self.assertEqual(repr("'\""), """'\\'"'""")
+        self.assertEqual(repr("'"), '''"'"''')
+        self.assertEqual(repr('"'), """'"'""")
+        latin1repr = (
+            "'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
+            "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
+            "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
+            "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
+            "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
+            "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
+            "\\x9c\\x9d\\x9e\\x9f\\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9"
+            "\xaa\xab\xac\\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
+            "\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5"
+            "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
+            "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1"
+            "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
+            "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd"
+            "\xfe\xff'")
+        testrepr = repr(''.join(map(chr, range(256))))
+        self.assertEqual(testrepr, latin1repr)
+        # Test repr works on wide unicode escapes without overflow.
+        self.assertEqual(repr("\U00010000" * 39 + "\uffff" * 4096),
+                            repr("\U00010000" * 39 + "\uffff" * 4096))
+
+        class WrongRepr:
+            def __repr__(self):
+                return b'byte-repr'
+        self.assertRaises(TypeError, repr, WrongRepr())
 
     def test_iterators(self):
         # Make sure unicode objects have an __iter__ method
@@ -684,8 +682,7 @@ class UnicodeTest(string_tests.CommonTest,
 
     def test_isupper(self):
         super().test_isupper()
-        if not sys.platform.startswith('java'):
-            self.checkequalnofix(False, '\u1FFc', 'isupper')
+        self.checkequalnofix(False, '\u1FFc', 'isupper')
         self.assertTrue('\u2167'.isupper())
         self.assertFalse('\u2177'.isupper())
         # non-BMP, uppercase
@@ -1473,10 +1470,9 @@ class UnicodeTest(string_tests.CommonTest,
         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.5), 'abc, abc, -1, -2.000000,  3.50')
         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 3.57), 'abc, abc, -1, -2.000000,  3.57')
         self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", -1, -2, 1003.57), 'abc, abc, -1, -2.000000, 1003.57')
-        if not sys.platform.startswith('java'):
-            self.assertEqual("%r, %r" % (b"abc", "abc"), "b'abc', 'abc'")
-            self.assertEqual("%r" % ("\u1234",), "'\u1234'")
-            self.assertEqual("%a" % ("\u1234",), "'\\u1234'")
+        self.assertEqual("%r, %r" % (b"abc", "abc"), "b'abc', 'abc'")
+        self.assertEqual("%r" % ("\u1234",), "'\u1234'")
+        self.assertEqual("%a" % ("\u1234",), "'\\u1234'")
         self.assertEqual("%(x)s, %(y)s" % {'x':"abc", 'y':"def"}, 'abc, def')
         self.assertEqual("%(x)s, %(\xfc)s" % {'x':"abc", '\xfc':"def"}, 'abc, def')
 
@@ -1671,29 +1667,27 @@ class UnicodeTest(string_tests.CommonTest,
         # unicode(obj, encoding, error) tests (this maps to
         # PyUnicode_FromEncodedObject() at C level)
 
-        if not sys.platform.startswith('java'):
-            self.assertRaises(
-                TypeError,
-                str,
-                'decoding unicode is not supported',
-                'utf-8',
-                'strict'
-            )
+        self.assertRaises(
+            TypeError,
+            str,
+            'decoding unicode is not supported',
+            'utf-8',
+            'strict'
+        )
 
         self.assertEqual(
             str(b'strings are decoded to unicode', 'utf-8', 'strict'),
             'strings are decoded to unicode'
         )
 
-        if not sys.platform.startswith('java'):
-            self.assertEqual(
-                str(
-                    memoryview(b'character buffers are decoded to unicode'),
-                    'utf-8',
-                    'strict'
-                ),
-                'character buffers are decoded to unicode'
-            )
+        self.assertEqual(
+            str(
+                memoryview(b'character buffers are decoded to unicode'),
+                'utf-8',
+                'strict'
+            ),
+            'character buffers are decoded to unicode'
+        )
 
         self.assertRaises(TypeError, str, 42, 42, 42)
 
index f8353126cb527c03a73ced2980a17e2edbf4dc03..aa8a1c847223994174d9de50b5b10f3fb8f7ba72 100644 (file)
@@ -56,7 +56,6 @@ except TypeError as exc:
     TracebackType = type(exc.__traceback__)
     FrameType = type(exc.__traceback__.tb_frame)
 
-# For Jython, the following two types are identical
 GetSetDescriptorType = type(FunctionType.__code__)
 MemberDescriptorType = type(FunctionType.__globals__)
 
index eb18cd0b49cd2641ce6f53d9a612af5cc5c18501..80d4fbdd8e36062bf0241ba5d7f4bb1d57588622 100644 (file)
@@ -57,9 +57,7 @@ def _make_skipped_test(methodname, exception, suiteClass):
     TestClass = type("ModuleSkipped", (case.TestCase,), attrs)
     return suiteClass((TestClass(methodname),))
 
-def _jython_aware_splitext(path):
-    if path.lower().endswith('$py.class'):
-        return path[:-9]
+def _splitext(path):
     return os.path.splitext(path)[0]
 
 
@@ -315,7 +313,7 @@ class TestLoader(object):
     def _get_name_from_path(self, path):
         if path == self._top_level_dir:
             return '.'
-        path = _jython_aware_splitext(os.path.normpath(path))
+        path = _splitext(os.path.normpath(path))
 
         _relpath = os.path.relpath(path, self._top_level_dir)
         assert not os.path.isabs(_relpath), "Path must be within the project"
@@ -393,13 +391,13 @@ class TestLoader(object):
             else:
                 mod_file = os.path.abspath(
                     getattr(module, '__file__', full_path))
-                realpath = _jython_aware_splitext(
+                realpath = _splitext(
                     os.path.realpath(mod_file))
-                fullpath_noext = _jython_aware_splitext(
+                fullpath_noext = _splitext(
                     os.path.realpath(full_path))
                 if realpath.lower() != fullpath_noext.lower():
                     module_dir = os.path.dirname(realpath)
-                    mod_name = _jython_aware_splitext(
+                    mod_name = _splitext(
                         os.path.basename(full_path))
                     expected_dir = os.path.dirname(full_path)
                     msg = ("%r module incorrectly imported from %r. Expected "
index 17b75879ebaafad86c812bee53b4b24e01c18802..b657310207cfe50b772e0fd0696c98f8b62ef682 100644 (file)
@@ -60,11 +60,7 @@ if _false:
 import os, sys
 if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ:
     default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
-del os
-
-_key = "python.xml.sax.parser"
-if sys.platform[:4] == "java" and sys.registry.containsKey(_key):
-    default_parser_list = sys.registry.getProperty(_key).split(",")
+del os, sys
 
 
 def make_parser(parser_list=()):
@@ -93,15 +89,6 @@ def make_parser(parser_list=()):
 
 # --- Internal utility methods used by make_parser
 
-if sys.platform[ : 4] == "java":
-    def _create_parser(parser_name):
-        from org.python.core import imp
-        drv_module = imp.importName(parser_name, 0, globals())
-        return drv_module.create_parser()
-
-else:
-    def _create_parser(parser_name):
-        drv_module = __import__(parser_name,{},{},['create_parser'])
-        return drv_module.create_parser()
-
-del sys
+def _create_parser(parser_name):
+    drv_module = __import__(parser_name,{},{},['create_parser'])
+    return drv_module.create_parser()
index a9b2ba35c6a22b2e393b6a898780f025a9e15e0f..f292dc3a8e50123ecb0579c8bf0467d07f1e60a8 100644 (file)
@@ -1,8 +1,4 @@
 """Different kinds of SAX Exceptions"""
-import sys
-if sys.platform[:4] == "java":
-    from java.lang import Exception
-del sys
 
 # ===== SAXEXCEPTION =====
 
index e334ac9fea0d362ce2dbc494eecd2187d1dec88f..b9ad52692db8dd6917827637e6b1bac2af4a2eee 100644 (file)
@@ -12,12 +12,6 @@ from xml.sax.handler import feature_external_ges, feature_external_pes
 from xml.sax.handler import feature_string_interning
 from xml.sax.handler import property_xml_string, property_interning_dict
 
-# xml.parsers.expat does not raise ImportError in Jython
-import sys
-if sys.platform[:4] == "java":
-    raise SAXReaderNotAvailable("expat not available in Java", None)
-del sys
-
 try:
     from xml.parsers import expat
 except ImportError:
diff --git a/Misc/NEWS.d/next/Library/2022-11-14-19-58-36.gh-issue-99482.XmZyUr.rst b/Misc/NEWS.d/next/Library/2022-11-14-19-58-36.gh-issue-99482.XmZyUr.rst
new file mode 100644 (file)
index 0000000..dd2c925
--- /dev/null
@@ -0,0 +1 @@
+Remove ``Jython`` partial compatibility code from several stdlib modules.