def _optional_dependencies(): try: import ipaddress # noqa logger.debug('ipaddress module is available') ipaddr = True except ImportError: logger.warn('ipaddress module is unavailable') ipaddr = False if sys.hexversion < 0x030500F0: try: from backports.ssl_match_hostname import match_hostname, __version__ as ver ver = list(map(int, ver.split('.'))) logger.debug('backports.ssl_match_hostname module is available') match = match_hostname if ver[0] * 10 + ver[1] >= 35: return ipaddr, match else: logger.warn('backports.ssl_match_hostname module is too old') ipaddr = False except ImportError: logger.warn('backports.ssl_match_hostname is unavailable') ipaddr = False try: from ssl import match_hostname logger.debug('ssl.match_hostname is available') match = match_hostname except ImportError: logger.warn('using legacy validation callback') match = legacy_validate_callback return ipaddr, match