summaryrefslogtreecommitdiffstats
path: root/Modules/_struct.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-12-28 13:26:42 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-12-28 13:26:42 (GMT)
commitda9ec995f66bdb69dce7292abc4e1ca86e6a626a (patch)
tree0e32ecfe5b56b5dc0a4c1fc46eae094edf411905 /Modules/_struct.c
parente398da9ad0533d4bdca43aca8a7ff96cd02b7cfa (diff)
downloadcpython-da9ec995f66bdb69dce7292abc4e1ca86e6a626a.zip
cpython-da9ec995f66bdb69dce7292abc4e1ca86e6a626a.tar.gz
cpython-da9ec995f66bdb69dce7292abc4e1ca86e6a626a.tar.bz2
Issue #10783: struct.pack() doesn't encode implicitly unicode to UTF-8
* Replace "bytes" by "bytes object" in struct error messages * Document the API change in What's new in Python 3.2 * Fix test_wave * Remove also ugly implicit conversions in test_struct
Diffstat (limited to 'Modules/_struct.c')
-rw-r--r--Modules/_struct.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 2b4341c..b9dfe50 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -462,14 +462,9 @@ np_ubyte(char *p, PyObject *v, const formatdef *f)
static int
np_char(char *p, PyObject *v, const formatdef *f)
{
- if (PyUnicode_Check(v)) {
- v = _PyUnicode_AsDefaultEncodedString(v, NULL);
- if (v == NULL)
- return -1;
- }
if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) {
PyErr_SetString(StructError,
- "char format requires bytes or string of length 1");
+ "char format requires a bytes object of length 1");
return -1;
}
*p = *PyBytes_AsString(v);
@@ -1345,7 +1340,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
if (!PyBytes_Check(o_format)) {
Py_DECREF(o_format);
PyErr_Format(PyExc_TypeError,
- "Struct() argument 1 must be bytes, not %.200s",
+ "Struct() argument 1 must be a bytes object, not %.200s",
Py_TYPE(o_format)->tp_name);
return -1;
}
@@ -1423,7 +1418,7 @@ s_unpack(PyObject *self, PyObject *input)
return NULL;
if (vbuf.len != soself->s_size) {
PyErr_Format(StructError,
- "unpack requires a bytes argument of length %zd",
+ "unpack requires a bytes object of length %zd",
soself->s_size);
PyBuffer_Release(&vbuf);
return NULL;
@@ -1503,15 +1498,10 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
if (e->format == 's') {
int isstring;
void *p;
- if (PyUnicode_Check(v)) {
- v = _PyUnicode_AsDefaultEncodedString(v, NULL);
- if (v == NULL)
- return -1;
- }
isstring = PyBytes_Check(v);
if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError,
- "argument for 's' must be a bytes or string");
+ "argument for 's' must be a bytes object");
return -1;
}
if (isstring) {
@@ -1529,15 +1519,10 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
} else if (e->format == 'p') {
int isstring;
void *p;
- if (PyUnicode_Check(v)) {
- v = _PyUnicode_AsDefaultEncodedString(v, NULL);
- if (v == NULL)
- return -1;
- }
isstring = PyBytes_Check(v);
if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError,
- "argument for 'p' must be a bytes or string");
+ "argument for 'p' must be a bytes object");
return -1;
}
if (isstring) {
@@ -1691,7 +1676,7 @@ static struct PyMethodDef s_methods[] = {
{NULL, NULL} /* sentinel */
};
-PyDoc_STRVAR(s__doc__,
+PyDoc_STRVAR(s__doc__,
"Struct(fmt) --> compiled struct object\n"
"\n"
"Return a new Struct object which writes and reads binary data according to\n"