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,
* 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
# 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)()
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"
UTF7Test,
UTF16ExTest,
ReadBufferTest,
- CharBufferTest,
RecodingTest,
PunycodeTest,
UnicodeInternalTest,
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.
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)
{"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},
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 */
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);