Commit c8241fdd authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #26198: Added tests for "es", "et", "es#", "et#" and "C" format units

of PyArg_Parse*() functions.
parent 22532ac2
This diff is collapsed.
......@@ -1088,7 +1088,16 @@ getargs_c(PyObject *self, PyObject *args)
char c;
if (!PyArg_ParseTuple(args, "c", &c))
return NULL;
return PyBytes_FromStringAndSize(&c, 1);
return PyLong_FromLong((unsigned char)c);
}
static PyObject *
getargs_C(PyObject *self, PyObject *args)
{
int c;
if (!PyArg_ParseTuple(args, "C", &c))
return NULL;
return PyLong_FromLong(c);
}
static PyObject *
......@@ -1243,6 +1252,84 @@ getargs_Z_hash(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *
getargs_es(PyObject *self, PyObject *args)
{
PyObject *arg, *result;
const char *encoding = NULL;
char *str;
if (!PyArg_ParseTuple(args, "O|s", &arg, &encoding))
return NULL;
if (!PyArg_Parse(arg, "es", encoding, &str))
return NULL;
result = PyBytes_FromString(str);
PyMem_Free(str);
return result;
}
static PyObject *
getargs_et(PyObject *self, PyObject *args)
{
PyObject *arg, *result;
const char *encoding = NULL;
char *str;
if (!PyArg_ParseTuple(args, "O|s", &arg, &encoding))
return NULL;
if (!PyArg_Parse(arg, "et", encoding, &str))
return NULL;
result = PyBytes_FromString(str);
PyMem_Free(str);
return result;
}
static PyObject *
getargs_es_hash(PyObject *self, PyObject *args)
{
PyObject *arg, *result;
const char *encoding = NULL;
PyByteArrayObject *buffer = NULL;
char *str = NULL;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|sY", &arg, &encoding, &buffer))
return NULL;
if (buffer != NULL) {
str = PyByteArray_AS_STRING(buffer);
size = PyByteArray_GET_SIZE(buffer);
}
if (!PyArg_Parse(arg, "es#", encoding, &str, &size))
return NULL;
result = PyBytes_FromStringAndSize(str, size);
if (buffer == NULL)
PyMem_Free(str);
return result;
}
static PyObject *
getargs_et_hash(PyObject *self, PyObject *args)
{
PyObject *arg, *result;
const char *encoding = NULL;
PyByteArrayObject *buffer = NULL;
char *str = NULL;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|sY", &arg, &encoding, &buffer))
return NULL;
if (buffer != NULL) {
str = PyByteArray_AS_STRING(buffer);
size = PyByteArray_GET_SIZE(buffer);
}
if (!PyArg_Parse(arg, "et#", encoding, &str, &size))
return NULL;
result = PyBytes_FromStringAndSize(str, size);
if (buffer == NULL)
PyMem_Free(str);
return result;
}
/* Test the s and z codes for PyArg_ParseTuple.
*/
static PyObject *
......@@ -3588,6 +3675,7 @@ static PyMethodDef TestMethods[] = {
{"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
#endif
{"getargs_c", getargs_c, METH_VARARGS},
{"getargs_C", getargs_C, METH_VARARGS},
{"getargs_s", getargs_s, METH_VARARGS},
{"getargs_s_star", getargs_s_star, METH_VARARGS},
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
......@@ -3602,6 +3690,10 @@ static PyMethodDef TestMethods[] = {
{"getargs_Z", getargs_Z, METH_VARARGS},
{"getargs_Z_hash", getargs_Z_hash, METH_VARARGS},
{"getargs_w_star", getargs_w_star, METH_VARARGS},
{"getargs_es", getargs_es, METH_VARARGS},
{"getargs_et", getargs_et, METH_VARARGS},
{"getargs_es_hash", getargs_es_hash, METH_VARARGS},
{"getargs_et_hash", getargs_et_hash, METH_VARARGS},
{"codec_incrementalencoder",
(PyCFunction)codec_incrementalencoder, METH_VARARGS},
{"codec_incrementaldecoder",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment