]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Remove customizable selectors. (#1046)
authorBrian Wellington <bwelling@xbill.org>
Mon, 12 Feb 2024 23:12:25 +0000 (15:12 -0800)
committerGitHub <noreply@github.com>
Mon, 12 Feb 2024 23:12:25 +0000 (15:12 -0800)
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.

dns/query.py
dns/quic/_sync.py
tests/test_resolver.py

index bdd251e752a4df491cd869d80741b76fca49e5f1..06d186c7e4318e76133a2dc305e3137498ac36e1 100644 (file)
@@ -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)
 
index 120cb5f329c779a6556143339e536d1443bf3ddf..79bfa77430d179068cea0dc58f264fa0bf021fcc 100644 (file)
@@ -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:
index 9550e87bd20255e5b285c7c034957660a03bd852..8694335cc56bb20086cba5df7c0605ed32390fef 100644 (file)
@@ -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