[Python-checkins] r79779 - in python/trunk: Lib/test/test_codecs.py Modules/_codecsmodule.c
philip.jenvey
python-checkins at python.org
Mon Apr 5 04:51:51 CEST 2010
Author: philip.jenvey
Date: Mon Apr 5 04:51:51 2010
New Revision: 79779
Log:
fix escape_encode to return the correct consumed size
Modified:
python/trunk/Lib/test/test_codecs.py
python/trunk/Modules/_codecsmodule.c
Modified: python/trunk/Lib/test/test_codecs.py
==============================================================================
--- python/trunk/Lib/test/test_codecs.py (original)
+++ python/trunk/Lib/test/test_codecs.py Mon Apr 5 04:51:51 2010
@@ -835,6 +835,9 @@
self.assertEquals(encoder(u"a")[1], 1)
self.assertEquals(encoder(u"\xe9\u0142")[1], 2)
+ 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.
Modified: python/trunk/Modules/_codecsmodule.c
==============================================================================
--- python/trunk/Modules/_codecsmodule.c (original)
+++ python/trunk/Modules/_codecsmodule.c Mon Apr 5 04:51:51 2010
@@ -179,12 +179,13 @@
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 @@
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
More information about the Python-checkins
mailing list