summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-06-08 22:54:19 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-06-08 22:54:19 (GMT)
commit3dcb5acdb0151d1686762329ec07ae2ac4d1caae (patch)
tree1b9d0230afafafa0cff920c7f55c9ca98e433719
parent1fbd36b51d1bf65bc110e51840bede646b58f2d5 (diff)
downloadcpython-3dcb5acdb0151d1686762329ec07ae2ac4d1caae.zip
cpython-3dcb5acdb0151d1686762329ec07ae2ac4d1caae.tar.gz
cpython-3dcb5acdb0151d1686762329ec07ae2ac4d1caae.tar.bz2
Issue #8838, #8339: Remove codecs.charbuffer_encode() and "t#" parsing format
Remove last references to the "char buffer" of the buffer protocol from Python3.
-rw-r--r--Doc/c-api/arg.rst7
-rw-r--r--Doc/whatsnew/3.2.rst3
-rw-r--r--Lib/test/test_codecs.py14
-rw-r--r--Misc/NEWS7
-rw-r--r--Modules/_codecsmodule.c16
-rw-r--r--Python/getargs.c41
6 files changed, 11 insertions, 77 deletions
diff --git a/Doc/c-api/arg.rst b/Doc/c-api/arg.rst
index c8d9851..c5ec768 100644
--- a/Doc/c-api/arg.rst
+++ b/Doc/c-api/arg.rst
@@ -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,
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index 265f928..14f9215 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -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
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 598aaa2..7de1ed5 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -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,
diff --git a/Misc/NEWS b/Misc/NEWS
index b215450..e7e858f 100644
--- 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.
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index d0d870c..cabe600 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -639,21 +639,6 @@ readbuffer_encode(PyObject *self,
}
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},
diff --git a/Python/getargs.c b/Python/getargs.c
index 31b9d35..2a26a8f 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -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);