1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-27 18:17:46 +00:00
bazarr/libs/tld/result.py
josdion a430bffe57 added tld library, fix add space after dot in domain names
- added tld library, so "Common Fixes" mod can detect domain names and won't add spaces after each dot in them.
- fix HI_before_colon_noncaps, so it won't remove http: from URLs.
2020-07-31 12:39:25 +03:00

67 lines
1.5 KiB
Python

from typing import Any, Dict
from urllib.parse import SplitResult
__author__ = 'Artur Barseghyan'
__copyright__ = '2013-2020 Artur Barseghyan'
__license__ = 'MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later'
__all__ = (
'Result',
)
class Result(object):
"""Container."""
__slots__ = ('subdomain', 'domain', 'tld', '__fld', 'parsed_url')
def __init__(self,
tld: str,
domain: str,
subdomain: str,
parsed_url: SplitResult):
self.tld = tld
self.domain = domain if domain != '' else tld
self.subdomain = subdomain
self.parsed_url = parsed_url
if domain:
self.__fld = f"{self.domain}.{self.tld}"
else:
self.__fld = self.tld
@property
def extension(self) -> str:
"""Alias of ``tld``.
:return str:
"""
return self.tld
suffix = extension
@property
def fld(self) -> str:
"""First level domain.
:return:
:rtype: str
"""
return self.__fld
def __str__(self) -> str:
return self.tld
__repr__ = __str__
@property
def __dict__(self) -> Dict[str, Any]: # type: ignore
"""Mimic __dict__ functionality.
:return:
:rtype: dict
"""
return {
'tld': self.tld,
'domain': self.domain,
'subdomain': self.subdomain,
'fld': self.fld,
'parsed_url': self.parsed_url,
}