]> granicus.if.org Git - python/commitdiff
Issue #8838, #8339: Remove codecs.charbuffer_encode() and "t#" parsing format
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 8 Jun 2010 22:54:19 +0000 (22:54 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 8 Jun 2010 22:54:19 +0000 (22:54 +0000)
Remove last references to the "char buffer" of the buffer protocol from
Python3.

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

index c8d9851f35e0597bc2fbfc9601d96e5d7b489b75..c5ec768aa406be94c000f3b3858d67eaaa6b3f98 100644 (file)
@@ -150,13 +150,6 @@ Unless otherwise stated, buffers are not NUL-terminated.
    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,
index 265f9282e5713dea9c3f43353cea449236dd6115..14f9215e8b999bbeb1639bd420bf47a0e9b55f10 100644 (file)
@@ -173,4 +173,7 @@ that may require changes to your code:
 
 * 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
index 598aaa2d90de45ea0de9d22ebf3c16debc8b2e6a..7de1ed5f6bb2fc49efd3df13c73c8b955e1adaaa 100644 (file)
@@ -72,7 +72,6 @@ class ReadTest(unittest.TestCase, MixInCheckStateHandling):
         # 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 @@ class ReadBufferTest(unittest.TestCase):
         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 @@ def test_main():
         UTF7Test,
         UTF16ExTest,
         ReadBufferTest,
-        CharBufferTest,
         RecodingTest,
         PunycodeTest,
         UnicodeInternalTest,
index b21545033f6086c9d786974ee07dbe26f8fad84e..e7e858f8d96741c99b83200009b139d4adfe737d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,13 @@ What's New in Python 3.2 Alpha 1?
 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.
 
index d0d870cbe21517046b03c629bd58356682f2118e..cabe600ee8ec55aef39bc0bd8765a8ede1917e89 100644 (file)
@@ -638,21 +638,6 @@ readbuffer_encode(PyObject *self,
     return codec_tuple(result, size);
 }
 
-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 @@ static PyMethodDef _codecs_functions[] = {
     {"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},
index 31b9d35716b46a22493b7c23a221fde87427b2ca..2a26a8f9f359cfc00e70507b9d500efa4b7b5231 100644 (file)
@@ -864,7 +864,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
         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 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
         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);