3232import warnings
3333from inspect import iscoroutinefunction
3434
35+ from pymongo .synchronous .uri_parser import parse_uri
3536from pymongo .encryption_options import _HAVE_PYMONGOCRYPT
3637from pymongo .errors import AutoReconnect
37- from pymongo .synchronous .uri_parser import parse_uri
3838
3939try :
4040 import ipaddress
4141
4242 HAVE_IPADDRESS = True
4343except ImportError :
4444 HAVE_IPADDRESS = False
45- from contextlib import contextmanager
45+ from contextlib import contextmanager , contextmanager
4646from functools import partial , wraps
4747from typing import Any , Callable , Dict , Generator , overload
4848from unittest import SkipTest
5151import pymongo
5252import pymongo .errors
5353from bson .son import SON
54+ from pymongo .synchronous .database import Database
55+ from pymongo .synchronous .mongo_client import MongoClient
5456from pymongo .common import partition_node
5557from pymongo .hello import HelloCompat
5658from pymongo .server_api import ServerApi
5759from pymongo .ssl_support import HAVE_SSL , _ssl # type:ignore[attr-defined]
58- from pymongo .synchronous .database import Database
59- from pymongo .synchronous .mongo_client import MongoClient
6060
6161sys .path [0 :0 ] = ["" ]
6262
@@ -1006,7 +1006,9 @@ def _unmanaged_async_mongo_client(
10061006 client ._connect ()
10071007 return client
10081008
1009- def _async_mongo_client (self , host , port , authenticate = True , directConnection = None , ** kwargs ):
1009+ def _async_mongo_client (
1010+ self , host , port , authenticate = True , directConnection = None , ** kwargs
1011+ ):
10101012 """Create a new client over SSL/TLS if necessary."""
10111013 host = host or client_context .host
10121014 port = port or client_context .port
@@ -1053,7 +1055,9 @@ def unmanaged_single_client(
10531055 return cls ._unmanaged_async_mongo_client (h , p , directConnection = True , ** kwargs )
10541056
10551057 @classmethod
1056- def unmanaged_rs_client (cls , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
1058+ def unmanaged_rs_client (
1059+ cls , h : Any = None , p : Any = None , ** kwargs : Any
1060+ ) -> MongoClient [dict ]:
10571061 """Connect to the replica set and authenticate if necessary."""
10581062 return cls ._unmanaged_async_mongo_client (h , p , ** kwargs )
10591063
@@ -1082,17 +1086,25 @@ def single_client_noauth(
10821086 self , h : Any = None , p : Any = None , ** kwargs : Any
10831087 ) -> MongoClient [dict ]:
10841088 """Make a direct connection. Don't authenticate."""
1085- return self ._async_mongo_client (h , p , authenticate = False , directConnection = True , ** kwargs )
1089+ return self ._async_mongo_client (
1090+ h , p , authenticate = False , directConnection = True , ** kwargs
1091+ )
10861092
1087- def single_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
1093+ def single_client (
1094+ self , h : Any = None , p : Any = None , ** kwargs : Any
1095+ ) -> MongoClient [dict ]:
10881096 """Make a direct connection, and authenticate if necessary."""
10891097 return self ._async_mongo_client (h , p , directConnection = True , ** kwargs )
10901098
1091- def rs_client_noauth (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
1099+ def rs_client_noauth (
1100+ self , h : Any = None , p : Any = None , ** kwargs : Any
1101+ ) -> MongoClient [dict ]:
10921102 """Connect to the replica set. Don't authenticate."""
10931103 return self ._async_mongo_client (h , p , authenticate = False , ** kwargs )
10941104
1095- def rs_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [dict ]:
1105+ def rs_client (
1106+ self , h : Any = None , p : Any = None , ** kwargs : Any
1107+ ) -> MongoClient [dict ]:
10961108 """Connect to the replica set and authenticate if necessary."""
10971109 return self ._async_mongo_client (h , p , ** kwargs )
10981110
@@ -1105,7 +1117,9 @@ def rs_or_single_client_noauth(
11051117 """
11061118 return self ._async_mongo_client (h , p , authenticate = False , ** kwargs )
11071119
1108- def rs_or_single_client (self , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient [Any ]:
1120+ def rs_or_single_client (
1121+ self , h : Any = None , p : Any = None , ** kwargs : Any
1122+ ) -> MongoClient [Any ]:
11091123 """Connect to the replica set if there is one, otherwise the standalone.
11101124
11111125 Authenticates if necessary.
@@ -1121,7 +1135,9 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli
11211135 return client
11221136
11231137 @classmethod
1124- def unmanaged_simple_client (cls , h : Any = None , p : Any = None , ** kwargs : Any ) -> MongoClient :
1138+ def unmanaged_simple_client (
1139+ cls , h : Any = None , p : Any = None , ** kwargs : Any
1140+ ) -> MongoClient :
11251141 if not h and not p :
11261142 client = MongoClient (** kwargs )
11271143 else :
@@ -1302,21 +1318,3 @@ def drop_collections(db: Database):
13021318
13031319def remove_all_users (db : Database ):
13041320 db .command ("dropAllUsersFromDatabase" , 1 , writeConcern = {"w" : client_context .w })
1305-
1306-
1307- def skip_if_rust_bson (reason : str ):
1308- """Skip test if Rust BSON extension is being used.
1309-
1310- Use this decorator to skip tests that rely on features not yet implemented
1311- in the Rust BSON extension.
1312-
1313- :param reason: Explanation of why the test is skipped with Rust
1314- """
1315- import bson
1316-
1317- def decorator (func ):
1318- if bson .get_bson_implementation () == "rust" :
1319- return unittest .skip (f"Rust BSON: { reason } " )(func )
1320- return func
1321-
1322- return decorator
0 commit comments