Skip to content

Commit 27ac7bd

Browse files
authored
PYTHON-2517 Remove any Jython specific code or workarounds (#2641)
1 parent 2f7946f commit 27ac7bd

File tree

14 files changed

+9
-100
lines changed

14 files changed

+9
-100
lines changed

pymongo/asynchronous/pool.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,6 @@
104104
from pymongo.typings import _Address, _CollationIn
105105
from pymongo.write_concern import WriteConcern
106106

107-
try:
108-
from fcntl import F_GETFD, F_SETFD, FD_CLOEXEC, fcntl
109-
110-
def _set_non_inheritable_non_atomic(fd: int) -> None:
111-
"""Set the close-on-exec flag on the given file descriptor."""
112-
flags = fcntl(fd, F_GETFD)
113-
fcntl(fd, F_SETFD, flags | FD_CLOEXEC)
114-
115-
except ImportError:
116-
# Windows, various platforms we don't claim to support
117-
# (Jython, IronPython, ..), systems that don't provide
118-
# everything we need from fcntl, etc.
119-
def _set_non_inheritable_non_atomic(fd: int) -> None: # noqa: ARG001
120-
"""Dummy function for platforms that don't provide fcntl."""
121-
122107

123108
_IS_SYNC = False
124109

@@ -706,8 +691,6 @@ class PoolState:
706691
CLOSED = 3
707692

708693

709-
# Do *not* explicitly inherit from object or Jython won't call __del__
710-
# https://bugs.jython.org/issue1057
711694
class Pool:
712695
def __init__(
713696
self,

pymongo/message.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,6 @@ def _batched_write_command_impl(
12981298

12991299
# Start of payload
13001300
buf.seek(-1, 2)
1301-
# Work around some Jython weirdness.
1302-
buf.truncate()
13031301
try:
13041302
buf.write(_OP_MAP[operation])
13051303
except KeyError:

pymongo/pool_options.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,6 @@
7979
# Windows patch level (e.g. 10.0.17763-SP0).
8080
"version": ".".join(map(str, _ver[:3])) + f"-SP{_ver[-1] or '0'}",
8181
}
82-
elif sys.platform.startswith("java"):
83-
_name, _ver, _arch = platform.java_ver()[-1]
84-
_METADATA["os"] = {
85-
# Linux, Windows 7, Mac OS X, etc.
86-
"type": _name,
87-
"name": _name,
88-
# x86, x86_64, AMD64, etc.
89-
"architecture": _arch,
90-
# Linux kernel version, OSX version, etc.
91-
"version": _ver,
92-
}
9382
else:
9483
# Get potential alias (e.g. SunOS 5.11 becomes Solaris 2.11)
9584
_aliased = platform.system_alias(platform.system(), platform.release(), platform.version())
@@ -108,14 +97,6 @@
10897
"(Python %s)" % ".".join(map(str, sys.version_info)),
10998
)
11099
)
111-
elif sys.platform.startswith("java"):
112-
_METADATA["platform"] = " ".join(
113-
(
114-
platform.python_implementation(),
115-
".".join(map(str, sys.version_info)),
116-
"(%s)" % " ".join((platform.system(), platform.release())),
117-
)
118-
)
119100
else:
120101
_METADATA["platform"] = " ".join(
121102
(platform.python_implementation(), ".".join(map(str, sys.version_info)))

pymongo/pool_shared.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ async def _async_create_connection(address: _Address, options: PoolOptions) -> s
237237
else:
238238
# This likely means we tried to connect to an IPv6 only
239239
# host with an OS/kernel or Python interpreter that doesn't
240-
# support IPv6. The test case is Jython2.5.1 which doesn't
241-
# support IPv6 at all.
240+
# support IPv6.
242241
raise OSError("getaddrinfo failed")
243242

244243

@@ -418,8 +417,7 @@ def _create_connection(address: _Address, options: PoolOptions) -> socket.socket
418417
else:
419418
# This likely means we tried to connect to an IPv6 only
420419
# host with an OS/kernel or Python interpreter that doesn't
421-
# support IPv6. The test case is Jython2.5.1 which doesn't
422-
# support IPv6 at all.
420+
# support IPv6.
423421
raise OSError("getaddrinfo failed")
424422

425423

pymongo/socket_checker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717

1818
import errno
1919
import select
20-
import sys
2120
from typing import Any, Optional, cast
2221

23-
# PYTHON-2320: Jython does not fully support poll on SSL sockets,
24-
# https://bugs.jython.org/issue2900
25-
_HAVE_POLL = hasattr(select, "poll") and not sys.platform.startswith("java")
22+
_HAVE_POLL = hasattr(select, "poll")
2623
_SelectError = getattr(select, "error", OSError)
2724

2825

pymongo/synchronous/pool.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,6 @@
104104
from pymongo.typings import _Address, _CollationIn
105105
from pymongo.write_concern import WriteConcern
106106

107-
try:
108-
from fcntl import F_GETFD, F_SETFD, FD_CLOEXEC, fcntl
109-
110-
def _set_non_inheritable_non_atomic(fd: int) -> None:
111-
"""Set the close-on-exec flag on the given file descriptor."""
112-
flags = fcntl(fd, F_GETFD)
113-
fcntl(fd, F_SETFD, flags | FD_CLOEXEC)
114-
115-
except ImportError:
116-
# Windows, various platforms we don't claim to support
117-
# (Jython, IronPython, ..), systems that don't provide
118-
# everything we need from fcntl, etc.
119-
def _set_non_inheritable_non_atomic(fd: int) -> None: # noqa: ARG001
120-
"""Dummy function for platforms that don't provide fcntl."""
121-
122107

123108
_IS_SYNC = True
124109

@@ -704,8 +689,6 @@ class PoolState:
704689
CLOSED = 3
705690

706691

707-
# Do *not* explicitly inherit from object or Jython won't call __del__
708-
# https://bugs.jython.org/issue1057
709692
class Pool:
710693
def __init__(
711694
self,

test/asynchronous/test_client.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,6 @@ async def test_close(self):
10661066
await coll.count_documents({})
10671067

10681068
async def test_close_kills_cursors(self):
1069-
if sys.platform.startswith("java"):
1070-
# We can't figure out how to make this test reliable with Jython.
1071-
raise SkipTest("Can't test with Jython")
10721069
test_client = await self.async_rs_or_single_client()
10731070
# Kill any cursors possibly queued up by previous tests.
10741071
gc.collect()
@@ -1088,7 +1085,7 @@ async def test_close_kills_cursors(self):
10881085
cursor = await coll.aggregate([], batchSize=10)
10891086
self.assertTrue(bool(await anext(cursor)))
10901087
del cursor
1091-
# Required for PyPy, Jython and other Python implementations that
1088+
# Required for PyPy and other Python implementations that
10921089
# don't use reference counting garbage collection.
10931090
gc.collect()
10941091

@@ -1456,12 +1453,6 @@ async def test_contextlib(self):
14561453

14571454
@async_client_context.require_sync
14581455
def test_interrupt_signal(self):
1459-
if sys.platform.startswith("java"):
1460-
# We can't figure out how to raise an exception on a thread that's
1461-
# blocked on a socket, whether that's the main thread or a worker,
1462-
# without simply killing the whole thread in Jython. This suggests
1463-
# PYTHON-294 can't actually occur in Jython.
1464-
raise SkipTest("Can't test interrupts in Jython")
14651456
if is_greenthread_patched():
14661457
raise SkipTest("Can't reliably test interrupts with green threads")
14671458

test/asynchronous/test_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ async def test_id_ordering(self):
475475
# when you iterate key/value pairs in a document.
476476
# This isn't reliable since python dicts don't
477477
# guarantee any particular order. This will never
478-
# work right in Jython or any Python or environment
478+
# work right in any Python or environment
479479
# with hash randomization enabled (e.g. tox).
480480
db = self.client.pymongo_test
481481
await db.test.drop()

test/asynchronous/utils_spec_runner.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,7 @@ async def run_test_ops(self, sessions, collection, test):
597597

598598
def parse_client_options(self, opts):
599599
"""Allow encryption spec to override a clientOptions parsing."""
600-
# Convert test['clientOptions'] to dict to avoid a Jython bug using
601-
# "**" with ScenarioDict.
602-
return dict(opts)
600+
return opts
603601

604602
async def setup_scenario(self, scenario_def):
605603
"""Allow specs to override a test's setup."""

test/test_bson.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ def assertInvalid(self, data):
135135
self.assertRaises(InvalidBSON, decode, data)
136136

137137
def check_encode_then_decode(self, doc_class=dict, decoder=decode, encoder=encode):
138-
# Work around http://bugs.jython.org/issue1728
139-
if sys.platform.startswith("java"):
140-
doc_class = SON
141-
142138
def helper(doc):
143139
self.assertEqual(doc, (decoder(encoder(doc_class(doc)))))
144140
self.assertEqual(doc, decoder(encoder(doc)))

0 commit comments

Comments
 (0)