tld package¶
Submodules¶
tld.conf module¶
tld.defaults module¶
tld.exceptions module¶
-
exception
tld.exceptions.
TldBadUrl
(url)[source]¶ Bases:
exceptions.ValueError
TldBadUrl.
Supposed to be thrown when bad URL is given.
-
exception
tld.exceptions.
TldDomainNotFound
(domain_name)[source]¶ Bases:
exceptions.ValueError
TldDomainNotFound.
Supposed to be thrown when domain name is not found (didn’t match) the local TLD policy.
tld.test module¶
tld.utils module¶
-
tld.utils.
get_fld
(url, active_only=False, fail_silently=False, fix_protocol=False, search_public=True, search_private=True, **kwargs)[source]¶ Extract the first level domain.
Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw
TldBadUrl
orTldDomainNotFound
exceptions if there’s bad URL provided or no TLD match found respectively.Parameters: - url (str) – URL to get top level domain from.
- active_only (bool) – If set to True, only active patterns are matched.
- fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
- search_public (bool) – If set to True, search in public domains.
- search_private (bool) – If set to True, search in private domains.
Returns: String with top level domain (if
as_object
argument is set to False) or atld.utils.Result
object (ifas_object
argument is set to True); returns None on failure.Return type: str
-
tld.utils.
get_tld
(url, active_only=False, fail_silently=False, as_object=False, fix_protocol=False, search_public=True, search_private=True)[source]¶ Extract the top level domain.
Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw
TldBadUrl
orTldDomainNotFound
exceptions if there’s bad URL provided or no TLD match found respectively.Parameters: - url (str) – URL to get top level domain from.
- active_only (bool) – If set to True, only active patterns are matched.
- fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- as_object (bool) – If set to True,
tld.utils.Result
object is returned,domain
,suffix
andtld
properties. - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
- search_public (bool) – If set to True, search in public domains.
- search_private (bool) – If set to True, search in private domains.
Returns: String with top level domain (if
as_object
argument is set to False) or atld.utils.Result
object (ifas_object
argument is set to True); returns None on failure.Return type: str
-
tld.utils.
get_tld_names
(fail_silently=False, retry_count=0)[source]¶ Build the
tlds
list if empty. Recursive.Parameters: - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- retry_count (int) – If greater than 1, we raise an exception in order to avoid infinite loops.
Returns: List of TLD names
Type: iterable
-
tld.utils.
process_url
(url, active_only=False, fail_silently=False, fix_protocol=False, search_public=True, search_private=True)[source]¶ Process URL.
Parameters: - url –
- active_only –
- fail_silently –
- fix_protocol –
- search_public –
- search_private –
Returns:
Module contents¶
-
tld.
get_fld
(url, active_only=False, fail_silently=False, fix_protocol=False, search_public=True, search_private=True, **kwargs)[source]¶ Extract the first level domain.
Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw
TldBadUrl
orTldDomainNotFound
exceptions if there’s bad URL provided or no TLD match found respectively.Parameters: - url (str) – URL to get top level domain from.
- active_only (bool) – If set to True, only active patterns are matched.
- fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
- search_public (bool) – If set to True, search in public domains.
- search_private (bool) – If set to True, search in private domains.
Returns: String with top level domain (if
as_object
argument is set to False) or atld.utils.Result
object (ifas_object
argument is set to True); returns None on failure.Return type: str
-
tld.
get_tld
(url, active_only=False, fail_silently=False, as_object=False, fix_protocol=False, search_public=True, search_private=True)[source]¶ Extract the top level domain.
Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw
TldBadUrl
orTldDomainNotFound
exceptions if there’s bad URL provided or no TLD match found respectively.Parameters: - url (str) – URL to get top level domain from.
- active_only (bool) – If set to True, only active patterns are matched.
- fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- as_object (bool) – If set to True,
tld.utils.Result
object is returned,domain
,suffix
andtld
properties. - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
- search_public (bool) – If set to True, search in public domains.
- search_private (bool) – If set to True, search in private domains.
Returns: String with top level domain (if
as_object
argument is set to False) or atld.utils.Result
object (ifas_object
argument is set to True); returns None on failure.Return type: str
-
tld.
get_tld_names
(fail_silently=False, retry_count=0)[source]¶ Build the
tlds
list if empty. Recursive.Parameters: - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
- retry_count (int) – If greater than 1, we raise an exception in order to avoid infinite loops.
Returns: List of TLD names
Type: iterable