| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Any |
| 4 |
|
| 5 |
from .core import decode, encode |
| 6 |
|
| 7 |
|
| 8 |
def ToASCII(label: str) -> bytes: |
| 9 |
"""Compatibility shim for :rfc:`3490` ``ToASCII``. |
| 10 |
|
| 11 |
Delegates to :func:`idna.encode` (IDNA 2008). Provided to ease porting |
| 12 |
of code written against the legacy :mod:`encodings.idna` API; new code |
| 13 |
should call :func:`idna.encode` directly. |
| 14 |
|
| 15 |
:param label: The label or domain to encode. |
| 16 |
:returns: The encoded form as ASCII :class:`bytes`. |
| 17 |
""" |
| 18 |
return encode(label) |
| 19 |
|
| 20 |
|
| 21 |
def ToUnicode(label: bytes | bytearray) -> str: |
| 22 |
"""Compatibility shim for :rfc:`3490` ``ToUnicode``. |
| 23 |
|
| 24 |
Delegates to :func:`idna.decode` (IDNA 2008). Provided to ease porting |
| 25 |
of code written against the legacy :mod:`encodings.idna` API; new code |
| 26 |
should call :func:`idna.decode` directly. |
| 27 |
|
| 28 |
:param label: The label or domain to decode. |
| 29 |
:returns: The decoded Unicode form. |
| 30 |
""" |
| 31 |
return decode(label) |
| 32 |
|
| 33 |
|
| 34 |
def nameprep(s: Any) -> None: |
| 35 |
"""Stub for :rfc:`3491` Nameprep, which is not used by IDNA 2008. |
| 36 |
|
| 37 |
IDNA 2008 (:rfc:`5891`) replaces Nameprep with the per-codepoint |
| 38 |
validity classes from :rfc:`5892`; this function exists only to |
| 39 |
return a clear error if legacy code attempts to call it. |
| 40 |
|
| 41 |
:raises NotImplementedError: Always. |
| 42 |
""" |
| 43 |
raise NotImplementedError("IDNA 2008 does not utilise nameprep protocol") |