How to use the idna.alabel function in idna

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 testIDNTLDALabels(self):

        for (ulabel, alabel) in self.tld_strings:
            self.assertEqual(alabel, idna.alabel(ulabel))
github sjm-steffann / dhcpkit / dhcpkit / utils.py View on Github external
def validate_domain_label(label: str):
    """
    Check if a given string is a valid domain label

    :param label: The domain label
    """
    # Just try to encode it to ASCII
    try:
        idna.alabel(label)
    except idna.IDNAError as e:
        if e.args and 'A-label' in e.args[0]:
            raise ValueError('Invalid label') from None
        else:
            raise ValueError(e.args[0]) from None
github rthalley / dnspython / dns / name.py View on Github external
def encode(self, label):
        if label == '':
            return b''
        if self.allow_pure_ascii and is_all_ascii(label):
            return label.encode('ascii')
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, self.transitional)
            return idna.alabel(label)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
github teamhephy / controller / rootfs / api / serializers.py View on Github external
            def ToACE(x): return idna.alabel(x).decode("utf-8", "strict")
            labels = list(map(ToACE, labels))