]> granicus.if.org Git - python/commitdiff
Merged revisions 79779 via svnmerge from
authorPhilip Jenvey <pjenvey@underboss.org>
Wed, 9 Jun 2010 17:55:28 +0000 (17:55 +0000)
committerPhilip Jenvey <pjenvey@underboss.org>
Wed, 9 Jun 2010 17:55:28 +0000 (17:55 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79779 | philip.jenvey | 2010-04-04 19:51:51 -0700 (Sun, 04 Apr 2010) | 2 lines

  fix escape_encode to return the correct consumed size
........

Lib/test/test_codecs.py
Misc/NEWS
Modules/_codecsmodule.c

index 52e8dc9492d05bedbdad0c5be70788514eb123c3..a46edae8fd026697d66294d213de0488bb3d20ad 100644 (file)
@@ -829,6 +829,9 @@ class UnicodeInternalTest(unittest.TestCase):
                 "UnicodeInternalTest")
             self.assertEquals((u"ab", 12), ignored)
 
+        encoder = codecs.getencoder("string-escape")
+        self.assertEquals(encoder(r'\x00')[1], 4)
+
 # From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
 nameprep_tests = [
     # 3.1 Map to nothing.
index f1cf94922391a997ebd42fdfb5878702b1ff37b5..88a148ae786145acd30909df816d0dcb4027729f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,8 @@ C-API
 Library
 -------
 
+- Fix codecs.escape_encode to return the correct consumed size.
+
 - Issue #6470: Drop UNC prefix in FixTk.
 
 - Issue #8833: tarfile created hard link entries with a size field != 0 by
index 5b501441b11286e34a522e362970af85d252322d..3b07b6d72f19067cd3a46a5d4891f2e83adb6fe4 100644 (file)
@@ -179,12 +179,13 @@ escape_encode(PyObject *self,
     PyObject *str;
     const char *errors = NULL;
     char *buf;
-    Py_ssize_t len;
+    Py_ssize_t consumed, len;
 
-    if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
-                          &PyString_Type, &str, &errors))
+    if (!PyArg_ParseTuple(args, "S|z:escape_encode",
+                          &str, &errors))
         return NULL;
 
+    consumed = PyString_GET_SIZE(str);
     str = PyString_Repr(str, 0);
     if (!str)
         return NULL;
@@ -196,7 +197,7 @@ escape_encode(PyObject *self,
     if (_PyString_Resize(&str, len-2) < 0)
         return NULL;
 
-    return codec_tuple(str, PyString_Size(str));
+    return codec_tuple(str, consumed);
 }
 
 #ifdef Py_USING_UNICODE