diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 2d99ef16c8..43135b8aaa 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -29,15 +29,6 @@ _IS_SYNC = False -def _have_dnspython() -> bool: - try: - import dns # noqa: F401 - - return True - except ImportError: - return False - - # dnspython can return bytes or str from various parts # of its API depending on version. We always want str. def maybe_decode(text: Union[str, bytes]) -> str: diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index de1a0fc9e6..c44c74cbeb 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -29,15 +29,6 @@ _IS_SYNC = True -def _have_dnspython() -> bool: - try: - import dns # noqa: F401 - - return True - except ImportError: - return False - - # dnspython can return bytes or str from various parts # of its API depending on version. We always want str. def maybe_decode(text: Union[str, bytes]) -> str: diff --git a/pymongo/uri_parser_shared.py b/pymongo/uri_parser_shared.py index 62d862bcfa..6f51bcd92e 100644 --- a/pymongo/uri_parser_shared.py +++ b/pymongo/uri_parser_shared.py @@ -33,7 +33,6 @@ ) from urllib.parse import unquote_plus -from pymongo.asynchronous.srv_resolver import _have_dnspython from pymongo.client_options import _parse_ssl_options from pymongo.common import ( INTERNAL_URI_OPTION_NAME_MAP, @@ -47,6 +46,7 @@ if TYPE_CHECKING: from pymongo.pyopenssl_context import SSLContext + SCHEME = "mongodb://" SCHEME_LEN = len(SCHEME) SRV_SCHEME = "mongodb+srv://" @@ -105,6 +105,15 @@ ) +def _have_dnspython() -> bool: + try: + import dns # noqa: F401 + + return True + except ImportError: + return False + + def _unquoted_percent(s: str) -> bool: """Check for unescaped percent signs. diff --git a/test/asynchronous/test_srv_polling.py b/test/asynchronous/test_srv_polling.py index 74e6ce969e..b8b9129925 100644 --- a/test/asynchronous/test_srv_polling.py +++ b/test/asynchronous/test_srv_polling.py @@ -27,8 +27,8 @@ import pymongo from pymongo import common -from pymongo.asynchronous.srv_resolver import _have_dnspython from pymongo.errors import ConfigurationError +from pymongo.uri_parser_shared import _have_dnspython from test.asynchronous import AsyncPyMongoTestCase, client_knobs, unittest from test.asynchronous.utils import async_wait_until diff --git a/test/test_srv_polling.py b/test/test_srv_polling.py index 4927b08f3d..e01ae1da7f 100644 --- a/test/test_srv_polling.py +++ b/test/test_srv_polling.py @@ -28,7 +28,7 @@ import pymongo from pymongo import common from pymongo.errors import ConfigurationError -from pymongo.synchronous.srv_resolver import _have_dnspython +from pymongo.uri_parser_shared import _have_dnspython from test import PyMongoTestCase, client_knobs, unittest from test.utils import wait_until