@@ -184,16 +184,14 @@ def __init__(self, database, name, create=False, codec_options=None,
184184 unicode_decode_error_handler = 'replace' ,
185185 document_class = dict )
186186
187- def _socket_for_reads (self , session ):
188- return self .__database .client ._socket_for_reads (
189- self .read_preference , session )
187+ def _socket_for_reads (self ):
188+ return self .__database .client ._socket_for_reads (self .read_preference )
190189
191- def _socket_for_primary_reads (self , session ):
192- return self .__database .client ._socket_for_reads (
193- ReadPreference .PRIMARY , session )
190+ def _socket_for_primary_reads (self ):
191+ return self .__database .client ._socket_for_reads (ReadPreference .PRIMARY )
194192
195- def _socket_for_writes (self , session ):
196- return self .__database .client ._socket_for_writes (session )
193+ def _socket_for_writes (self ):
194+ return self .__database .client ._socket_for_writes ()
197195
198196 def _command (self , sock_info , command , slave_ok = False ,
199197 read_preference = None ,
@@ -254,7 +252,7 @@ def __create(self, options, collation, session):
254252 if "size" in options :
255253 options ["size" ] = float (options ["size" ])
256254 cmd .update (options )
257- with self ._socket_for_writes (session ) as sock_info :
255+ with self ._socket_for_writes () as sock_info :
258256 self ._command (
259257 sock_info , cmd , read_preference = ReadPreference .PRIMARY ,
260258 write_concern = self .write_concern ,
@@ -581,7 +579,7 @@ def _insert_command(session, sock_info, retryable_write):
581579 True , _insert_command , session )
582580 _check_write_command_response (result )
583581 else :
584- with self ._socket_for_writes (session = None ) as sock_info :
582+ with self ._socket_for_writes () as sock_info :
585583 # Legacy OP_INSERT.
586584 self ._legacy_write (
587585 sock_info , 'insert' , command , op_id ,
@@ -1495,7 +1493,7 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
14951493 ('numCursors' , num_cursors )])
14961494 cmd .update (kwargs )
14971495
1498- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
1496+ with self ._socket_for_reads () as (sock_info , slave_ok ):
14991497 result = self ._command (sock_info , cmd , slave_ok ,
15001498 read_concern = self .read_concern ,
15011499 session = session )
@@ -1511,7 +1509,7 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
15111509
15121510 def _count (self , cmd , collation = None , session = None ):
15131511 """Internal count helper."""
1514- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
1512+ with self ._socket_for_reads () as (sock_info , slave_ok ):
15151513 res = self ._command (
15161514 sock_info , cmd , slave_ok ,
15171515 allowable_errors = ["ns missing" ],
@@ -1608,7 +1606,7 @@ def create_indexes(self, indexes, session=None, **kwargs):
16081606 """
16091607 common .validate_list ('indexes' , indexes )
16101608 names = []
1611- with self ._socket_for_writes (session ) as sock_info :
1609+ with self ._socket_for_writes () as sock_info :
16121610 supports_collations = sock_info .max_wire_version >= 5
16131611 def gen_indexes ():
16141612 for index in indexes :
@@ -1649,7 +1647,7 @@ def __create_index(self, keys, index_options, session, **kwargs):
16491647 index_options .pop ('collation' , None ))
16501648 index .update (index_options )
16511649
1652- with self ._socket_for_writes (session ) as sock_info :
1650+ with self ._socket_for_writes () as sock_info :
16531651 if collation is not None :
16541652 if sock_info .max_wire_version < 5 :
16551653 raise ConfigurationError (
@@ -1876,7 +1874,7 @@ def drop_index(self, index_or_name, session=None, **kwargs):
18761874 self .__database .name , self .__name , name )
18771875 cmd = SON ([("dropIndexes" , self .__name ), ("index" , name )])
18781876 cmd .update (kwargs )
1879- with self ._socket_for_writes (session ) as sock_info :
1877+ with self ._socket_for_writes () as sock_info :
18801878 self ._command (sock_info ,
18811879 cmd ,
18821880 read_preference = ReadPreference .PRIMARY ,
@@ -1913,7 +1911,7 @@ def reindex(self, session=None, **kwargs):
19131911 """
19141912 cmd = SON ([("reIndex" , self .__name )])
19151913 cmd .update (kwargs )
1916- with self ._socket_for_writes (session ) as sock_info :
1914+ with self ._socket_for_writes () as sock_info :
19171915 return self ._command (
19181916 sock_info , cmd , read_preference = ReadPreference .PRIMARY ,
19191917 parse_write_concern_error = True , session = session )
@@ -1942,7 +1940,7 @@ def list_indexes(self, session=None):
19421940 codec_options = CodecOptions (SON )
19431941 coll = self .with_options (codec_options = codec_options ,
19441942 read_preference = ReadPreference .PRIMARY )
1945- with self ._socket_for_primary_reads (session ) as (sock_info , slave_ok ):
1943+ with self ._socket_for_primary_reads () as (sock_info , slave_ok ):
19461944 cmd = SON ([("listIndexes" , self .__name ), ("cursor" , {})])
19471945 if sock_info .max_wire_version > 2 :
19481946 with self .__database .client ._tmp_session (session , False ) as s :
@@ -2063,7 +2061,7 @@ def _aggregate(self, pipeline, cursor_class, first_batch_size, session,
20632061 "batchSize" , kwargs .pop ("batchSize" , None ))
20642062 # If the server does not support the "cursor" option we
20652063 # ignore useCursor and batchSize.
2066- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2064+ with self ._socket_for_reads () as (sock_info , slave_ok ):
20672065 dollar_out = pipeline and '$out' in pipeline [- 1 ]
20682066 if use_cursor :
20692067 if "cursor" not in kwargs :
@@ -2352,7 +2350,7 @@ def group(self, key, condition, initial, reduce, finalize=None, **kwargs):
23522350 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
23532351 cmd .update (kwargs )
23542352
2355- with self ._socket_for_reads (session = None ) as (sock_info , slave_ok ):
2353+ with self ._socket_for_reads () as (sock_info , slave_ok ):
23562354 return self ._command (sock_info , cmd , slave_ok ,
23572355 collation = collation )["retval" ]
23582356
@@ -2398,7 +2396,7 @@ def rename(self, new_name, session=None, **kwargs):
23982396
23992397 new_name = "%s.%s" % (self .__database .name , new_name )
24002398 cmd = SON ([("renameCollection" , self .__full_name ), ("to" , new_name )])
2401- with self ._socket_for_writes (session ) as sock_info :
2399+ with self ._socket_for_writes () as sock_info :
24022400 with self .__database .client ._tmp_session (session ) as s :
24032401 if sock_info .max_wire_version >= 5 and self .write_concern :
24042402 cmd ['writeConcern' ] = self .write_concern .document
@@ -2453,7 +2451,7 @@ def distinct(self, key, filter=None, session=None, **kwargs):
24532451 kwargs ["query" ] = filter
24542452 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
24552453 cmd .update (kwargs )
2456- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2454+ with self ._socket_for_reads () as (sock_info , slave_ok ):
24572455 return self ._command (sock_info , cmd , slave_ok ,
24582456 read_concern = self .read_concern ,
24592457 collation = collation , session = session )["values" ]
@@ -2525,7 +2523,7 @@ def map_reduce(self, map, reduce, out, full_response=False, session=None,
25252523 cmd .update (kwargs )
25262524
25272525 inline = 'inline' in cmd ['out' ]
2528- with self ._socket_for_primary_reads (session ) as (sock_info , slave_ok ):
2526+ with self ._socket_for_primary_reads () as (sock_info , slave_ok ):
25292527 if (sock_info .max_wire_version >= 5 and self .write_concern and
25302528 not inline ):
25312529 cmd ['writeConcern' ] = self .write_concern .document
@@ -2594,7 +2592,7 @@ def inline_map_reduce(self, map, reduce, full_response=False, session=None,
25942592 ("out" , {"inline" : 1 })])
25952593 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
25962594 cmd .update (kwargs )
2597- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2595+ with self ._socket_for_reads () as (sock_info , slave_ok ):
25982596 if sock_info .max_wire_version >= 4 and 'readConcern' not in cmd :
25992597 res = self ._command (sock_info , cmd , slave_ok ,
26002598 read_concern = self .read_concern ,
0 commit comments