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