Python3 Migrate

This commit is contained in:
MariuszC
2020-01-18 20:01:00 +01:00
parent ea05af2d15
commit 6cd7e0fe44
691 changed files with 201846 additions and 598 deletions

View File

@@ -0,0 +1,31 @@
import logging
import re
import socket
logger = logging.getLogger(__name__)
def try_ipv6_socket():
"""Determine if system really supports IPv6"""
if not socket.has_ipv6:
return False
try:
socket.socket(socket.AF_INET6).close()
return True
except OSError as exc:
logger.debug(
f"Platform supports IPv6, but socket creation failed, "
f"disabling: {exc}"
)
return False
#: Boolean value that indicates if creating an IPv6 socket will succeed.
has_ipv6 = try_ipv6_socket()
def format_hostname(hostname):
"""Format hostname for display."""
if has_ipv6 and re.match(r"\d+.\d+.\d+.\d+", hostname) is not None:
hostname = f"::ffff:{hostname}"
return hostname