@@ -830,48 +830,13 @@ def __init__(
830
830
# Username and password passed as kwargs override user info in URI.
831
831
username = opts .get ("username" , username )
832
832
password = opts .get ("password" , password )
833
- self ._options = options = ClientOptions (username , password , dbase , opts , _IS_SYNC )
833
+ self ._options = ClientOptions (username , password , dbase , opts , _IS_SYNC )
834
834
835
835
self ._default_database_name = dbase
836
836
self ._lock = _async_create_lock ()
837
837
self ._kill_cursors_queue : list = []
838
838
839
- self ._event_listeners = options .pool_options ._event_listeners
840
- super ().__init__ (
841
- options .codec_options ,
842
- options .read_preference ,
843
- options .write_concern ,
844
- options .read_concern ,
845
- )
846
839
self ._encrypter : Optional [_Encrypter ] = None
847
- if not is_srv :
848
- self ._topology_settings = TopologySettings (
849
- seeds = seeds ,
850
- replica_set_name = options .replica_set_name ,
851
- pool_class = pool_class ,
852
- pool_options = options .pool_options ,
853
- monitor_class = monitor_class ,
854
- condition_class = condition_class ,
855
- local_threshold_ms = options .local_threshold_ms ,
856
- server_selection_timeout = options .server_selection_timeout ,
857
- server_selector = options .server_selector ,
858
- heartbeat_frequency = options .heartbeat_frequency ,
859
- fqdn = fqdn ,
860
- direct_connection = options .direct_connection ,
861
- load_balanced = options .load_balanced ,
862
- srv_service_name = srv_service_name ,
863
- srv_max_hosts = srv_max_hosts ,
864
- server_monitoring_mode = options .server_monitoring_mode ,
865
- )
866
- if self ._options .auto_encryption_opts :
867
- from pymongo .asynchronous .encryption import _Encrypter
868
-
869
- self ._encrypter = _Encrypter (self , self ._options .auto_encryption_opts )
870
-
871
- self ._opened = False
872
- self ._closed = False
873
- if not is_srv :
874
- self ._init_background (first = True )
875
840
876
841
self ._resolve_srv_info .update (
877
842
{
@@ -885,11 +850,17 @@ def __init__(
885
850
"condition_class" : condition_class ,
886
851
}
887
852
)
853
+ if not is_srv :
854
+ self ._init_based_on_options (seeds , srv_max_hosts , srv_service_name )
855
+
856
+ self ._opened = False
857
+ self ._closed = False
858
+ if not is_srv :
859
+ self ._init_background (first = True )
860
+
888
861
if _IS_SYNC and connect :
889
862
self ._get_topology () # type: ignore[unused-coroutine]
890
863
891
- self ._timeout = self ._options .timeout
892
-
893
864
def _resolve_srv (self ) -> None :
894
865
keyword_opts = self ._resolve_srv_info ["keyword_opts" ]
895
866
seeds = set ()
@@ -957,38 +928,39 @@ def _resolve_srv(self) -> None:
957
928
username , password , self ._resolve_srv_info ["dbase" ], opts , _IS_SYNC
958
929
)
959
930
960
- self ._event_listeners = self ._options .pool_options ._event_listeners
961
- super ().__init__ (
962
- self ._options .codec_options ,
963
- self ._options .read_preference ,
964
- self ._options .write_concern ,
965
- self ._options .read_concern ,
966
- )
931
+ self ._init_based_on_options (seeds , srv_max_hosts , srv_service_name )
967
932
968
- self ._topology_settings = TopologySettings (
969
- seeds = seeds ,
970
- replica_set_name = self ._options .replica_set_name ,
971
- pool_class = self ._resolve_srv_info ["pool_class" ],
972
- pool_options = self ._options .pool_options ,
973
- monitor_class = self ._resolve_srv_info ["monitor_class" ],
974
- condition_class = self ._resolve_srv_info ["condition_class" ],
975
- local_threshold_ms = self ._options .local_threshold_ms ,
976
- server_selection_timeout = self ._options .server_selection_timeout ,
977
- server_selector = self ._options .server_selector ,
978
- heartbeat_frequency = self ._options .heartbeat_frequency ,
979
- fqdn = self ._resolve_srv_info ["fqdn" ],
980
- direct_connection = self ._options .direct_connection ,
981
- load_balanced = self ._options .load_balanced ,
982
- srv_service_name = srv_service_name ,
983
- srv_max_hosts = srv_max_hosts ,
984
- server_monitoring_mode = self ._options .server_monitoring_mode ,
985
- )
986
-
987
- if self ._options .auto_encryption_opts :
988
- from pymongo .asynchronous .encryption import _Encrypter
933
+ def _init_based_on_options (self , seeds , srv_max_hosts , srv_service_name ):
934
+ self ._event_listeners = self ._options .pool_options ._event_listeners
935
+ super ().__init__ (
936
+ self ._options .codec_options ,
937
+ self ._options .read_preference ,
938
+ self ._options .write_concern ,
939
+ self ._options .read_concern ,
940
+ )
941
+ self ._topology_settings = TopologySettings (
942
+ seeds = seeds ,
943
+ replica_set_name = self ._options .replica_set_name ,
944
+ pool_class = self ._resolve_srv_info ["pool_class" ],
945
+ pool_options = self ._options .pool_options ,
946
+ monitor_class = self ._resolve_srv_info ["monitor_class" ],
947
+ condition_class = self ._resolve_srv_info ["condition_class" ],
948
+ local_threshold_ms = self ._options .local_threshold_ms ,
949
+ server_selection_timeout = self ._options .server_selection_timeout ,
950
+ server_selector = self ._options .server_selector ,
951
+ heartbeat_frequency = self ._options .heartbeat_frequency ,
952
+ fqdn = self ._resolve_srv_info ["fqdn" ],
953
+ direct_connection = self ._options .direct_connection ,
954
+ load_balanced = self ._options .load_balanced ,
955
+ srv_service_name = srv_service_name ,
956
+ srv_max_hosts = srv_max_hosts ,
957
+ server_monitoring_mode = self ._options .server_monitoring_mode ,
958
+ )
959
+ if self ._options .auto_encryption_opts :
960
+ from pymongo .asynchronous .encryption import _Encrypter
989
961
990
- self ._encrypter = _Encrypter (self , self ._options .auto_encryption_opts )
991
- self ._timeout = self ._options .timeout
962
+ self ._encrypter = _Encrypter (self , self ._options .auto_encryption_opts )
963
+ self ._timeout = self ._options .timeout
992
964
993
965
def _normalize_and_validate_options (
994
966
self , opts : common ._CaseInsensitiveDictionary , seeds : set [tuple [str , int | None ]]
0 commit comments