diff -r 2f563908ebc5 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Thu Apr 26 17:05:31 2012 +0200 +++ b/Modules/zlibmodule.c Fri Apr 27 13:33:57 2012 -0700 @@ -916,6 +916,67 @@ return retval; } +PyDoc_STRVAR(decomp_set_dictionary__doc__, +"set_dictionary(dict) -- Initialize the compression dictionary.\n"); + +static PyObject * +PyZlib_decomp_set_dictionary(compobject *self, PyObject *args) +{ + int err, dlen; + Byte *dict; + PyObject * retval = NULL; + + if (!PyArg_ParseTuple(args, "s#|i:set_dictionary", &dict, &dlen)) { + return NULL; + } + + ENTER_ZLIB(self); + + Py_BEGIN_ALLOW_THREADS + err = deflateSetDictionary (&(self->zst), dict, dlen); + Py_END_ALLOW_THREADS + + if (err == Z_OK) { + Py_INCREF (Py_None); + retval = Py_None; + } else { + zlib_error (self->zst, err, "from deflateSetDictionary()"); + } + + LEAVE_ZLIB(self); + + return retval; +} + +static PyObject * +PyZlib_comp_set_dictionary(compobject *self, PyObject *args) +{ + int err, dlen; + Byte *dict; + PyObject * retval = NULL; + + if (!PyArg_ParseTuple(args, "s#|i:set_dictionary", &dict, &dlen)) { + return NULL; + } + + ENTER_ZLIB(self); + + Py_BEGIN_ALLOW_THREADS + err = inflateSetDictionary (&(self->zst), dict, dlen); + Py_END_ALLOW_THREADS + + if (err == Z_OK) { + Py_INCREF (Py_None); + retval = Py_None; + } else { + zlib_error (self->zst, err, "from inflateSetDictionary()"); + } + + LEAVE_ZLIB(self); + + return retval; +} + static PyMethodDef comp_methods[] = { {"compress", (binaryfunc)PyZlib_objcompress, METH_VARARGS, @@ -926,6 +987,8 @@ {"copy", (PyCFunction)PyZlib_copy, METH_NOARGS, comp_copy__doc__}, #endif + {"set_dictionary", (PyCFunction)PyZlib_decomp_set_dictionary, METH_VARARGS, + decomp_set_dictionary__doc__}, {NULL, NULL} }; @@ -939,6 +1002,8 @@ {"copy", (PyCFunction)PyZlib_uncopy, METH_NOARGS, decomp_copy__doc__}, #endif + {"set_dictionary", (PyCFunction)PyZlib_comp_set_dictionary, METH_VARARGS, + decomp_set_dictionary__doc__}, {NULL, NULL} };