METADATA 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. Metadata-Version: 2.1
  2. Name: idna
  3. Version: 3.2
  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 :: Implementation :: CPython
  24. Classifier: Programming Language :: Python :: Implementation :: PyPy
  25. Classifier: Topic :: Internet :: Name Service (DNS)
  26. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  27. Classifier: Topic :: Utilities
  28. Requires-Python: >=3.5
  29. Internationalized Domain Names in Applications (IDNA)
  30. =====================================================
  31. Support for the Internationalised Domain Names in Applications
  32. (IDNA) protocol as specified in `RFC 5891 <https://tools.ietf.org/html/rfc5891>`_.
  33. This is the latest version of the protocol and is sometimes referred to as
  34. “IDNA 2008”.
  35. This library also provides support for Unicode Technical Standard 46,
  36. `Unicode IDNA Compatibility Processing <https://unicode.org/reports/tr46/>`_.
  37. This acts as a suitable replacement for the “encodings.idna” module that
  38. comes with the Python standard library, but which only supports the
  39. old, deprecated IDNA specification (`RFC 3490 <https://tools.ietf.org/html/rfc3490>`_).
  40. Basic functions are simply executed:
  41. .. code-block:: pycon
  42. >>> import idna
  43. >>> idna.encode('ドメイン.テスト')
  44. b'xn--eckwd4c7c.xn--zckzah'
  45. >>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
  46. ドメイン.テスト
  47. Packages
  48. --------
  49. The latest tagged release version is published in the PyPI repository:
  50. .. image:: https://badge.fury.io/py/idna.svg
  51. :target: https://badge.fury.io/py/idna
  52. Installation
  53. ------------
  54. To install this library, you can use pip:
  55. .. code-block:: bash
  56. $ pip install idna
  57. Alternatively, you can install the package using the bundled setup script:
  58. .. code-block:: bash
  59. $ python setup.py install
  60. This library works with Python 3.4 or later. Earlier versions of this
  61. library support Python 2 - use "idna<3" in your requirements file if
  62. you need this library for a Python 2 application.
  63. Usage
  64. -----
  65. For typical usage, the ``encode`` and ``decode`` functions will take a domain
  66. name argument and perform a conversion to A-labels or U-labels respectively.
  67. .. code-block:: pycon
  68. >>> import idna
  69. >>> idna.encode('ドメイン.テスト')
  70. b'xn--eckwd4c7c.xn--zckzah'
  71. >>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
  72. ドメイン.テスト
  73. You may use the codec encoding and decoding methods using the
  74. ``idna.codec`` module:
  75. .. code-block:: pycon
  76. >>> import idna.codec
  77. >>> print('домена.испытание'.encode('idna'))
  78. b'xn--80ahd1agd.xn--80akhbyknj4f'
  79. >>> print(b'xn--80ahd1agd.xn--80akhbyknj4f'.decode('idna'))
  80. домена.испытание
  81. Conversions can be applied at a per-label basis using the ``ulabel`` or ``alabel``
  82. functions if necessary:
  83. .. code-block:: pycon
  84. >>> idna.alabel('测试')
  85. b'xn--0zwm56d'
  86. Compatibility Mapping (UTS #46)
  87. +++++++++++++++++++++++++++++++
  88. As described in `RFC 5895 <https://tools.ietf.org/html/rfc5895>`_, the IDNA
  89. specification does not normalize input from different potential ways a user
  90. may input a domain name. This functionality, known as a “mapping”, is
  91. considered by the specification to be a local user-interface issue distinct
  92. from IDNA conversion functionality.
  93. This library provides one such mapping, that was developed by the Unicode
  94. Consortium. Known as `Unicode IDNA Compatibility Processing <https://unicode.org/reports/tr46/>`_,
  95. it provides for both a regular mapping for typical applications, as well as
  96. a transitional mapping to help migrate from older IDNA 2003 applications.
  97. For example, “Königsgäßchen” is not a permissible label as *LATIN CAPITAL
  98. LETTER K* is not allowed (nor are capital letters in general). UTS 46 will
  99. convert this into lower case prior to applying the IDNA conversion.
  100. .. code-block:: pycon
  101. >>> import idna
  102. >>> idna.encode('Königsgäßchen')
  103. ...
  104. idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
  105. >>> idna.encode('Königsgäßchen', uts46=True)
  106. b'xn--knigsgchen-b4a3dun'
  107. >>> print(idna.decode('xn--knigsgchen-b4a3dun'))
  108. königsgäßchen
  109. Transitional processing provides conversions to help transition from the older
  110. 2003 standard to the current standard. For example, in the original IDNA
  111. specification, the *LATIN SMALL LETTER SHARP S* (ß) was converted into two
  112. *LATIN SMALL LETTER S* (ss), whereas in the current IDNA specification this
  113. conversion is not performed.
  114. .. code-block:: pycon
  115. >>> idna.encode('Königsgäßchen', uts46=True, transitional=True)
  116. 'xn--knigsgsschen-lcb0w'
  117. Implementors should use transitional processing with caution, only in rare
  118. cases where conversion from legacy labels to current labels must be performed
  119. (i.e. IDNA implementations that pre-date 2008). For typical applications
  120. that just need to convert labels, transitional processing is unlikely to be
  121. beneficial and could produce unexpected incompatible results.
  122. ``encodings.idna`` Compatibility
  123. ++++++++++++++++++++++++++++++++
  124. Function calls from the Python built-in ``encodings.idna`` module are
  125. mapped to their IDNA 2008 equivalents using the ``idna.compat`` module.
  126. Simply substitute the ``import`` clause in your code to refer to the
  127. new module name.
  128. Exceptions
  129. ----------
  130. All errors raised during the conversion following the specification should
  131. raise an exception derived from the ``idna.IDNAError`` base class.
  132. More specific exceptions that may be generated as ``idna.IDNABidiError``
  133. when the error reflects an illegal combination of left-to-right and
  134. right-to-left characters in a label; ``idna.InvalidCodepoint`` when
  135. a specific codepoint is an illegal character in an IDN label (i.e.
  136. INVALID); and ``idna.InvalidCodepointContext`` when the codepoint is
  137. illegal based on its positional context (i.e. it is CONTEXTO or CONTEXTJ
  138. but the contextual requirements are not satisfied.)
  139. Building and Diagnostics
  140. ------------------------
  141. The IDNA and UTS 46 functionality relies upon pre-calculated lookup
  142. tables for performance. These tables are derived from computing against
  143. eligibility criteria in the respective standards. These tables are
  144. computed using the command-line script ``tools/idna-data``.
  145. This tool will fetch relevant codepoint data from the Unicode repository
  146. and perform the required calculations to identify eligibility. There are
  147. three main modes:
  148. * ``idna-data make-libdata``. Generates ``idnadata.py`` and ``uts46data.py``,
  149. the pre-calculated lookup tables using for IDNA and UTS 46 conversions. Implementors
  150. who wish to track this library against a different Unicode version may use this tool
  151. to manually generate a different version of the ``idnadata.py`` and ``uts46data.py``
  152. files.
  153. * ``idna-data make-table``. Generate a table of the IDNA disposition
  154. (e.g. PVALID, CONTEXTJ, CONTEXTO) in the format found in Appendix B.1 of RFC
  155. 5892 and the pre-computed tables published by `IANA <https://www.iana.org/>`_.
  156. * ``idna-data U+0061``. Prints debugging output on the various properties
  157. associated with an individual Unicode codepoint (in this case, U+0061), that are
  158. used to assess the IDNA and UTS 46 status of a codepoint. This is helpful in debugging
  159. or analysis.
  160. The tool accepts a number of arguments, described using ``idna-data -h``. Most notably,
  161. the ``--version`` argument allows the specification of the version of Unicode to use
  162. in computing the table data. For example, ``idna-data --version 9.0.0 make-libdata``
  163. will generate library data against Unicode 9.0.0.
  164. Testing
  165. -------
  166. The library has a test suite based on each rule of the IDNA specification, as
  167. well as tests that are provided as part of the Unicode Technical Standard 46,
  168. `Unicode IDNA Compatibility Processing <https://unicode.org/reports/tr46/>`_.