aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/tld/exceptions.py
blob: b8a24d193d337e26fdd7e9c421c987caf2e954e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
__author__ = 'Artur Barseghyan'
__copyright__ = '2013-2020 Artur Barseghyan'
__license__ = 'MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later'
__all__ = (
    'TldBadUrl',
    'TldDomainNotFound',
    'TldImproperlyConfigured',
    'TldIOError',
)


class TldIOError(IOError):
    """TldIOError.

    Supposed to be thrown when problems with reading/writing occur.
    """


class TldDomainNotFound(ValueError):
    """TldDomainNotFound.

    Supposed to be thrown when domain name is not found (didn't match) the
    local TLD policy.
    """

    def __init__(self, domain_name):
        super(TldDomainNotFound, self).__init__(
            "Domain %s didn't match any existing TLD name!" % domain_name
        )


class TldBadUrl(ValueError):
    """TldBadUrl.

    Supposed to be thrown when bad URL is given.
    """

    def __init__(self, url):
        super(TldBadUrl, self).__init__("Is not a valid URL %s!" % url)


class TldImproperlyConfigured(Exception):
    """TldImproperlyConfigured.

    Supposed to be thrown when code is improperly configured. Typical use-case
    is when user tries to use `get_tld` function with both `search_public` and
    `search_private` set to False.
    """

    def __init__(self, msg=None):
        if msg is None:
            msg = "Improperly configured."
        else:
            msg = "Improperly configured. %s" % msg

        super(TldImproperlyConfigured, self).__init__(msg)