Example #1
0
 def decode(self, label):
     if label == b'':
         return u''
     if not have_idna_2008:
         raise NoIDNA2008
     try:
         if self.uts_46:
             label = idna.uts46_remap(label, False, False)
         return _escapify(idna.ulabel(label), True)
     except idna.IDNAError as e:
         raise IDNAException(idna_exception=e)
Example #2
0
 def encode(self, label):
     if label == '':
         return b''
     if self.allow_pure_ascii and self.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)
Example #3
0
 def encode(self, label):
     if label == '':
         return b''
     if self.allow_pure_ascii and self.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)
Example #4
0
 def decode(self, label):
     if not self.strict_decode:
         return super(IDNA2008Codec, self).decode(label)
     if label == b'':
         return u''
     if not have_idna_2008:
         raise NoIDNA2008
     try:
         if self.uts_46:
             label = idna.uts46_remap(label, False, False)
         return _escapify(idna.ulabel(label), True)
     except idna.IDNAError as e:
         raise IDNAException(idna_exception=e)
Example #5
0
 def decode(self, label):
     if not self.strict_decode:
         return super().decode(label)
     if label == b'':
         return ''
     if not have_idna_2008:
         raise NoIDNA2008
     try:
         ulabel = idna.ulabel(label)
         if self.uts_46:
             ulabel = idna.uts46_remap(ulabel, False, self.transitional)
         return _escapify(ulabel)
     except (idna.IDNAError, UnicodeError) as e:
         raise IDNAException(idna_exception=e)
Example #6
0
def _idna_encode(label, idna_2008, uts_46, std3_rules, transitional):
    if label == '':
        return b''
    if idna_2008:
        if not have_idna_2008:
            raise NoIDNA2008
        if uts_46:
            label = idna.uts46_remap(label, std3_rules, transitional)
        label = idna.alabel(label)
    else:
        try:
            label = encodings.idna.ToASCII(label)
        except UnicodeError:
            raise LabelTooLong
    return label
Example #7
0
 def encode(self, label):
     if label == '':
         return b''
     if self.allow_pure_ascii and is_all_ascii(label):
         encoded = label.encode('ascii')
         if len(encoded) > 63:
             raise LabelTooLong
         return encoded
     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:
         if e.args[0] == 'Label too long':
             raise LabelTooLong
         else:
             raise IDNAException(idna_exception=e)