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)
| 425 | |
| 426 | |
| 427 | def 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 |