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

Remove last references to the "char buffer" of the buffer protocol from
Python3.
This commit is contained in:
Victor Stinner 2010-06-08 22:54:19 +00:00
parent 1fbd36b51d
commit 3dcb5acdb0
6 changed files with 11 additions and 77 deletions

View 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,

View 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

View 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,

View File

@ -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.

View 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},

View 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);