CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dnspython

DNS toolkit for Python supporting almost all record types with high-level and low-level DNS operations

85

1.37x
Overview
Eval results
Files

task.mdevals/scenario-2/

Domain Normalizer

Build a small library that normalizes and inspects domain names with full IDNA handling.

Capabilities

Normalize inputs to canonical ASCII

  • Converts a mix of Unicode and ASCII domain strings to lowercase absolute ASCII with trailing dot, applying IDNA so ["Example.com", "bücher.example", "Example.com."] becomes ["example.com.", "xn--bcher-kva.example."] (duplicate removed). @test
  • Rejects names with empty labels or illegal characters by raising ValueError. @test

Unicode rendering

  • Produces Unicode representation (with trailing dot) when given a canonical ASCII domain such as xn--bcher-kva.example. returning bücher.example. @test

Hierarchy awareness

  • Determines whether api.eu.Example.com is inside example.com. after normalization (True) and example.net is not. @test
  • Returns the longest shared suffix between mail.bücher.example and bücher.example as xn--bcher-kva.example. (root represented as "." when no shared labels). @test

Implementation

@generates

API

from collections.abc import Iterable
from typing import List

def normalize_ascii(names: Iterable[str]) -> List[str]:
    """Normalize iterable of domain strings to canonical ASCII with trailing dots, removing duplicates in first-seen order and raising ValueError on invalid input."""

def to_unicode(name: str) -> str:
    """Render a canonical ASCII domain to Unicode with trailing dot preserved."""

def is_subdomain(candidate: str, parent: str) -> bool:
    """Return True if candidate is within parent after normalization, otherwise False."""

def common_suffix(name1: str, name2: str) -> str:
    """Return longest shared suffix of two domains as canonical ASCII with trailing dot (or '.' for the root)."""

Dependencies { .dependencies }

dnspython { .dependency }

Provides domain modeling and IDNA conversion utilities.

Install with Tessl CLI

npx tessl i tessl/pypi-dnspython

tile.json