$27 GRAYBYTE WORDPRESS FILE MANAGER $83

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 91.108.106.10 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/validators/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/validators//domain.py
"""Domain."""

# standard
from pathlib import Path
import re

# local
from .utils import validator


def _iana_tld():
    """Load IANA TLDs as a Generator."""
    with Path(__file__).parent.joinpath("_tld.txt").open() as tld_f:
        _ = next(tld_f)  # ignore the first line
        for line in tld_f:
            yield line.strip()


@validator
def domain(
    value: str, /, *, consider_tld: bool = False, rfc_1034: bool = False, rfc_2782: bool = False
):
    """Return whether or not given value is a valid domain.

    Examples:
        >>> domain('example.com')
        # Output: True
        >>> domain('example.com/')
        # Output: ValidationError(func=domain, ...)
        >>> # Supports IDN domains as well::
        >>> domain('xn----gtbspbbmkef.xn--p1ai')
        # Output: True

    Args:
        value:
            Domain string to validate.
        consider_tld:
            Restrict domain to TLDs allowed by IANA.
        rfc_1034:
            Allows optional trailing dot in the domain name.
            Ref: [RFC 1034](https://www.rfc-editor.org/rfc/rfc1034).
        rfc_2782:
            Domain name is of type service record.
            Allows optional underscores in the domain name.
            Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782).


    Returns:
        (Literal[True]): If `value` is a valid domain name.
        (ValidationError): If `value` is an invalid domain name.

    Raises:
        (UnicodeError): If `value` cannot be encoded into `idna` or decoded into `utf-8`.
    """
    if not value:
        return False

    if consider_tld and value.rstrip(".").rsplit(".", 1)[-1].upper() not in _iana_tld():
        return False

    try:

        service_record = r"_" if rfc_2782 else ""
        trailing_dot = r"\.?$" if rfc_1034 else r"$"

        return not re.search(r"\s|__+", value) and re.match(
            # First character of the domain
            rf"^(?:[a-z0-9{service_record}]"
            # Sub-domain
            + rf"(?:[a-z0-9-{service_record}]{{0,61}}"
            # Hostname
            + rf"[a-z0-9{service_record}])?\.)"
            # First 61 characters of the gTLD
            + r"+[a-z0-9][a-z0-9-_]{0,61}"
            # Last character of the gTLD
            + rf"[a-z]{trailing_dot}",
            value.encode("idna").decode("utf-8"),
            re.IGNORECASE,
        )
    except UnicodeError as err:
        raise UnicodeError(f"Unable to encode/decode {value}") from err

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
5 Sep 2025 9.32 AM
root / 996
0755
__pycache__
--
8 May 2024 6.34 PM
root / root
0755
i18n
--
8 May 2024 6.34 PM
root / root
0755
__init__.py
1.86 KB
8 May 2024 6.34 PM
root / root
0644
_extremes.py
1.014 KB
8 May 2024 6.34 PM
root / root
0644
_tld.txt
9.401 KB
8 May 2024 6.34 PM
root / root
0644
between.py
2.387 KB
8 May 2024 6.34 PM
root / root
0644
btc_address.py
1.616 KB
8 May 2024 6.34 PM
root / root
0644
card.py
5.631 KB
8 May 2024 6.34 PM
root / root
0644
country.py
14.569 KB
8 May 2024 6.34 PM
root / root
0644
cron.py
2.228 KB
8 May 2024 6.34 PM
root / root
0644
domain.py
2.401 KB
8 May 2024 6.34 PM
root / root
0644
email.py
2.723 KB
8 May 2024 6.34 PM
root / root
0644
encoding.py
1.337 KB
8 May 2024 6.34 PM
root / root
0644
finance.py
3.222 KB
8 May 2024 6.34 PM
root / root
0644
hashes.py
3.21 KB
8 May 2024 6.34 PM
root / root
0644
hostname.py
4.046 KB
8 May 2024 6.34 PM
root / root
0644
iban.py
1.054 KB
8 May 2024 6.34 PM
root / root
0644
ip_address.py
4.341 KB
8 May 2024 6.34 PM
root / root
0644
length.py
1.45 KB
8 May 2024 6.34 PM
root / root
0644
mac_address.py
0.845 KB
8 May 2024 6.34 PM
root / root
0644
py.typed
0 KB
8 May 2024 6.34 PM
root / root
0644
slug.py
0.732 KB
8 May 2024 6.34 PM
root / root
0644
uri.py
1.777 KB
8 May 2024 6.34 PM
root / root
0644
url.py
7.231 KB
8 May 2024 6.34 PM
root / root
0644
utils.py
3.103 KB
8 May 2024 6.34 PM
root / root
0644
uuid.py
1.039 KB
8 May 2024 6.34 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF