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

Function split_hosts

pymongo/uri_parser_shared.py:427–448  ·  view source on GitHub ↗

Takes a string of the form host1[:port],host2[:port]... and splits it into (host, port) tuples. If [:port] isn't present the default_port is used. Returns a set of 2-tuples containing the host name (or IP) followed by port number. :param hosts: A string of the form host1[:port]

(hosts: str, default_port: Optional[int] = DEFAULT_PORT)

Source from the content-addressed store, hash-verified

425
426
427def split_hosts(hosts: str, default_port: Optional[int] = DEFAULT_PORT) -> list[_Address]:
428 """Takes a string of the form host1[:port],host2[:port]... and
429 splits it into (host, port) tuples. If [:port] isn't present the
430 default_port is used.
431
432 Returns a set of 2-tuples containing the host name (or IP) followed by
433 port number.
434
435 :param hosts: A string of the form host1[:port],host2[:port],...
436 :param default_port: The port number to use when one wasn't specified
437 for a host.
438 """
439 nodes = []
440 for entity in hosts.split(","):
441 if not entity:
442 raise ConfigurationError("Empty host (or extra comma in host list)")
443 port = default_port
444 # Unix socket entities don't have ports
445 if entity.endswith(".sock"):
446 port = None
447 nodes.append(parse_host(entity, port))
448 return nodes
449
450
451# Prohibited characters in database name. DB names also can't have ".", but for

Callers 10

test_split_hostsMethod · 0.90
run_testFunction · 0.90
run_testFunction · 0.90
_parse_srvFunction · 0.90
__init__Method · 0.90
_resolve_srvMethod · 0.90
_parse_srvFunction · 0.90
__init__Method · 0.90
_resolve_srvMethod · 0.90
_validate_uriFunction · 0.85

Calls 2

ConfigurationErrorClass · 0.90
parse_hostFunction · 0.85

Tested by 3

test_split_hostsMethod · 0.72
run_testFunction · 0.72
run_testFunction · 0.72