diff -r 82451c88b3c0 Lib/encodings/idna.py --- a/Lib/encodings/idna.py Thu Apr 11 19:18:22 2013 -0500 +++ b/Lib/encodings/idna.py Sat Apr 13 13:14:34 2013 -0400 @@ -162,9 +162,9 @@ labels = result.split(b'.') for label in labels[:-1]: if not (0 < len(label) < 64): - raise UnicodeError("label empty or too long") + raise UnicodeError("label empty or too long in %s" % result.decode()) if len(labels[-1]) >= 64: - raise UnicodeError("label too long") + raise UnicodeError("label too long %s" % labels[-1].decode()) return result, len(input) result = bytearray() diff -r 82451c88b3c0 Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py Thu Apr 11 19:18:22 2013 -0500 +++ b/Lib/test/test_unicode.py Sat Apr 13 13:14:34 2013 -0400 @@ -1673,6 +1673,21 @@ # Test whether trailing dot is preserved self.assertEqual("www.python.org.".encode("idna"), b"www.python.org.") + def test_codecs_errors_messages(self): + # Test Empty + self.assertRaisesRegexp(UnicodeError, 'label empty or too long in 1..com', "1..com".encode, 'idna') + # Test label greater then 64 + label = "A" * 64 + value = "first." + label + ".last" + self.assertRaisesRegexp(UnicodeError, 'label empty or too long in first.%s.last' % label, value.encode, 'idna') + # Test last label length 64 + value = "first.second." + label + self.assertRaisesRegexp(UnicodeError, "label too long " + label, value.encode, 'idna') + # Test last label length greater then 64 + label += "A" + value += "A" + self.assertRaisesRegexp(UnicodeError, "label too long " + label, value.encode, 'idna') + def test_codecs_errors(self): # Error handling (encoding) self.assertRaises(UnicodeError, 'Andr\202 x'.encode, 'ascii')