[Python-checkins] r81854 - in python/branches/py3k: Doc/c-api/arg.rst Doc/whatsnew/3.2.rst Lib/test/test_codecs.py Misc/NEWS Modules/_codecsmodule.c Python/getargs.c

victor.stinner python-checkins at python.org
Wed Jun 9 00:54:20 CEST 2010


Author: victor.stinner
Date: Wed Jun  9 00:54:19 2010
New Revision: 81854

Log:
Issue #8838, #8339: Remove codecs.charbuffer_encode() and "t#" parsing format

Remove last references to the "char buffer" of the buffer protocol from
Python3.


Modified:
   python/branches/py3k/Doc/c-api/arg.rst
   python/branches/py3k/Doc/whatsnew/3.2.rst
   python/branches/py3k/Lib/test/test_codecs.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_codecsmodule.c
   python/branches/py3k/Python/getargs.c

Modified: python/branches/py3k/Doc/c-api/arg.rst
==============================================================================
--- python/branches/py3k/Doc/c-api/arg.rst	(original)
+++ python/branches/py3k/Doc/c-api/arg.rst	Wed Jun  9 00:54:19 2010
@@ -150,13 +150,6 @@
    any conversion.  Raises :exc:`TypeError` if the object is not a Unicode
    object.  The C variable may also be declared as :ctype:`PyObject\*`.
 
-``t#`` (:class:`bytes`, :class:`bytearray` or read-only character buffer) [char \*, int]
-   Like ``s#``, but accepts any object which implements the read-only buffer
-   interface.  The :ctype:`char\*` variable is set to point to the first byte of
-   the buffer, and the :ctype:`int` is set to the length of the buffer.  Only
-   single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
-   others.
-
 ``w`` (:class:`bytearray` or read-write character buffer) [char \*]
    Similar to ``s``, but accepts any object which implements the read-write buffer
    interface.  The caller must determine the length of the buffer by other means,

Modified: python/branches/py3k/Doc/whatsnew/3.2.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/3.2.rst	(original)
+++ python/branches/py3k/Doc/whatsnew/3.2.rst	Wed Jun  9 00:54:19 2010
@@ -173,4 +173,7 @@
 
 * bytearray objects cannot be used anymore as filenames: convert them to bytes
 
+* "t#" format of PyArg_Parse*() functions has been removed: use "s#" or "s*"
+  instead
+
 * Stub

Modified: python/branches/py3k/Lib/test/test_codecs.py
==============================================================================
--- python/branches/py3k/Lib/test/test_codecs.py	(original)
+++ python/branches/py3k/Lib/test/test_codecs.py	Wed Jun  9 00:54:19 2010
@@ -72,7 +72,6 @@
         # check that there's nothing left in the buffers
         self.assertEqual(r.read(), "")
         self.assertEqual(r.bytebuffer, b"")
-        self.assertEqual(r.charbuffer, "")
 
         # do the check again, this time using a incremental decoder
         d = codecs.getincrementaldecoder(self.encoding)()
@@ -628,18 +627,6 @@
         self.assertRaises(TypeError, codecs.readbuffer_encode)
         self.assertRaises(TypeError, codecs.readbuffer_encode, 42)
 
-class CharBufferTest(unittest.TestCase):
-
-    def test_string(self):
-        self.assertEqual(codecs.charbuffer_encode(b"spam"), (b"spam", 4))
-
-    def test_empty(self):
-        self.assertEqual(codecs.charbuffer_encode(b""), (b"", 0))
-
-    def test_bad_args(self):
-        self.assertRaises(TypeError, codecs.charbuffer_encode)
-        self.assertRaises(TypeError, codecs.charbuffer_encode, 42)
-
 class UTF8SigTest(ReadTest):
     encoding = "utf-8-sig"
 
@@ -1663,7 +1650,6 @@
         UTF7Test,
         UTF16ExTest,
         ReadBufferTest,
-        CharBufferTest,
         RecodingTest,
         PunycodeTest,
         UnicodeInternalTest,

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed Jun  9 00:54:19 2010
@@ -12,6 +12,13 @@
 Core and Builtins
 -----------------
 
+- Issue #8838: Remove codecs.charbuffer_encode() function. The buffer protocol
+  doesn't support "char buffer" anymore in Python3.
+
+- Issue #8339: Remove "t#" format of PyArg_Parse*() functions, use "s#" or "s*"
+  instead. codecs.charbuffer_encode() now accepts modifiable buffer objects
+  like bytearray.
+
 - Issue #8837: Remove "O?" format of PyArg_Parse*() functions. The format is no
   used anymore and it was never documented.
 

Modified: python/branches/py3k/Modules/_codecsmodule.c
==============================================================================
--- python/branches/py3k/Modules/_codecsmodule.c	(original)
+++ python/branches/py3k/Modules/_codecsmodule.c	Wed Jun  9 00:54:19 2010
@@ -639,21 +639,6 @@
 }
 
 static PyObject *
-charbuffer_encode(PyObject *self,
-                  PyObject *args)
-{
-    const char *data;
-    Py_ssize_t size;
-    const char *errors = NULL;
-
-    if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
-                          &data, &size, &errors))
-        return NULL;
-
-    return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
-}
-
-static PyObject *
 unicode_internal_encode(PyObject *self,
                         PyObject *args)
 {
@@ -1116,7 +1101,6 @@
     {"charmap_decode",          charmap_decode,                 METH_VARARGS},
     {"charmap_build",           charmap_build,                  METH_VARARGS},
     {"readbuffer_encode",       readbuffer_encode,              METH_VARARGS},
-    {"charbuffer_encode",       charbuffer_encode,              METH_VARARGS},
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
     {"mbcs_encode",             mbcs_encode,                    METH_VARARGS},
     {"mbcs_decode",             mbcs_decode,                    METH_VARARGS},

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Wed Jun  9 00:54:19 2010
@@ -864,7 +864,7 @@
         break;
     }
 
-    /* XXX WAAAAH!  's', 'y', 'z', 'u', 'Z', 'e', 'w', 't' codes all
+    /* XXX WAAAAH!  's', 'y', 'z', 'u', 'Z', 'e', 'w' codes all
        need to be cleaned up! */
 
     case 's': {/* text string */
@@ -1362,45 +1362,6 @@
         break;
     }
 
-      /*TEO: This can be eliminated --- here only for backward
-        compatibility */
-    case 't': { /* 8-bit character buffer, read-only access */
-        char **p = va_arg(*p_va, char **);
-        PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
-        Py_ssize_t count;
-        Py_buffer view;
-
-        if (*format++ != '#')
-            return converterr(
-                "invalid use of 't' format character",
-                arg, msgbuf, bufsize);
-        if (pb == NULL || pb->bf_getbuffer == NULL)
-            return converterr(
-                "bytes or read-only character buffer",
-                arg, msgbuf, bufsize);
-
-        if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0)
-            return converterr("string or single-segment read-only buffer",
-                              arg, msgbuf, bufsize);
-
-        count = view.len;
-        *p = view.buf;
-        if (pb->bf_releasebuffer)
-            return converterr(
-                "string or pinned buffer",
-                arg, msgbuf, bufsize);
-
-        PyBuffer_Release(&view);
-
-        if (count < 0)
-            return converterr("(unspecified)", arg, msgbuf, bufsize);
-        {
-            FETCH_SIZE;
-            STORE_SIZE(count);
-        }
-        break;
-    }
-
     default:
         return converterr("impossible<bad format char>", arg, msgbuf, bufsize);
 


More information about the Python-checkins mailing list