@@ -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 ,
@@ -1487,7 +1485,7 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
14871485 ('numCursors' , num_cursors )])
14881486 cmd .update (kwargs )
14891487
1490- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
1488+ with self ._socket_for_reads () as (sock_info , slave_ok ):
14911489 result = self ._command (sock_info , cmd , slave_ok ,
14921490 read_concern = self .read_concern ,
14931491 session = session )
@@ -1503,7 +1501,7 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
15031501
15041502 def _count (self , cmd , collation = None , session = None ):
15051503 """Internal count helper."""
1506- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
1504+ with self ._socket_for_reads () as (sock_info , slave_ok ):
15071505 res = self ._command (
15081506 sock_info , cmd , slave_ok ,
15091507 allowable_errors = ["ns missing" ],
@@ -1600,7 +1598,7 @@ def create_indexes(self, indexes, session=None, **kwargs):
16001598 """
16011599 common .validate_list ('indexes' , indexes )
16021600 names = []
1603- with self ._socket_for_writes (session ) as sock_info :
1601+ with self ._socket_for_writes () as sock_info :
16041602 supports_collations = sock_info .max_wire_version >= 5
16051603 def gen_indexes ():
16061604 for index in indexes :
@@ -1641,7 +1639,7 @@ def __create_index(self, keys, index_options, session, **kwargs):
16411639 index_options .pop ('collation' , None ))
16421640 index .update (index_options )
16431641
1644- with self ._socket_for_writes (session ) as sock_info :
1642+ with self ._socket_for_writes () as sock_info :
16451643 if collation is not None :
16461644 if sock_info .max_wire_version < 5 :
16471645 raise ConfigurationError (
@@ -1868,7 +1866,7 @@ def drop_index(self, index_or_name, session=None, **kwargs):
18681866 self .__database .name , self .__name , name )
18691867 cmd = SON ([("dropIndexes" , self .__name ), ("index" , name )])
18701868 cmd .update (kwargs )
1871- with self ._socket_for_writes (session ) as sock_info :
1869+ with self ._socket_for_writes () as sock_info :
18721870 self ._command (sock_info ,
18731871 cmd ,
18741872 read_preference = ReadPreference .PRIMARY ,
@@ -1905,7 +1903,7 @@ def reindex(self, session=None, **kwargs):
19051903 """
19061904 cmd = SON ([("reIndex" , self .__name )])
19071905 cmd .update (kwargs )
1908- with self ._socket_for_writes (session ) as sock_info :
1906+ with self ._socket_for_writes () as sock_info :
19091907 return self ._command (
19101908 sock_info , cmd , read_preference = ReadPreference .PRIMARY ,
19111909 parse_write_concern_error = True , session = session )
@@ -1934,7 +1932,7 @@ def list_indexes(self, session=None):
19341932 codec_options = CodecOptions (SON )
19351933 coll = self .with_options (codec_options = codec_options ,
19361934 read_preference = ReadPreference .PRIMARY )
1937- with self ._socket_for_primary_reads (session ) as (sock_info , slave_ok ):
1935+ with self ._socket_for_primary_reads () as (sock_info , slave_ok ):
19381936 cmd = SON ([("listIndexes" , self .__name ), ("cursor" , {})])
19391937 if sock_info .max_wire_version > 2 :
19401938 with self .__database .client ._tmp_session (session , False ) as s :
@@ -2055,7 +2053,7 @@ def _aggregate(self, pipeline, cursor_class, first_batch_size, session,
20552053 "batchSize" , kwargs .pop ("batchSize" , None ))
20562054 # If the server does not support the "cursor" option we
20572055 # ignore useCursor and batchSize.
2058- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2056+ with self ._socket_for_reads () as (sock_info , slave_ok ):
20592057 dollar_out = pipeline and '$out' in pipeline [- 1 ]
20602058 if use_cursor :
20612059 if "cursor" not in kwargs :
@@ -2344,7 +2342,7 @@ def group(self, key, condition, initial, reduce, finalize=None, **kwargs):
23442342 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
23452343 cmd .update (kwargs )
23462344
2347- with self ._socket_for_reads (session = None ) as (sock_info , slave_ok ):
2345+ with self ._socket_for_reads () as (sock_info , slave_ok ):
23482346 return self ._command (sock_info , cmd , slave_ok ,
23492347 collation = collation )["retval" ]
23502348
@@ -2390,7 +2388,7 @@ def rename(self, new_name, session=None, **kwargs):
23902388
23912389 new_name = "%s.%s" % (self .__database .name , new_name )
23922390 cmd = SON ([("renameCollection" , self .__full_name ), ("to" , new_name )])
2393- with self ._socket_for_writes (session ) as sock_info :
2391+ with self ._socket_for_writes () as sock_info :
23942392 with self .__database .client ._tmp_session (session ) as s :
23952393 if sock_info .max_wire_version >= 5 and self .write_concern :
23962394 cmd ['writeConcern' ] = self .write_concern .document
@@ -2445,7 +2443,7 @@ def distinct(self, key, filter=None, session=None, **kwargs):
24452443 kwargs ["query" ] = filter
24462444 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
24472445 cmd .update (kwargs )
2448- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2446+ with self ._socket_for_reads () as (sock_info , slave_ok ):
24492447 return self ._command (sock_info , cmd , slave_ok ,
24502448 read_concern = self .read_concern ,
24512449 collation = collation , session = session )["values" ]
@@ -2517,7 +2515,7 @@ def map_reduce(self, map, reduce, out, full_response=False, session=None,
25172515 cmd .update (kwargs )
25182516
25192517 inline = 'inline' in cmd ['out' ]
2520- with self ._socket_for_primary_reads (session ) as (sock_info , slave_ok ):
2518+ with self ._socket_for_primary_reads () as (sock_info , slave_ok ):
25212519 if (sock_info .max_wire_version >= 5 and self .write_concern and
25222520 not inline ):
25232521 cmd ['writeConcern' ] = self .write_concern .document
@@ -2586,7 +2584,7 @@ def inline_map_reduce(self, map, reduce, full_response=False, session=None,
25862584 ("out" , {"inline" : 1 })])
25872585 collation = validate_collation_or_none (kwargs .pop ('collation' , None ))
25882586 cmd .update (kwargs )
2589- with self ._socket_for_reads (session ) as (sock_info , slave_ok ):
2587+ with self ._socket_for_reads () as (sock_info , slave_ok ):
25902588 if sock_info .max_wire_version >= 4 and 'readConcern' not in cmd :
25912589 res = self ._command (sock_info , cmd , slave_ok ,
25922590 read_concern = self .read_concern ,
0 commit comments