METADATA 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. Metadata-Version: 2.5
  2. Name: idna
  3. Version: 3.19
  4. Summary: Internationalized Domain Names in Applications (IDNA)
  5. Author-email: Kim Davies <kim+pypi@gumleaf.org>
  6. Requires-Python: >=3.9
  7. Description-Content-Type: text/markdown
  8. License-Expression: BSD-3-Clause
  9. Classifier: Development Status :: 5 - Production/Stable
  10. Classifier: Intended Audience :: Developers
  11. Classifier: Intended Audience :: System Administrators
  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.9
  17. Classifier: Programming Language :: Python :: 3.10
  18. Classifier: Programming Language :: Python :: 3.11
  19. Classifier: Programming Language :: Python :: 3.12
  20. Classifier: Programming Language :: Python :: 3.13
  21. Classifier: Programming Language :: Python :: 3.14
  22. Classifier: Programming Language :: Python :: Implementation :: CPython
  23. Classifier: Programming Language :: Python :: Implementation :: PyPy
  24. Classifier: Topic :: Internet :: Name Service (DNS)
  25. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  26. Classifier: Topic :: Utilities
  27. License-File: LICENSE.md
  28. Requires-Dist: ruff >= 0.16.0 ; extra == "all"
  29. Requires-Dist: mypy >= 1.11.2 ; extra == "all"
  30. Requires-Dist: ty >= 0.0.37 ; extra == "all"
  31. Requires-Dist: pytest >= 8.3.2 ; extra == "all"
  32. Requires-Dist: hypothesis >= 6.141.1 ; extra == "all"
  33. Requires-Dist: coverage >= 7.10.0 ; extra == "all"
  34. Project-URL: Changelog, https://github.com/kjd/idna/blob/master/HISTORY.md
  35. Project-URL: Issue tracker, https://github.com/kjd/idna/issues
  36. Project-URL: Source, https://github.com/kjd/idna
  37. Provides-Extra: all
  38. Import-Name: idna
  39. # Internationalized Domain Names in Applications (IDNA)
  40. Support for [Internationalized Domain Names in Applications
  41. (IDNA)](https://tools.ietf.org/html/rfc5891) and [Unicode IDNA
  42. Compatibility Processing](https://unicode.org/reports/tr46/). It
  43. supersedes the standard library's `encodings.idna`, which only
  44. implements the 2003 specification, offering broader script coverage and
  45. limiting domains with known security vulnerabilities.
  46. ## Usage
  47. Package may be installed from [PyPI](https://pypi.org/project/idna/) via
  48. the typical methods (e.g. `python3 -m pip install idna`)
  49. For typical usage, the `encode` and `decode` functions will take a
  50. domain name argument and perform a conversion to ASCII-compatible encoding
  51. (known as A-labels), or to Unicode strings (known as U-labels)
  52. respectively.
  53. ```pycon
  54. >>> import idna
  55. >>> idna.encode('ドメイン.テスト')
  56. b'xn--eckwd4c7c.xn--zckzah'
  57. >>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
  58. ドメイン.テスト
  59. ```
  60. Conversions can be applied at a per-label basis using the `ulabel` or
  61. `alabel` functions for specialized use cases.
  62. ### Compatibility Mapping (UTS #46)
  63. This library provides support for [Unicode IDNA Compatibility
  64. Processing](https://unicode.org/reports/tr46/) which normalizes input from
  65. different potential ways a user may input a domain prior to performing the IDNA
  66. conversion operations. This functionality, known as a
  67. [mapping](https://tools.ietf.org/html/rfc5895), is considered by the
  68. specification to be a local user-interface issue distinct from IDNA
  69. conversion functionality.
  70. For example, "Königsgäßchen" is not a permissible label as capital letters
  71. are not allowed. UTS #46 will convert this into lower case prior to applying
  72. the IDNA conversion.
  73. ```pycon
  74. >>> import idna
  75. >>> idna.encode('Königsgäßchen')
  76. ...
  77. idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
  78. >>> idna.encode('Königsgäßchen', uts46=True)
  79. b'xn--knigsgchen-b4a3dun'
  80. >>> idna.decode('xn--knigsgchen-b4a3dun')
  81. 'königsgäßchen'
  82. ```
  83. When performing a decode operation for display purposes, `decode()`
  84. accepts a `display=True` argument that leaves any `xn--` label that
  85. fails to decode unchanged. This is useful for user interface display
  86. where a domain is in use, the A-label form can be presented when it
  87. is not a valid IDN.
  88. ## Exceptions
  89. All errors raised during conversion derive from the `idna.IDNAError`
  90. base class. The more specific exceptions are:
  91. * `idna.IDNABidiError` — raised when a label contains an illegal
  92. combination of left-to-right and right-to-left characters.
  93. * `idna.InvalidCodepoint` — raised when a label contains a codepoint
  94. that is INVALID for IDNA.
  95. * `idna.InvalidCodepointContext` — raised when a CONTEXTO or CONTEXTJ
  96. codepoint appears in a position whose contextual requirements are
  97. not satisfied.
  98. Exceptions carry machine-readable attributes so that applications
  99. do not need to parse the message: `code` is a short, stable identifier
  100. for the rule that failed (listed below); and, when the failure can be
  101. attributed to a particular character, `text` (the label, or domain for
  102. UTS #46 processing, being validated), `codepoint` (the offending
  103. codepoint as an integer) and `position` (its 1-based index within
  104. `text`, as quoted in the message) are set. Each is `None` when it does
  105. not apply. Message wording is not part of the API and may change.
  106. ```pycon
  107. >>> try:
  108. ... idna.encode('Königsgäßchen')
  109. ... except idna.IDNAError as err:
  110. ... print(err.code, err.codepoint, err.position, err.text)
  111. disallowed_codepoint 75 1 Königsgäßchen
  112. ```
  113. | `code` | Meaning |
  114. |---|---|
  115. | `input_too_long` | Input exceeds the library's defensive length limit and was not processed |
  116. | `label_too_long` | A label exceeds 63 octets |
  117. | `domain_too_long` | The domain exceeds 253 octets |
  118. | `empty_label` | A label is empty (e.g. consecutive dots) |
  119. | `empty_domain` | The domain is empty |
  120. | `not_nfc` | The label is not in Unicode Normalization Form C |
  121. | `hyphen_3_4` | The label has hyphens in the 3rd and 4th positions |
  122. | `hyphen_start_end` | The label starts or ends with a hyphen |
  123. | `leading_combiner` | The label starts with a combining mark |
  124. | `disallowed_codepoint` | A codepoint is DISALLOWED or UNASSIGNED under IDNA 2008 |
  125. | `contextj` | A CONTEXTJ codepoint (joiner) appears in an invalid context |
  126. | `contexto` | A CONTEXTO codepoint appears in an invalid context |
  127. | `unknown_codepoint` | A codepoint next to a joiner is unknown to this Python's Unicode database |
  128. | `bidi_rule_1` … `bidi_rule_6` | The corresponding rule of RFC 5893 (the Bidi Rule) is violated |
  129. | `bidi_unknown_direction` | A codepoint's directionality is unknown to this Python's Unicode database |
  130. | `invalid_alabel` | An `xn--` label is malformed or is not valid Punycode |
  131. | `non_canonical_alabel` | An `xn--` label is not the canonical Punycode encoding of its U-label (a "fake A-label") |
  132. | `invalid_ascii` | Byte input is not ASCII |
  133. | `invalid_utf8` | Byte input is not UTF-8 |
  134. | `uts46_disallowed` | A codepoint is disallowed by the UTS #46 mapping table |
  135. | `uts46_std3` | An ASCII character is rejected by the UTS #46 STD3 rules |
  136. | `unsupported_errors` | The codec was given an `errors` handler other than `strict` |
  137. ## Command-line tool
  138. The package supports command-line usage to convert domain names
  139. between their Unicode and ASCII-compatible forms. It can be run either
  140. as a module (`python3 -m idna`) or, once installed (such as with `uv
  141. tool` or `pipx`), via the `idna` script:
  142. ```bash
  143. $ uv tool install idna
  144. $ idna xn--e1afmkfd.xn--p1ai
  145. пример.рф
  146. $ idna пример.рф
  147. xn--e1afmkfd.xn--p1ai
  148. ```
  149. Mode can be specified with `-e`/`--encode` or `-d`/`--decode`, otherwise
  150. it will be chosen automatically based on the first input. Multiple
  151. domains can be supplied either as arguments or through standard input.
  152. UTS #46 mapping is applied by default, which lets the tool accept
  153. inputs that aren't strictly valid IDNA 2008 by normalising them first,
  154. pass `--strict` to disable UTS #46.
  155. Conversion failures are reported on stderr together with the
  156. offending input; processing continues with the remaining domains and
  157. the tool exits with a non-zero status if any conversion failed.
  158. ## Additional Notes
  159. * **Python version support**. This library supports Python 3.9 and higher.
  160. As this library serves as a low-level toolkit for a variety of
  161. applications, we strive to support all versions of Python that are
  162. not beyond end-of-life. Free-threaded Python is also supported,
  163. as the library holds no mutable global state the functions can be
  164. called concurrently from multiple threads.
  165. * **Unicode version**. The IDNA and UTS #46 lookup tables are generated
  166. from a specific Unicode release. Some Unicode data depends on the
  167. running Python's `unicodedata` module, so on an older Python a
  168. character new to Unicode may be rejected as unknown even if this
  169. library knows about it.
  170. * **Emoji**. It is an occasional request to support emoji domains in
  171. this library. Encoding of symbols like emoji is expressly prohibited by
  172. the IDNA technical standard, and emoji domains are broadly phased
  173. out across the domain industry due to associated security risks.
  174. * **Regenerating lookup tables**. The IDNA and UTS #46 functionality
  175. relies upon pre-calculated lookup tables, generated using the
  176. `idna-data` script in [`tools/`](tools/README.md).