Skip to content

URL.Parse reads IRIs with iri=True - #639

Merged
Paebbels merged 1 commit into
devfrom
claude/url-iri
Oct 25, 2026
Merged

Paebbels merged 1 commit into
devfrom
claude/url-iri

Conversation

@pytooling-claude

Copy link
Copy Markdown

New Features

  • pyTooling.GenericPath.URL:
    • URL.Parse(url, *, iri=False) reads an IRI (RFC 3987) with iri=True, and maps it to a URL as RFC 3987 §3.1 describes, so the URL object is an RFC 3986 URL either way and str() renders it in ASCII:
    • Host.UnicodeHostname returns the hostname with its A-labels decoded to Unicode: www.xn--mller-kva.de → www.müller.de. Only labels starting with xn-- are decoded, so an ASCII label IDNA 2008 would reject (my_host) is kept; an invalid A-label (xn--zz) raises URLError with idna's reason as note.
  • New extra idna (pip install pyTooling[idna], idna >= 3.20). The package is imported where it is needed - converting a Unicode host, decoding an A-label - and its absence raises MissingDependencyError naming pyTooling[idna]. An IRI whose host is ASCII, and a hostname without A-labels, need no package.

Why IDNA 2008 with UTS #46, through the PyPI package idna:

  • Python's built-in idna codec implements IDNA 2003: "straße.de".encode("idna") is b"strasse.de", another domain than the xn--strae-oqa.de DENIC registers, and it accepts symbols IDNA 2008 disallows (☃.net → xn--n3h.net).
  • idna.encode(host, uts46=True) is the mapping the WHATWG URL Standard prescribes for browsers (domain to ASCII: UTS v2.0.0 #46, non-transitional): case folding (MÜLLER.de → xn--mller-kva.de), width mapping (müller。de, with the ideographic full stop as a dot), ß kept. Without uts46, an upper-case letter is an error. transitional is left at its default False; idna 3.20 deprecates and ignores it anyway.
  • idna is the package requests and yarl (aiohttp) depend on, so most installations carry it already. 3.20 is the latest release (2026-09-17).

Documentation

  • doc/DataStructures/Path/URL.rst has a section Internationalized Resource Identifiers (IRI): what an IRI and an A-label are, the mapping of iri=True, the www.müller.de example in an Example admonition, why the host is mapped as browsers map it (UTS v2.0.0 #46, non-transitional, straße.de, ☃.net), a table of the specifications - RFC 3986, RFC 3987, RFC 5890/5891, UTS v2.0.0 #46, WHATWG URL Standard - and what each decides, and the idna extra.
  • URL.Parse's iri parameter names IRI and RFC 3987; its doc-string and Host.UnicodeHostname's reference RFC 3987 §3.1, RFC 5890, RFC 5891 and UTS v2.0.0 #46. The module doc-string points to iri=True.
  • doc/Dependency.rst lists the idna extra's table (doc/conf.py entrypoint idna), doc/Installation.rst the extra in the list and as a tab.
  • doc/News.rst lists the feature with the other pyTooling.GenericPath.URL items.

Unit Tests

  • tests/unit/Path/URL.py:
    • New class IRIs: strict mode rejects https://www.müller.de/ (message and note) and adds no note to an ASCII syntax error; iri=True gives the A-label (with port, trailing dot), IDNA 2008 (straße.de → xn--strae-oqa.de), UTS v2.0.0 #46 mapping (upper case, full-width letters, ideographic full stop), percent-encoding of path, query and fragment, of user and password, of a path under an IPv6 host, a percent-encoded triplet kept, the str() round trip (the converted URL is ASCII and parses without iri into the same string), ASCII URLs read the same with and without iri, an IDN IDNA rejects (☃.net, an empty label), the note on an error in the converted URL, missing scheme, forbidden characters (space, U+3000), the iri parameter check, and without idna (import blocked): MissingDependencyError with dependency, extra and note, while an IRI with an ASCII host still parses.
    • New class UnicodeHostnames: A-label decoded (also upper case XN--), ASCII labels kept beside an A-label, hostnames without A-labels (DNS name, IPv4, IPv6, my_host) unchanged - also without idna -, an invalid A-label, and MissingDependencyError without idna.
  • tests/unit/requirements.txt requires idna >= 3.20, so the IRI testcases run in CI.

Related Issues and Pull-Requests

  • Builds on URL.Parse rejects strings that aren't URLs #636 (merged): URL.Parse reads strict RFC 3986 there, and iri=True maps an IRI onto that parser.
  • Agreed in the review of URL.Parse rejects strings that aren't URLs #636 (parameter iri, the RFCs and the www.müller.de example in the documentation, IDNA 2008 via idna behind an extra idna).
  • Companion in pyTooling/Actions: ComputePacboyPackages maps the extra pyTooling[idna] and the requirement idna to the MSYS2 package python-idna.

A URL of RFC 3986 holds ASCII characters only; 'https://www.müller.de/' is an
IRI (RFC 3987) with an internationalized domain name. URL.Parse(url, iri=True)
maps it to a URL as RFC 3987 section 3.1 describes, so the URL object is an
RFC 3986 URL either way:

* A Unicode host is converted to its A-labels by IDNA 2008 (RFC 5890/5891),
  via the PyPI package 'idna': idna.encode(host, uts46=True). UTS #46 mapping
  is what the WHATWG URL Standard's "domain to ASCII" does in browsers - case
  folding (MÜLLER.de), width mapping, the ideographic full stop - and is
  non-transitional: 'straße.de' -> 'xn--strae-oqa.de', where IDNA 2003 and
  Python's built-in 'idna' codec give 'strasse.de', another domain. A host IDNA
  2008 rejects ('☃.net') raises URLError with idna's reason as note.
* Every other non-ASCII character (user information, path, query, fragment)
  is percent-encoded as UTF-8; percent-encoded triplets stay.
* An error found in the converted URL names it, and a note names the IRI.
* Strict mode (default) is unchanged; its syntax error for a URL holding a
  Unicode character gets a note offering 'iri=True'.

Host.UnicodeHostname decodes A-labels (idna.decode per 'xn--' label, so an
ASCII label like 'my_host', which IDNA 2008 would reject, is kept). A hostname
without A-labels needs no 'idna' package.

'idna' is optional: new extra 'idna' (idna >= 3.20, the latest release), lazy
import where a Unicode host is converted or an A-label decoded, else
MissingDependencyError naming 'pyTooling[idna]'. tests/unit/requirements.txt
requires it, so CI runs the IRI testcases.

Docs: URL.rst section on IRIs/IDNs (RFC 3986, RFC 3987, RFC 5890/5891, UTS #46,
WHATWG URL Standard) with the www.müller.de example; Dependency.rst,
Installation.rst, conf.py list the extra; News.rst.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 25, 2026 12:58
@codacy-production

codacy-production Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 medium

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Complexity 1 medium

View in Codacy

🟢 Metrics 52 complexity · 0 duplication

Metric Results
Complexity 52
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.02% coverage variation

Metric Results
Coverage variation ✅ +0.02% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (6473d71) 16704 15326 91.75%
Head commit (16f7370) 16754 (+50) 15376 (+50) 91.78% (+0.02%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#639) 53 53 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.25%. Comparing base (6473d71) to head (16f7370).
⚠️ Report is 3 commits behind head on dev.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #639      +/-   ##
==========================================
+ Coverage   89.22%   89.25%   +0.03%     
==========================================
  Files          63       63              
  Lines       16704    16754      +50     
  Branches     2562     2570       +8     
==========================================
+ Hits        14904    14954      +50     
  Misses       1378     1378              
  Partials      422      422              
Flag Coverage Δ
unittests 89.25% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Paebbels
Paebbels merged commit 9f336df into dev Oct 25, 2026
64 of 65 checks passed
@Paebbels
Paebbels deleted the claude/url-iri branch October 25, 2026 15:05
@pytooling-claude pytooling-claude Bot mentioned this pull request Oct 25, 2026
@pytooling-claude pytooling-claude Bot added Dependencies Used by Dependabot. Documentation Improvements or additions to documentation Enhancement New feature or request GenericPath pyTooling.GenericPath Unit Tests labels Oct 26, 2026
@pytooling-claude pytooling-claude Bot added this to the v10.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dependencies Used by Dependabot. Documentation Improvements or additions to documentation Enhancement New feature or request GenericPath pyTooling.GenericPath Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants