METADATA 9.5 KB

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