MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _resolve_srv

Method _resolve_srv

pymongo/synchronous/mongo_client.py:910–977  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

908 self._get_topology() # type: ignore[unused-coroutine]
909
910 def _resolve_srv(self) -> None:
911 keyword_opts = self._resolve_srv_info["keyword_opts"]
912 seeds = set()
913 opts = common._CaseInsensitiveDictionary()
914 srv_service_name = keyword_opts.get("srvservicename")
915 srv_max_hosts = keyword_opts.get("srvmaxhosts")
916 for entity in self._host:
917 # A hostname can only include a-z, 0-9, '-' and '.'. If we find a '/'
918 # it must be a URI,
919 # https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
920 if "/" in entity:
921 # Determine connection timeout from kwargs.
922 timeout = keyword_opts.get("connecttimeoutms")
923 if timeout is not None:
924 timeout = common.validate_timeout_or_none_or_zero(
925 keyword_opts.cased_key("connecttimeoutms"), timeout
926 )
927 res = uri_parser._parse_srv(
928 entity,
929 self._port,
930 validate=True,
931 warn=True,
932 normalize=False,
933 connect_timeout=timeout,
934 srv_service_name=srv_service_name,
935 srv_max_hosts=srv_max_hosts,
936 )
937 seeds.update(res["nodelist"])
938 opts = res["options"]
939 else:
940 seeds.update(split_hosts(entity, self._port))
941
942 if not seeds:
943 raise ConfigurationError("need to specify at least one host")
944
945 for hostname in [node[0] for node in seeds]:
946 if _detect_external_db(hostname):
947 break
948
949 # Add options with named keyword arguments to the parsed kwarg options.
950 tz_aware = keyword_opts["tz_aware"]
951 connect = keyword_opts["connect"]
952 if tz_aware is None:
953 tz_aware = opts.get("tz_aware", False)
954 if connect is None:
955 # Default to connect=True unless on a FaaS system, which might use fork.
956 from pymongo.pool_options import _is_faas
957
958 connect = opts.get("connect", not _is_faas())
959 keyword_opts["tz_aware"] = tz_aware
960 keyword_opts["connect"] = connect
961
962 opts = self._validate_kwargs_and_update_opts(keyword_opts, opts)
963
964 if srv_service_name is None:
965 srv_service_name = opts.get("srvServiceName", common.SRV_SERVICE_NAME)
966
967 srv_max_hosts = srv_max_hosts or opts.get("srvmaxhosts")

Callers 1

_get_topologyMethod · 0.95

Calls 11

split_hostsFunction · 0.90
ConfigurationErrorClass · 0.90
_is_faasFunction · 0.90
ClientOptionsClass · 0.90
cased_keyMethod · 0.80
_detect_external_dbFunction · 0.70
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected