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