summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-12-23 20:17:24 (GMT)
committerGitHub <noreply@github.com>2022-12-23 20:17:24 (GMT)
commit745545b5bb847023f90505bf9caa983463413780 (patch)
tree1b6db7fc6c92542ac9bc56769524ee26ce9eb10e
parentc5726b727e26b81a267933654cf26b760a90d9aa (diff)
downloadcpython-745545b5bb847023f90505bf9caa983463413780.zip
cpython-745545b5bb847023f90505bf9caa983463413780.tar.gz
cpython-745545b5bb847023f90505bf9caa983463413780.tar.bz2
gh-99482: remove `jython` compatibility parts from stdlib and tests (#99484)
-rw-r--r--Doc/whatsnew/3.12.rst3
-rw-r--r--Lib/copy.py12
-rw-r--r--Lib/pickle.py8
-rwxr-xr-xLib/platform.py2
-rw-r--r--Lib/site.py7
-rw-r--r--Lib/test/support/__init__.py3
-rw-r--r--Lib/test/support/os_helper.py6
-rw-r--r--Lib/test/test___all__.py7
-rw-r--r--Lib/test/test_codeop.py49
-rw-r--r--Lib/test/test_exceptions.py7
-rw-r--r--Lib/test/test_import/__init__.py7
-rw-r--r--Lib/test/test_platform.py2
-rw-r--r--Lib/test/test_strftime.py12
-rw-r--r--Lib/test/test_unicode.py200
-rw-r--r--Lib/types.py1
-rw-r--r--Lib/unittest/loader.py12
-rw-r--r--Lib/xml/sax/__init__.py21
-rw-r--r--Lib/xml/sax/_exceptions.py4
-rw-r--r--Lib/xml/sax/expatreader.py6
-rw-r--r--Misc/NEWS.d/next/Library/2022-11-14-19-58-36.gh-issue-99482.XmZyUr.rst1
20 files changed, 136 insertions, 234 deletions
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index 617fadd..69f97de 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -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`.)
diff --git a/Lib/copy.py b/Lib/copy.py
index 1b276af..6e8c19b 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -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
diff --git a/Lib/pickle.py b/Lib/pickle.py
index f027e04..15fa5f6 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -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
diff --git a/Lib/platform.py b/Lib/platform.py
index 6745321..b018046 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -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,
diff --git a/Lib/site.py b/Lib/site.py
index 69670d9..7faf1c6 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -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 = [], []
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index b718605..ff736f1 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -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()
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index f37a442..2d4356a 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -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.
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index 1ec83cb..ecf73b3 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -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 = []
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py
index d7b51be..6966c2f 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -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")
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 65a3a8a..f629321 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -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:
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 6c5b80b..1e4429e 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -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",
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index 3992faf..72942dd 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -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):
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
index be43c49..cebfc89 100644
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -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()
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 5465d35..79360f5 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -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)
diff --git a/Lib/types.py b/Lib/types.py
index f835312..aa8a1c8 100644
--- a/Lib/types.py
+++ b/Lib/types.py
@@ -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__)
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index eb18cd0..80d4fbd 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -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 "
diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py
index 17b7587..b657310 100644
--- a/Lib/xml/sax/__init__.py
+++ b/Lib/xml/sax/__init__.py
@@ -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()
diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py
index a9b2ba3..f292dc3 100644
--- a/Lib/xml/sax/_exceptions.py
+++ b/Lib/xml/sax/_exceptions.py
@@ -1,8 +1,4 @@
"""Different kinds of SAX Exceptions"""
-import sys
-if sys.platform[:4] == "java":
- from java.lang import Exception
-del sys
# ===== SAXEXCEPTION =====
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index e334ac9..b9ad526 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -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
index 0000000..dd2c925
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-14-19-58-36.gh-issue-99482.XmZyUr.rst
@@ -0,0 +1 @@
+Remove ``Jython`` partial compatibility code from several stdlib modules.