Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param str local_hostname: Hostname to use for generating the WPAD URLs.
If not provided, the local hostname is used.
:return: PAC URLs to try in order, according to the WPAD protocol.
If the hostname isn't qualified or is otherwise invalid, an empty list is returned.
:rtype: list[str]
"""
if not local_hostname:
local_hostname = socket.getfqdn()
if '.' not in local_hostname or len(local_hostname) < 3 or \
local_hostname.startswith('.') or local_hostname.endswith('.'):
return []
try:
parsed = get_tld('http://' + local_hostname, as_object=True)
subdomain, tld = parsed.subdomain, parsed.fld
except TldDomainNotFound:
final_dot_index = local_hostname.rfind('.')
subdomain, tld = local_hostname[0:final_dot_index], local_hostname[final_dot_index+1:]
return wpad_search_urls(subdomain, tld)
def validate_tld(value):
try:
tld.get_tld(value)
except TldDomainNotFound:
raise ValidationError('Invalid domain name')