From: Brian Wellington Date: Mon, 12 Feb 2024 23:12:25 +0000 (-0800) Subject: Remove customizable selectors. (#1046) X-Git-Tag: v2.7.0rc1~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c1f0c8f6c8d8e9c90a3c82b5e35095b968ee3cc7;p=thirdparty%2Fdnspython.git Remove customizable selectors. (#1046) The customization predates the selectors now, and presumably was present to work around something broken long ago. Any such logic should be in the selectors module, and if there is some platform for which selectors.DefaultSelector doesn't work, that can be overridden. --- diff --git a/dns/query.py b/dns/query.py index bdd251e7..06d186c7 100644 --- a/dns/query.py +++ b/dns/query.py @@ -217,7 +217,7 @@ def _wait_for(fd, readable, writable, _, expiration): if readable and isinstance(fd, ssl.SSLSocket) and fd.pending() > 0: return True - sel = _selector_class() + sel = selectors.DefaultSelector() events = 0 if readable: events |= selectors.EVENT_READ @@ -235,26 +235,6 @@ def _wait_for(fd, readable, writable, _, expiration): raise dns.exception.Timeout -def _set_selector_class(selector_class): - # Internal API. Do not use. - - global _selector_class - - _selector_class = selector_class - - -if hasattr(selectors, "PollSelector"): - # Prefer poll() on platforms that support it because it has no - # limits on the maximum value of a file descriptor (plus it will - # be more efficient for high values). - # - # We ignore typing here as we can't say _selector_class is Any - # on python < 3.8 due to a bug. - _selector_class = selectors.PollSelector # type: ignore -else: - _selector_class = selectors.SelectSelector # type: ignore - - def _wait_for_readable(s, expiration): _wait_for(s, True, False, True, expiration) diff --git a/dns/quic/_sync.py b/dns/quic/_sync.py index 120cb5f3..79bfa774 100644 --- a/dns/quic/_sync.py +++ b/dns/quic/_sync.py @@ -21,12 +21,6 @@ from dns.quic._common import ( UnexpectedEOF, ) -# Avoid circularity with dns.query -if hasattr(selectors, "PollSelector"): - _selector_class = selectors.PollSelector # type: ignore -else: - _selector_class = selectors.SelectSelector # type: ignore - class SyncQuicStream(BaseQuicStream): def __init__(self, connection, stream_id): @@ -118,7 +112,7 @@ class SyncQuicConnection(BaseQuicConnection): def _worker(self): try: - sel = _selector_class() + sel = selectors.DefaultSelector() sel.register(self._socket, selectors.EVENT_READ, self._read) sel.register(self._receive_wakeup, selectors.EVENT_READ, self._drain_wakeup) while not self._done: diff --git a/tests/test_resolver.py b/tests/test_resolver.py index 9550e87b..8694335c 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -817,35 +817,6 @@ class LiveResolverTests(unittest.TestCase): res.nameservers = [ns] -class PollingMonkeyPatchMixin(object): - def setUp(self): - self.__native_selector_class = dns.query._selector_class - dns.query._set_selector_class(self.selector_class()) - - unittest.TestCase.setUp(self) - - def tearDown(self): - dns.query._set_selector_class(self.__native_selector_class) - - unittest.TestCase.tearDown(self) - - -class SelectResolverTestCase( - PollingMonkeyPatchMixin, LiveResolverTests, unittest.TestCase -): - def selector_class(self): - return selectors.SelectSelector - - -if hasattr(selectors, "PollSelector"): - - class PollResolverTestCase( - PollingMonkeyPatchMixin, LiveResolverTests, unittest.TestCase - ): - def selector_class(self): - return selectors.PollSelector - - class NXDOMAINExceptionTestCase(unittest.TestCase): # pylint: disable=broad-except