Skip to content
Snippets Groups Projects
Commit 8cd15986 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Support keyword & optional args

parent 9ecabdb4
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import zlib_into
a = b'abcde' * 5000
b = bytearray(5000)
res = zlib_into.compress_into(a, b, 1, 15)
res = zlib_into.compress_into(a, b, level=9)
print("res", res)
print(b[:res])
......
......@@ -59,14 +59,16 @@ zlib_error(z_stream zst, int err, const char *msg)
}
static PyObject *
compress_into(PyObject *module, PyObject *args) {
compress_into(PyObject *module, PyObject *args, PyObject *kwargs) {
static char *keywords[] = {"data", "output", "level", "wbits", NULL};
PyObject *return_value = NULL;
Py_buffer input, output;
Py_ssize_t bytes_written;
int level, wbits;
Py_buffer input, output;
int level=Z_DEFAULT_COMPRESSION, wbits=MAX_WBITS;
z_stream zst;
if (!PyArg_ParseTuple(args, "y*w*ii", &input, &output, &level, &wbits)) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*w*|ii", keywords,
&input, &output, &level, &wbits)) {
return NULL;
}
......@@ -131,7 +133,7 @@ compress_into(PyObject *module, PyObject *args) {
}
static PyMethodDef ZlibIntoMethods[] = {
{"compress_into", compress_into, METH_VARARGS, "zlib compress data into a buffer"},
{"compress_into", (PyCFunction)compress_into, METH_VARARGS | METH_KEYWORDS, "zlib compress data into a buffer"},
{NULL, NULL, 0, NULL}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment