"UnicodeInternalTest")
self.assertEquals(("ab", 12), ignored)
+ def test_encode_length(self):
+ # Issue 3739
+ encoder = codecs.getencoder("unicode_internal")
+ self.assertEquals(encoder("a")[1], 1)
+ self.assertEquals(encoder("\xe9\u0142")[1], 2)
+
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
nameprep_tests = [
# 3.1 Map to nothing.
name = "latin_1"
self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
(b, size) = codecs.getencoder(encoding)(s)
- if encoding != "unicode_internal":
- self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding))
+ self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding))
(chars, size) = codecs.getdecoder(encoding)(b)
self.assertEqual(chars, s, "%r != %r (encoding=%r)" % (chars, s, encoding))
- Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)'
to avoid compiler warnings.
+- Issue #3739: The unicode-internal encoder now reports the number of characters
+ consumed like any other encoder (instead of the number of bytes).
+
Installation
------------
if (PyUnicode_Check(obj)) {
data = PyUnicode_AS_DATA(obj);
size = PyUnicode_GET_DATA_SIZE(obj);
- return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
+ return codec_tuple(PyBytes_FromStringAndSize(data, size),
+ PyUnicode_GET_SIZE(obj));
}
else {
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))