You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mailu/core/base/libs/socrate/socrate/system.py

21 lines
658 B
Python

6 years ago
import socket
import tenacity
@retry(stop=tenacity.stop_after_attempt(100),
wait=tenacity.wait_random(min=2, max=5))
def resolve_hostname(hostname):
""" This function uses system DNS to resolve a hostname.
It is capable of retrying in case the host is not immediately available
"""
return socket.gethostbyname(hostname)
def resolve_address(address):
""" This function is identical to ``resolve_host`` but also supports
resolving an address, i.e. including a port.
"""
hostname, *rest = address.resplit(":", 1)
ip_address = resolve_hostname(hostname)
return ip_address + "".join(":" + port for port in rest)