| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: idna |
| 3 |
Version: 3.10 |
| 4 |
Summary: Internationalized Domain Names in Applications (IDNA) |
| 5 |
Author-email: Kim Davies <[email protected]> |
| 6 |
Requires-Python: >=3.6 |
| 7 |
Description-Content-Type: text/x-rst |
| 8 |
Classifier: Development Status :: 5 - Production/Stable |
| 9 |
Classifier: Intended Audience :: Developers |
| 10 |
Classifier: Intended Audience :: System Administrators |
| 11 |
Classifier: License :: OSI Approved :: BSD License |
| 12 |
Classifier: Operating System :: OS Independent |
| 13 |
Classifier: Programming Language :: Python |
| 14 |
Classifier: Programming Language :: Python :: 3 |
| 15 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 16 |
Classifier: Programming Language :: Python :: 3.6 |
| 17 |
Classifier: Programming Language :: Python :: 3.7 |
| 18 |
Classifier: Programming Language :: Python :: 3.8 |
| 19 |
Classifier: Programming Language :: Python :: 3.9 |
| 20 |
Classifier: Programming Language :: Python :: 3.10 |
| 21 |
Classifier: Programming Language :: Python :: 3.11 |
| 22 |
Classifier: Programming Language :: Python :: 3.12 |
| 23 |
Classifier: Programming Language :: Python :: 3.13 |
| 24 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 25 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 26 |
Classifier: Topic :: Internet :: Name Service (DNS) |
| 27 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 28 |
Classifier: Topic :: Utilities |
| 29 |
Requires-Dist: ruff >= 0.6.2 ; extra == "all" |
| 30 |
Requires-Dist: mypy >= 1.11.2 ; extra == "all" |
| 31 |
Requires-Dist: pytest >= 8.3.2 ; extra == "all" |
| 32 |
Requires-Dist: flake8 >= 7.1.1 ; extra == "all" |
| 33 |
Project-URL: Changelog, https://github.com/kjd/idna/blob/master/HISTORY.rst |
| 34 |
Project-URL: Issue tracker, https://github.com/kjd/idna/issues |
| 35 |
Project-URL: Source, https://github.com/kjd/idna |
| 36 |
Provides-Extra: all |
| 37 |
|
| 38 |
Internationalized Domain Names in Applications (IDNA) |
| 39 |
===================================================== |
| 40 |
|
| 41 |
Support for the Internationalized Domain Names in |
| 42 |
Applications (IDNA) protocol as specified in `RFC 5891 |
| 43 |
<https://tools.ietf.org/html/rfc5891>`_. This is the latest version of |
| 44 |
the protocol and is sometimes referred to as “IDNA 2008”. |
| 45 |
|
| 46 |
This library also provides support for Unicode Technical |
| 47 |
Standard 46, `Unicode IDNA Compatibility Processing |
| 48 |
<https://unicode.org/reports/tr46/>`_. |
| 49 |
|
| 50 |
This acts as a suitable replacement for the “encodings.idna” |
| 51 |
module that comes with the Python standard library, but which |
| 52 |
only supports the older superseded IDNA specification (`RFC 3490 |
| 53 |
<https://tools.ietf.org/html/rfc3490>`_). |
| 54 |
|
| 55 |
Basic functions are simply executed: |
| 56 |
|
| 57 |
.. code-block:: pycon |
| 58 |
|
| 59 |
>>> import idna |
| 60 |
>>> idna.encode('ドメイン.テスト') |
| 61 |
b'xn--eckwd4c7c.xn--zckzah' |
| 62 |
>>> print(idna.decode('xn--eckwd4c7c.xn--zckzah')) |
| 63 |
ドメイン.テスト |
| 64 |
|
| 65 |
|
| 66 |
Installation |
| 67 |
------------ |
| 68 |
|
| 69 |
This package is available for installation from PyPI: |
| 70 |
|
| 71 |
.. code-block:: bash |
| 72 |
|
| 73 |
$ python3 -m pip install idna |
| 74 |
|
| 75 |
|
| 76 |
Usage |
| 77 |
----- |
| 78 |
|
| 79 |
For typical usage, the ``encode`` and ``decode`` functions will take a |
| 80 |
domain name argument and perform a conversion to A-labels or U-labels |
| 81 |
respectively. |
| 82 |
|
| 83 |
.. code-block:: pycon |
| 84 |
|
| 85 |
>>> import idna |
| 86 |
>>> idna.encode('ドメイン.テスト') |
| 87 |
b'xn--eckwd4c7c.xn--zckzah' |
| 88 |
>>> print(idna.decode('xn--eckwd4c7c.xn--zckzah')) |
| 89 |
ドメイン.テスト |
| 90 |
|
| 91 |
You may use the codec encoding and decoding methods using the |
| 92 |
``idna.codec`` module: |
| 93 |
|
| 94 |
.. code-block:: pycon |
| 95 |
|
| 96 |
>>> import idna.codec |
| 97 |
>>> print('домен.испытание'.encode('idna2008')) |
| 98 |
b'xn--d1acufc.xn--80akhbyknj4f' |
| 99 |
>>> print(b'xn--d1acufc.xn--80akhbyknj4f'.decode('idna2008')) |
| 100 |
домен.испытание |
| 101 |
|
| 102 |
Conversions can be applied at a per-label basis using the ``ulabel`` or |
| 103 |
``alabel`` functions if necessary: |
| 104 |
|
| 105 |
.. code-block:: pycon |
| 106 |
|
| 107 |
>>> idna.alabel('测试') |
| 108 |
b'xn--0zwm56d' |
| 109 |
|
| 110 |
Compatibility Mapping (UTS #46) |
| 111 |
+++++++++++++++++++++++++++++++ |
| 112 |
|
| 113 |
As described in `RFC 5895 <https://tools.ietf.org/html/rfc5895>`_, the |
| 114 |
IDNA specification does not normalize input from different potential |
| 115 |
ways a user may input a domain name. This functionality, known as |
| 116 |
a “mapping”, is considered by the specification to be a local |
| 117 |
user-interface issue distinct from IDNA conversion functionality. |
| 118 |
|
| 119 |
This library provides one such mapping that was developed by the |
| 120 |
Unicode Consortium. Known as `Unicode IDNA Compatibility Processing |
| 121 |
<https://unicode.org/reports/tr46/>`_, it provides for both a regular |
| 122 |
mapping for typical applications, as well as a transitional mapping to |
| 123 |
help migrate from older IDNA 2003 applications. Strings are |
| 124 |
preprocessed according to Section 4.4 “Preprocessing for IDNA2008” |
| 125 |
prior to the IDNA operations. |
| 126 |
|
| 127 |
For example, “Königsgäßchen” is not a permissible label as *LATIN |
| 128 |
CAPITAL LETTER K* is not allowed (nor are capital letters in general). |
| 129 |
UTS 46 will convert this into lower case prior to applying the IDNA |
| 130 |
conversion. |
| 131 |
|
| 132 |
.. code-block:: pycon |
| 133 |
|
| 134 |
>>> import idna |
| 135 |
>>> idna.encode('Königsgäßchen') |
| 136 |
... |
| 137 |
idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed |
| 138 |
>>> idna.encode('Königsgäßchen', uts46=True) |
| 139 |
b'xn--knigsgchen-b4a3dun' |
| 140 |
>>> print(idna.decode('xn--knigsgchen-b4a3dun')) |
| 141 |
königsgäßchen |
| 142 |
|
| 143 |
Transitional processing provides conversions to help transition from |
| 144 |
the older 2003 standard to the current standard. For example, in the |
| 145 |
original IDNA specification, the *LATIN SMALL LETTER SHARP S* (ß) was |
| 146 |
converted into two *LATIN SMALL LETTER S* (ss), whereas in the current |
| 147 |
IDNA specification this conversion is not performed. |
| 148 |
|
| 149 |
.. code-block:: pycon |
| 150 |
|
| 151 |
>>> idna.encode('Königsgäßchen', uts46=True, transitional=True) |
| 152 |
'xn--knigsgsschen-lcb0w' |
| 153 |
|
| 154 |
Implementers should use transitional processing with caution, only in |
| 155 |
rare cases where conversion from legacy labels to current labels must be |
| 156 |
performed (i.e. IDNA implementations that pre-date 2008). For typical |
| 157 |
applications that just need to convert labels, transitional processing |
| 158 |
is unlikely to be beneficial and could produce unexpected incompatible |
| 159 |
results. |
| 160 |
|
| 161 |
``encodings.idna`` Compatibility |
| 162 |
++++++++++++++++++++++++++++++++ |
| 163 |
|
| 164 |
Function calls from the Python built-in ``encodings.idna`` module are |
| 165 |
mapped to their IDNA 2008 equivalents using the ``idna.compat`` module. |
| 166 |
Simply substitute the ``import`` clause in your code to refer to the new |
| 167 |
module name. |
| 168 |
|
| 169 |
Exceptions |
| 170 |
---------- |
| 171 |
|
| 172 |
All errors raised during the conversion following the specification |
| 173 |
should raise an exception derived from the ``idna.IDNAError`` base |
| 174 |
class. |
| 175 |
|
| 176 |
More specific exceptions that may be generated as ``idna.IDNABidiError`` |
| 177 |
when the error reflects an illegal combination of left-to-right and |
| 178 |
right-to-left characters in a label; ``idna.InvalidCodepoint`` when |
| 179 |
a specific codepoint is an illegal character in an IDN label (i.e. |
| 180 |
INVALID); and ``idna.InvalidCodepointContext`` when the codepoint is |
| 181 |
illegal based on its positional context (i.e. it is CONTEXTO or CONTEXTJ |
| 182 |
but the contextual requirements are not satisfied.) |
| 183 |
|
| 184 |
Building and Diagnostics |
| 185 |
------------------------ |
| 186 |
|
| 187 |
The IDNA and UTS 46 functionality relies upon pre-calculated lookup |
| 188 |
tables for performance. These tables are derived from computing against |
| 189 |
eligibility criteria in the respective standards. These tables are |
| 190 |
computed using the command-line script ``tools/idna-data``. |
| 191 |
|
| 192 |
This tool will fetch relevant codepoint data from the Unicode repository |
| 193 |
and perform the required calculations to identify eligibility. There are |
| 194 |
three main modes: |
| 195 |
|
| 196 |
* ``idna-data make-libdata``. Generates ``idnadata.py`` and |
| 197 |
``uts46data.py``, the pre-calculated lookup tables used for IDNA and |
| 198 |
UTS 46 conversions. Implementers who wish to track this library against |
| 199 |
a different Unicode version may use this tool to manually generate a |
| 200 |
different version of the ``idnadata.py`` and ``uts46data.py`` files. |
| 201 |
|
| 202 |
* ``idna-data make-table``. Generate a table of the IDNA disposition |
| 203 |
(e.g. PVALID, CONTEXTJ, CONTEXTO) in the format found in Appendix |
| 204 |
B.1 of RFC 5892 and the pre-computed tables published by `IANA |
| 205 |
<https://www.iana.org/>`_. |
| 206 |
|
| 207 |
* ``idna-data U+0061``. Prints debugging output on the various |
| 208 |
properties associated with an individual Unicode codepoint (in this |
| 209 |
case, U+0061), that are used to assess the IDNA and UTS 46 status of a |
| 210 |
codepoint. This is helpful in debugging or analysis. |
| 211 |
|
| 212 |
The tool accepts a number of arguments, described using ``idna-data |
| 213 |
-h``. Most notably, the ``--version`` argument allows the specification |
| 214 |
of the version of Unicode to be used in computing the table data. For |
| 215 |
example, ``idna-data --version 9.0.0 make-libdata`` will generate |
| 216 |
library data against Unicode 9.0.0. |
| 217 |
|
| 218 |
|
| 219 |
Additional Notes |
| 220 |
---------------- |
| 221 |
|
| 222 |
* **Packages**. The latest tagged release version is published in the |
| 223 |
`Python Package Index <https://pypi.org/project/idna/>`_. |
| 224 |
|
| 225 |
* **Version support**. This library supports Python 3.6 and higher. |
| 226 |
As this library serves as a low-level toolkit for a variety of |
| 227 |
applications, many of which strive for broad compatibility with older |
| 228 |
Python versions, there is no rush to remove older interpreter support. |
| 229 |
Removing support for older versions should be well justified in that the |
| 230 |
maintenance burden has become too high. |
| 231 |
|
| 232 |
* **Python 2**. Python 2 is supported by version 2.x of this library. |
| 233 |
Use "idna<3" in your requirements file if you need this library for |
| 234 |
a Python 2 application. Be advised that these versions are no longer |
| 235 |
actively developed. |
| 236 |
|
| 237 |
* **Testing**. The library has a test suite based on each rule of the |
| 238 |
IDNA specification, as well as tests that are provided as part of the |
| 239 |
Unicode Technical Standard 46, `Unicode IDNA Compatibility Processing |
| 240 |
<https://unicode.org/reports/tr46/>`_. |
| 241 |
|
| 242 |
* **Emoji**. It is an occasional request to support emoji domains in |
| 243 |
this library. Encoding of symbols like emoji is expressly prohibited by |
| 244 |
the technical standard IDNA 2008 and emoji domains are broadly phased |
| 245 |
out across the domain industry due to associated security risks. For |
| 246 |
now, applications that need to support these non-compliant labels |
| 247 |
may wish to consider trying the encode/decode operation in this library |
| 248 |
first, and then falling back to using `encodings.idna`. See `the Github |
| 249 |
project <https://github.com/kjd/idna/issues/18>`_ for more discussion. |
| 250 |
|