How to use the tld.exceptions.TldDomainNotFound function in tld

To help you get started, we’ve selected a few tld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carsonyl / pypac / pypac / wpad.py View on Github external
: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)
github WebarchivCZ / Seeder / Seeder / source / models.py View on Github external
def validate_tld(value):
    try:
        tld.get_tld(value)
    except TldDomainNotFound:
        raise ValidationError('Invalid domain name')

tld

Extract the top-level domain (TLD) from the URL given.

MPL-1.1 OR GPL-2.0-only OR LG…
Latest version published 2 years ago

Package Health Score

76 / 100
Full package analysis