Skip to content

Commit ad20606

Browse files
committed
okay turns out it was *too* lazy HAHA
1 parent d94743b commit ad20606

File tree

5 files changed

+77
-76
lines changed

5 files changed

+77
-76
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,10 @@ def __init__(
763763
# Parse options passed as kwargs.
764764
keyword_opts = common._CaseInsensitiveDictionary(kwargs)
765765
keyword_opts["document_class"] = doc_class
766-
self._resolve_uri_info: dict[str, Any] = {"keyword_opts": keyword_opts}
766+
self._resolve_srv_info: dict[str, Any] = {"keyword_opts": keyword_opts}
767767

768768
seeds = set()
769+
is_srv = False
769770
username = None
770771
password = None
771772
dbase = None
@@ -789,6 +790,7 @@ def __init__(
789790
srv_max_hosts=srv_max_hosts,
790791
)
791792
seeds.update(res["nodelist"])
793+
is_srv = res["is_srv"] or is_srv
792794
username = res["username"] or username
793795
password = res["password"] or password
794796
dbase = res["database"] or dbase
@@ -840,33 +842,33 @@ def __init__(
840842
options.write_concern,
841843
options.read_concern,
842844
)
843-
844-
# self._topology_settings = TopologySettings(
845-
# seeds=seeds,
846-
# replica_set_name=options.replica_set_name,
847-
# pool_class=pool_class,
848-
# pool_options=options.pool_options,
849-
# monitor_class=monitor_class,
850-
# condition_class=condition_class,
851-
# local_threshold_ms=options.local_threshold_ms,
852-
# server_selection_timeout=options.server_selection_timeout,
853-
# server_selector=options.server_selector,
854-
# heartbeat_frequency=options.heartbeat_frequency,
855-
# fqdn=fqdn,
856-
# direct_connection=options.direct_connection,
857-
# load_balanced=options.load_balanced,
858-
# srv_service_name=srv_service_name,
859-
# srv_max_hosts=srv_max_hosts,
860-
# server_monitoring_mode=options.server_monitoring_mode,
861-
# )
862-
#
863-
# self._topology = Topology(self._topology_settings)
845+
if not is_srv:
846+
self._topology_settings = TopologySettings(
847+
seeds=seeds,
848+
replica_set_name=options.replica_set_name,
849+
pool_class=pool_class,
850+
pool_options=options.pool_options,
851+
monitor_class=monitor_class,
852+
condition_class=condition_class,
853+
local_threshold_ms=options.local_threshold_ms,
854+
server_selection_timeout=options.server_selection_timeout,
855+
server_selector=options.server_selector,
856+
heartbeat_frequency=options.heartbeat_frequency,
857+
fqdn=fqdn,
858+
direct_connection=options.direct_connection,
859+
load_balanced=options.load_balanced,
860+
srv_service_name=srv_service_name,
861+
srv_max_hosts=srv_max_hosts,
862+
server_monitoring_mode=options.server_monitoring_mode,
863+
)
864+
self._topology = Topology(self._topology_settings)
864865

865866
self._opened = False
866867
self._closed = False
867868

868-
self._resolve_uri_info.update(
869+
self._resolve_srv_info.update(
869870
{
871+
"is_srv": is_srv,
870872
"username": username,
871873
"password": password,
872874
"dbase": dbase,
@@ -882,8 +884,8 @@ def __init__(
882884
self._encrypter: Optional[_Encrypter] = None
883885
self._timeout = self._options.timeout
884886

885-
def _resolve_uri(self) -> None:
886-
keyword_opts = self._resolve_uri_info["keyword_opts"]
887+
def _resolve_srv(self) -> None:
888+
keyword_opts = self._resolve_srv_info["keyword_opts"]
887889
seeds = set()
888890
opts = common._CaseInsensitiveDictionary()
889891
srv_service_name = keyword_opts.get("srvservicename")
@@ -899,7 +901,7 @@ def _resolve_uri(self) -> None:
899901
timeout = common.validate_timeout_or_none_or_zero(
900902
keyword_opts.cased_key("connecttimeoutms"), timeout
901903
)
902-
res = uri_parser._lookup_uri(
904+
res = uri_parser._parse_srv(
903905
entity,
904906
self._port,
905907
validate=True,
@@ -943,10 +945,10 @@ def _resolve_uri(self) -> None:
943945
opts = self._normalize_and_validate_options(opts, seeds)
944946

945947
# Username and password passed as kwargs override user info in URI.
946-
username = opts.get("username", self._resolve_uri_info["username"])
947-
password = opts.get("password", self._resolve_uri_info["password"])
948+
username = opts.get("username", self._resolve_srv_info["username"])
949+
password = opts.get("password", self._resolve_srv_info["password"])
948950
self._options = ClientOptions(
949-
username, password, self._resolve_uri_info["dbase"], opts, _IS_SYNC
951+
username, password, self._resolve_srv_info["dbase"], opts, _IS_SYNC
950952
)
951953

952954
self._event_listeners = self._options.pool_options._event_listeners
@@ -960,22 +962,21 @@ def _resolve_uri(self) -> None:
960962
self._topology_settings = TopologySettings(
961963
seeds=seeds,
962964
replica_set_name=self._options.replica_set_name,
963-
pool_class=self._resolve_uri_info["pool_class"],
965+
pool_class=self._resolve_srv_info["pool_class"],
964966
pool_options=self._options.pool_options,
965-
monitor_class=self._resolve_uri_info["monitor_class"],
966-
condition_class=self._resolve_uri_info["condition_class"],
967+
monitor_class=self._resolve_srv_info["monitor_class"],
968+
condition_class=self._resolve_srv_info["condition_class"],
967969
local_threshold_ms=self._options.local_threshold_ms,
968970
server_selection_timeout=self._options.server_selection_timeout,
969971
server_selector=self._options.server_selector,
970972
heartbeat_frequency=self._options.heartbeat_frequency,
971-
fqdn=self._resolve_uri_info["fqdn"],
973+
fqdn=self._resolve_srv_info["fqdn"],
972974
direct_connection=self._options.direct_connection,
973975
load_balanced=self._options.load_balanced,
974976
srv_service_name=srv_service_name,
975977
srv_max_hosts=srv_max_hosts,
976978
server_monitoring_mode=self._options.server_monitoring_mode,
977979
)
978-
979980
self._topology = Topology(self._topology_settings)
980981

981982
if self._options.auto_encryption_opts:
@@ -1709,7 +1710,8 @@ async def _get_topology(self) -> Topology:
17091710
launches the connection process in the background.
17101711
"""
17111712
if not self._opened:
1712-
self._resolve_uri()
1713+
if self._resolve_srv_info["is_srv"]:
1714+
self._resolve_srv()
17131715
self._init_background()
17141716
await self._topology.open()
17151717
async with self._lock:

pymongo/asynchronous/topology.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ async def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None:
567567
if td_old.topology_type not in SRV_POLLING_TOPOLOGIES:
568568
return
569569
self._description = _updated_topology_description_srv_polling(self._description, seedlist)
570-
571570
await self._update_servers()
572571

573572
if self._publish_tp:
@@ -983,7 +982,6 @@ def _create_pool_for_monitor(self, address: _Address) -> Pool:
983982
pause_enabled=False,
984983
server_api=options.server_api,
985984
)
986-
987985
return self._settings.pool_class(
988986
address, monitor_pool_options, handshake=False, client_id=self._topology_id
989987
)

pymongo/synchronous/mongo_client.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,10 @@ def __init__(
761761
# Parse options passed as kwargs.
762762
keyword_opts = common._CaseInsensitiveDictionary(kwargs)
763763
keyword_opts["document_class"] = doc_class
764-
self._resolve_uri_info: dict[str, Any] = {"keyword_opts": keyword_opts}
764+
self._resolve_srv_info: dict[str, Any] = {"keyword_opts": keyword_opts}
765765

766766
seeds = set()
767+
is_srv = False
767768
username = None
768769
password = None
769770
dbase = None
@@ -787,6 +788,7 @@ def __init__(
787788
srv_max_hosts=srv_max_hosts,
788789
)
789790
seeds.update(res["nodelist"])
791+
is_srv = res["is_srv"] or is_srv
790792
username = res["username"] or username
791793
password = res["password"] or password
792794
dbase = res["database"] or dbase
@@ -838,33 +840,33 @@ def __init__(
838840
options.write_concern,
839841
options.read_concern,
840842
)
841-
842-
# self._topology_settings = TopologySettings(
843-
# seeds=seeds,
844-
# replica_set_name=options.replica_set_name,
845-
# pool_class=pool_class,
846-
# pool_options=options.pool_options,
847-
# monitor_class=monitor_class,
848-
# condition_class=condition_class,
849-
# local_threshold_ms=options.local_threshold_ms,
850-
# server_selection_timeout=options.server_selection_timeout,
851-
# server_selector=options.server_selector,
852-
# heartbeat_frequency=options.heartbeat_frequency,
853-
# fqdn=fqdn,
854-
# direct_connection=options.direct_connection,
855-
# load_balanced=options.load_balanced,
856-
# srv_service_name=srv_service_name,
857-
# srv_max_hosts=srv_max_hosts,
858-
# server_monitoring_mode=options.server_monitoring_mode,
859-
# )
860-
#
861-
# self._topology = Topology(self._topology_settings)
843+
if not is_srv:
844+
self._topology_settings = TopologySettings(
845+
seeds=seeds,
846+
replica_set_name=options.replica_set_name,
847+
pool_class=pool_class,
848+
pool_options=options.pool_options,
849+
monitor_class=monitor_class,
850+
condition_class=condition_class,
851+
local_threshold_ms=options.local_threshold_ms,
852+
server_selection_timeout=options.server_selection_timeout,
853+
server_selector=options.server_selector,
854+
heartbeat_frequency=options.heartbeat_frequency,
855+
fqdn=fqdn,
856+
direct_connection=options.direct_connection,
857+
load_balanced=options.load_balanced,
858+
srv_service_name=srv_service_name,
859+
srv_max_hosts=srv_max_hosts,
860+
server_monitoring_mode=options.server_monitoring_mode,
861+
)
862+
self._topology = Topology(self._topology_settings)
862863

863864
self._opened = False
864865
self._closed = False
865866

866-
self._resolve_uri_info.update(
867+
self._resolve_srv_info.update(
867868
{
869+
"is_srv": is_srv,
868870
"username": username,
869871
"password": password,
870872
"dbase": dbase,
@@ -880,8 +882,8 @@ def __init__(
880882
self._encrypter: Optional[_Encrypter] = None
881883
self._timeout = self._options.timeout
882884

883-
def _resolve_uri(self) -> None:
884-
keyword_opts = self._resolve_uri_info["keyword_opts"]
885+
def _resolve_srv(self) -> None:
886+
keyword_opts = self._resolve_srv_info["keyword_opts"]
885887
seeds = set()
886888
opts = common._CaseInsensitiveDictionary()
887889
srv_service_name = keyword_opts.get("srvservicename")
@@ -897,7 +899,7 @@ def _resolve_uri(self) -> None:
897899
timeout = common.validate_timeout_or_none_or_zero(
898900
keyword_opts.cased_key("connecttimeoutms"), timeout
899901
)
900-
res = uri_parser._lookup_uri(
902+
res = uri_parser._parse_srv(
901903
entity,
902904
self._port,
903905
validate=True,
@@ -941,10 +943,10 @@ def _resolve_uri(self) -> None:
941943
opts = self._normalize_and_validate_options(opts, seeds)
942944

943945
# Username and password passed as kwargs override user info in URI.
944-
username = opts.get("username", self._resolve_uri_info["username"])
945-
password = opts.get("password", self._resolve_uri_info["password"])
946+
username = opts.get("username", self._resolve_srv_info["username"])
947+
password = opts.get("password", self._resolve_srv_info["password"])
946948
self._options = ClientOptions(
947-
username, password, self._resolve_uri_info["dbase"], opts, _IS_SYNC
949+
username, password, self._resolve_srv_info["dbase"], opts, _IS_SYNC
948950
)
949951

950952
self._event_listeners = self._options.pool_options._event_listeners
@@ -958,22 +960,21 @@ def _resolve_uri(self) -> None:
958960
self._topology_settings = TopologySettings(
959961
seeds=seeds,
960962
replica_set_name=self._options.replica_set_name,
961-
pool_class=self._resolve_uri_info["pool_class"],
963+
pool_class=self._resolve_srv_info["pool_class"],
962964
pool_options=self._options.pool_options,
963-
monitor_class=self._resolve_uri_info["monitor_class"],
964-
condition_class=self._resolve_uri_info["condition_class"],
965+
monitor_class=self._resolve_srv_info["monitor_class"],
966+
condition_class=self._resolve_srv_info["condition_class"],
965967
local_threshold_ms=self._options.local_threshold_ms,
966968
server_selection_timeout=self._options.server_selection_timeout,
967969
server_selector=self._options.server_selector,
968970
heartbeat_frequency=self._options.heartbeat_frequency,
969-
fqdn=self._resolve_uri_info["fqdn"],
971+
fqdn=self._resolve_srv_info["fqdn"],
970972
direct_connection=self._options.direct_connection,
971973
load_balanced=self._options.load_balanced,
972974
srv_service_name=srv_service_name,
973975
srv_max_hosts=srv_max_hosts,
974976
server_monitoring_mode=self._options.server_monitoring_mode,
975977
)
976-
977978
self._topology = Topology(self._topology_settings)
978979

979980
if self._options.auto_encryption_opts:
@@ -1703,7 +1704,8 @@ def _get_topology(self) -> Topology:
17031704
launches the connection process in the background.
17041705
"""
17051706
if not self._opened:
1706-
self._resolve_uri()
1707+
if self._resolve_srv_info["is_srv"]:
1708+
self._resolve_srv()
17071709
self._init_background()
17081710
self._topology.open()
17091711
with self._lock:

pymongo/synchronous/topology.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None:
567567
if td_old.topology_type not in SRV_POLLING_TOPOLOGIES:
568568
return
569569
self._description = _updated_topology_description_srv_polling(self._description, seedlist)
570-
571570
self._update_servers()
572571

573572
if self._publish_tp:
@@ -981,7 +980,6 @@ def _create_pool_for_monitor(self, address: _Address) -> Pool:
981980
pause_enabled=False,
982981
server_api=options.server_api,
983982
)
984-
985983
return self._settings.pool_class(
986984
address, monitor_pool_options, handshake=False, client_id=self._topology_id
987985
)

pymongo/uri_parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def parse_uri(
486486
"""
487487
result = _validate_uri(uri, default_port, validate, warn, normalize, srv_max_hosts)
488488
result.update(
489-
_lookup_uri(
489+
_parse_srv(
490490
uri,
491491
default_port,
492492
validate,
@@ -586,6 +586,7 @@ def _validate_uri(
586586
_check_options(nodes, options)
587587

588588
return {
589+
"is_srv": is_srv,
589590
"nodelist": nodes,
590591
"username": user,
591592
"password": passwd,
@@ -596,7 +597,7 @@ def _validate_uri(
596597
}
597598

598599

599-
def _lookup_uri(
600+
def _parse_srv(
600601
uri: str,
601602
default_port: Optional[int] = DEFAULT_PORT,
602603
validate: bool = True,

0 commit comments

Comments
 (0)