@@ -150,6 +150,9 @@ def __init__(self, sock, pool, host):
150150 self .last_checkout = time .time ()
151151 self .pool_ref = weakref .ref (pool )
152152
153+ self ._min_wire_version = None
154+ self ._max_wire_version = None
155+
153156 # The pool's pool_id changes with each reset() so we can close sockets
154157 # created before the last reset.
155158 self .pool_id = pool .pool_id
@@ -257,6 +260,20 @@ def close(self):
257260 self .sock .close ()
258261 except :
259262 pass
263+
264+ def set_wire_version_range (self , min_wire_version , max_wire_version ):
265+ self ._min_wire_version = min_wire_version
266+ self ._max_wire_version = max_wire_version
267+
268+ @property
269+ def min_wire_version (self ):
270+ assert self ._min_wire_version is not None
271+ return self ._min_wire_version
272+
273+ @property
274+ def max_wire_version (self ):
275+ assert self ._max_wire_version is not None
276+ return self ._max_wire_version
260277
261278 def exhaust (self , exhaust ):
262279 self ._exhaust = exhaust
@@ -425,19 +442,25 @@ def connect(self):
425442 sock .settimeout (self .opts .socket_timeout )
426443 return SocketInfo (sock , self , hostname )
427444
428- def get_socket (self , all_credentials ):
445+ def get_socket (self , all_credentials , min_wire_version , max_wire_version ):
429446 """Get a socket from the pool.
430447
431448 Returns a :class:`SocketInfo` object wrapping a connected
432- :class:`socket.socket`, and a bool saying whether the socket was from
433- the pool or freshly created.
449+ :class:`socket.socket`.
450+
451+ The socket is logged in or out as necessary to match ``all_credentials``
452+ using the correct authentication mechanism for the server's wire
453+ protocol version.
434454
435455 :Parameters:
436456 - `all_credentials`: dict, maps auth source to MongoCredential.
457+ - `min_wire_version`: int, minimum protocol the server supports.
458+ - `max_wire_version`: int, maximum protocol the server supports.
437459 """
438460 # First get a socket, then attempt authentication. Simplifies
439461 # semaphore management in the face of network errors during auth.
440462 sock_info = self ._get_socket_no_auth ()
463+ sock_info .set_wire_version_range (min_wire_version , max_wire_version )
441464 try :
442465 sock_info .check_auth (all_credentials )
443466 return sock_info
0 commit comments