How to use idna - 10 common examples

To help you get started, we’ve selected a few idna examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kjd / idna / tests / test_idna.py View on Github external
def test_check_initial_combiner(self):

        m = u'\u0300'
        a = u'\u0061'

        self.assertTrue(idna.check_initial_combiner(a))
        self.assertTrue(idna.check_initial_combiner(a + m))
        self.assertRaises(idna.IDNAError, idna.check_initial_combiner, m + a)
github Nuitka / Nuitka / tests / standalone / IdnaUsing.py View on Github external
#     You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
from __future__ import print_function

import idna.core
import sys

print(idna.core, "idna.idnadata" in sys.modules)
github kjd / idna / tests / test_idna.py View on Github external
def test_encode(self):

        self.assertEqual(idna.encode('xn--zckzah.xn--zckzah'), b'xn--zckzah.xn--zckzah')
        self.assertEqual(idna.encode(u'\u30c6\u30b9\u30c8.xn--zckzah'), b'xn--zckzah.xn--zckzah')
        self.assertEqual(idna.encode(u'\u30c6\u30b9\u30c8.\u30c6\u30b9\u30c8'), b'xn--zckzah.xn--zckzah')
        self.assertEqual(idna.encode('abc.abc'), b'abc.abc')
        self.assertEqual(idna.encode('xn--zckzah.abc'), b'xn--zckzah.abc')
        self.assertEqual(idna.encode(u'\u30c6\u30b9\u30c8.abc'), b'xn--zckzah.abc')
        self.assertEqual(idna.encode(u'\u0521\u0525\u0523-\u0523\u0523-----\u0521\u0523\u0523\u0523.aa'),
                         b'xn---------90gglbagaar.aa')
        self.assertRaises(idna.IDNAError, idna.encode,
                          u'\u0521\u0524\u0523-\u0523\u0523-----\u0521\u0523\u0523\u0523.aa', uts46=False)
        self.assertEqual(idna.encode('a'*63), b'a'*63)
        self.assertRaises(idna.IDNAError, idna.encode, 'a'*64)
        self.assertRaises(idna.core.InvalidCodepoint, idna.encode, '*')
github kjd / idna / tests / test_intranges.py View on Github external
def _test_containment(self, ints, disjoint_ints):
        ranges = intranges_from_list(ints)
        for int_ in ints:
            assert intranges_contain(int_, ranges)
        for int_ in disjoint_ints:
            assert not intranges_contain(int_, ranges)
github kjd / idna / tests / test_intranges.py View on Github external
def _test_containment(self, ints, disjoint_ints):
        ranges = intranges_from_list(ints)
        for int_ in ints:
            assert intranges_contain(int_, ranges)
        for int_ in disjoint_ints:
            assert not intranges_contain(int_, ranges)
github kjd / idna / tests / test_idna.py View on Github external
def testIDNTLDALabels(self):

        for (ulabel, alabel) in self.tld_strings:
            self.assertEqual(alabel, idna.alabel(ulabel))
github kjd / idna / tests / test_intranges.py View on Github external
def test_skips(self):
        self.assertEqual(
            intranges_from_list([0, 2, 4, 6, 9, 10, 11, 13, 15,]),
            (
                _encode_range(0, 1),
                _encode_range(2, 3),
                _encode_range(4, 5),
                _encode_range(6, 7),
                _encode_range(9, 12),
                _encode_range(13, 14),
                _encode_range(15, 16),
            )
github kjd / idna / tests / test_intranges.py View on Github external
def test_skips(self):
        self.assertEqual(
            intranges_from_list([0, 2, 4, 6, 9, 10, 11, 13, 15,]),
            (
                _encode_range(0, 1),
                _encode_range(2, 3),
                _encode_range(4, 5),
                _encode_range(6, 7),
                _encode_range(9, 12),
                _encode_range(13, 14),
                _encode_range(15, 16),
            )
github kjd / idna / tests / test_intranges.py View on Github external
def test_skips(self):
        self.assertEqual(
            intranges_from_list([0, 2, 4, 6, 9, 10, 11, 13, 15,]),
            (
                _encode_range(0, 1),
                _encode_range(2, 3),
                _encode_range(4, 5),
                _encode_range(6, 7),
                _encode_range(9, 12),
                _encode_range(13, 14),
                _encode_range(15, 16),
            )
github kjd / idna / tests / test_intranges.py View on Github external
def test_skips(self):
        self.assertEqual(
            intranges_from_list([0, 2, 4, 6, 9, 10, 11, 13, 15,]),
            (
                _encode_range(0, 1),
                _encode_range(2, 3),
                _encode_range(4, 5),
                _encode_range(6, 7),
                _encode_range(9, 12),
                _encode_range(13, 14),
                _encode_range(15, 16),
            )