Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(zlib_compress__doc__, |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 6 | "compress($module, /, data, level=Z_DEFAULT_COMPRESSION)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 9 | "Returns a bytes object containing compressed data.\n" |
| 10 | "\n" |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 11 | " data\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 12 | " Binary data to be compressed.\n" |
| 13 | " level\n" |
Martin Panter | b0cb42d | 2016-02-10 10:45:54 +0000 | [diff] [blame] | 14 | " Compression level, in 0-9 or -1."); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 15 | |
| 16 | #define ZLIB_COMPRESS_METHODDEF \ |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 17 | {"compress", (PyCFunction)zlib_compress, METH_VARARGS|METH_KEYWORDS, zlib_compress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 20 | zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 21 | |
| 22 | static PyObject * |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 23 | zlib_compress(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 24 | { |
| 25 | PyObject *return_value = NULL; |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 26 | static char *_keywords[] = {"data", "level", NULL}; |
| 27 | Py_buffer data = {NULL, NULL}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 28 | int level = Z_DEFAULT_COMPRESSION; |
| 29 | |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 30 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i:compress", _keywords, |
| 31 | &data, &level)) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 32 | goto exit; |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 33 | return_value = zlib_compress_impl(module, &data, level); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 34 | |
| 35 | exit: |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 36 | /* Cleanup for data */ |
| 37 | if (data.obj) |
| 38 | PyBuffer_Release(&data); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 39 | |
| 40 | return return_value; |
| 41 | } |
| 42 | |
| 43 | PyDoc_STRVAR(zlib_decompress__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 44 | "decompress($module, data, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE, /)\n" |
| 45 | "--\n" |
| 46 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 47 | "Returns a bytes object containing the uncompressed data.\n" |
| 48 | "\n" |
| 49 | " data\n" |
| 50 | " Compressed data.\n" |
| 51 | " wbits\n" |
| 52 | " The window buffer size.\n" |
| 53 | " bufsize\n" |
| 54 | " The initial output buffer size."); |
| 55 | |
| 56 | #define ZLIB_DECOMPRESS_METHODDEF \ |
| 57 | {"decompress", (PyCFunction)zlib_decompress, METH_VARARGS, zlib_decompress__doc__}, |
| 58 | |
| 59 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 60 | zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, |
| 61 | unsigned int bufsize); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 62 | |
| 63 | static PyObject * |
| 64 | zlib_decompress(PyModuleDef *module, PyObject *args) |
| 65 | { |
| 66 | PyObject *return_value = NULL; |
| 67 | Py_buffer data = {NULL, NULL}; |
| 68 | int wbits = MAX_WBITS; |
| 69 | unsigned int bufsize = DEF_BUF_SIZE; |
| 70 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 71 | if (!PyArg_ParseTuple(args, "y*|iO&:decompress", |
Martin Panter | e99e977 | 2015-11-20 08:13:35 +0000 | [diff] [blame] | 72 | &data, &wbits, capped_uint_converter, &bufsize)) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 73 | goto exit; |
| 74 | return_value = zlib_decompress_impl(module, &data, wbits, bufsize); |
| 75 | |
| 76 | exit: |
| 77 | /* Cleanup for data */ |
| 78 | if (data.obj) |
| 79 | PyBuffer_Release(&data); |
| 80 | |
| 81 | return return_value; |
| 82 | } |
| 83 | |
| 84 | PyDoc_STRVAR(zlib_compressobj__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 85 | "compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n" |
| 86 | " wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n" |
| 87 | " strategy=Z_DEFAULT_STRATEGY, zdict=None)\n" |
| 88 | "--\n" |
| 89 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 90 | "Return a compressor object.\n" |
| 91 | "\n" |
| 92 | " level\n" |
Martin Panter | 567d513 | 2016-02-03 07:06:33 +0000 | [diff] [blame] | 93 | " The compression level (an integer in the range 0-9 or -1; default is\n" |
| 94 | " currently equivalent to 6). Higher compression levels are slower,\n" |
| 95 | " but produce smaller results.\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 96 | " method\n" |
| 97 | " The compression algorithm. If given, this must be DEFLATED.\n" |
| 98 | " wbits\n" |
| 99 | " The base two logarithm of the window size (range: 8..15).\n" |
| 100 | " memLevel\n" |
| 101 | " Controls the amount of memory used for internal compression state.\n" |
| 102 | " Valid values range from 1 to 9. Higher values result in higher memory\n" |
| 103 | " usage, faster compression, and smaller output.\n" |
| 104 | " strategy\n" |
| 105 | " Used to tune the compression algorithm. Possible values are\n" |
| 106 | " Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n" |
| 107 | " zdict\n" |
| 108 | " The predefined compression dictionary - a sequence of bytes\n" |
| 109 | " containing subsequences that are likely to occur in the input data."); |
| 110 | |
| 111 | #define ZLIB_COMPRESSOBJ_METHODDEF \ |
| 112 | {"compressobj", (PyCFunction)zlib_compressobj, METH_VARARGS|METH_KEYWORDS, zlib_compressobj__doc__}, |
| 113 | |
| 114 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 115 | zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, |
| 116 | int memLevel, int strategy, Py_buffer *zdict); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 117 | |
| 118 | static PyObject * |
| 119 | zlib_compressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 120 | { |
| 121 | PyObject *return_value = NULL; |
| 122 | static char *_keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL}; |
| 123 | int level = Z_DEFAULT_COMPRESSION; |
| 124 | int method = DEFLATED; |
| 125 | int wbits = MAX_WBITS; |
| 126 | int memLevel = DEF_MEM_LEVEL; |
| 127 | int strategy = Z_DEFAULT_STRATEGY; |
| 128 | Py_buffer zdict = {NULL, NULL}; |
| 129 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 130 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiiiy*:compressobj", _keywords, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 131 | &level, &method, &wbits, &memLevel, &strategy, &zdict)) |
| 132 | goto exit; |
| 133 | return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict); |
| 134 | |
| 135 | exit: |
| 136 | /* Cleanup for zdict */ |
| 137 | if (zdict.obj) |
| 138 | PyBuffer_Release(&zdict); |
| 139 | |
| 140 | return return_value; |
| 141 | } |
| 142 | |
| 143 | PyDoc_STRVAR(zlib_decompressobj__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 144 | "decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n" |
| 145 | "--\n" |
| 146 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 147 | "Return a decompressor object.\n" |
| 148 | "\n" |
| 149 | " wbits\n" |
| 150 | " The window buffer size.\n" |
| 151 | " zdict\n" |
| 152 | " The predefined compression dictionary. This must be the same\n" |
| 153 | " dictionary as used by the compressor that produced the input data."); |
| 154 | |
| 155 | #define ZLIB_DECOMPRESSOBJ_METHODDEF \ |
| 156 | {"decompressobj", (PyCFunction)zlib_decompressobj, METH_VARARGS|METH_KEYWORDS, zlib_decompressobj__doc__}, |
| 157 | |
| 158 | static PyObject * |
| 159 | zlib_decompressobj_impl(PyModuleDef *module, int wbits, PyObject *zdict); |
| 160 | |
| 161 | static PyObject * |
| 162 | zlib_decompressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 163 | { |
| 164 | PyObject *return_value = NULL; |
| 165 | static char *_keywords[] = {"wbits", "zdict", NULL}; |
| 166 | int wbits = MAX_WBITS; |
| 167 | PyObject *zdict = NULL; |
| 168 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 169 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:decompressobj", _keywords, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 170 | &wbits, &zdict)) |
| 171 | goto exit; |
| 172 | return_value = zlib_decompressobj_impl(module, wbits, zdict); |
| 173 | |
| 174 | exit: |
| 175 | return return_value; |
| 176 | } |
| 177 | |
| 178 | PyDoc_STRVAR(zlib_Compress_compress__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 179 | "compress($self, data, /)\n" |
| 180 | "--\n" |
| 181 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 182 | "Returns a bytes object containing compressed data.\n" |
| 183 | "\n" |
| 184 | " data\n" |
| 185 | " Binary data to be compressed.\n" |
| 186 | "\n" |
| 187 | "After calling this function, some of the input data may still\n" |
| 188 | "be stored in internal buffers for later processing.\n" |
| 189 | "Call the flush() method to clear these buffers."); |
| 190 | |
| 191 | #define ZLIB_COMPRESS_COMPRESS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 192 | {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 193 | |
| 194 | static PyObject * |
| 195 | zlib_Compress_compress_impl(compobject *self, Py_buffer *data); |
| 196 | |
| 197 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 198 | zlib_Compress_compress(compobject *self, PyObject *arg) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 199 | { |
| 200 | PyObject *return_value = NULL; |
| 201 | Py_buffer data = {NULL, NULL}; |
| 202 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 203 | if (!PyArg_Parse(arg, "y*:compress", &data)) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 204 | goto exit; |
| 205 | return_value = zlib_Compress_compress_impl(self, &data); |
| 206 | |
| 207 | exit: |
| 208 | /* Cleanup for data */ |
| 209 | if (data.obj) |
| 210 | PyBuffer_Release(&data); |
| 211 | |
| 212 | return return_value; |
| 213 | } |
| 214 | |
| 215 | PyDoc_STRVAR(zlib_Decompress_decompress__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 216 | "decompress($self, data, max_length=0, /)\n" |
| 217 | "--\n" |
| 218 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 219 | "Return a bytes object containing the decompressed version of the data.\n" |
| 220 | "\n" |
| 221 | " data\n" |
| 222 | " The binary data to decompress.\n" |
| 223 | " max_length\n" |
| 224 | " The maximum allowable length of the decompressed data.\n" |
| 225 | " Unconsumed input data will be stored in\n" |
| 226 | " the unconsumed_tail attribute.\n" |
| 227 | "\n" |
| 228 | "After calling this function, some of the input data may still be stored in\n" |
| 229 | "internal buffers for later processing.\n" |
| 230 | "Call the flush() method to clear these buffers."); |
| 231 | |
| 232 | #define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \ |
| 233 | {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_VARARGS, zlib_Decompress_decompress__doc__}, |
| 234 | |
| 235 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 236 | zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, |
| 237 | unsigned int max_length); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 238 | |
| 239 | static PyObject * |
| 240 | zlib_Decompress_decompress(compobject *self, PyObject *args) |
| 241 | { |
| 242 | PyObject *return_value = NULL; |
| 243 | Py_buffer data = {NULL, NULL}; |
| 244 | unsigned int max_length = 0; |
| 245 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 246 | if (!PyArg_ParseTuple(args, "y*|O&:decompress", |
Martin Panter | e99e977 | 2015-11-20 08:13:35 +0000 | [diff] [blame] | 247 | &data, capped_uint_converter, &max_length)) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 248 | goto exit; |
| 249 | return_value = zlib_Decompress_decompress_impl(self, &data, max_length); |
| 250 | |
| 251 | exit: |
| 252 | /* Cleanup for data */ |
| 253 | if (data.obj) |
| 254 | PyBuffer_Release(&data); |
| 255 | |
| 256 | return return_value; |
| 257 | } |
| 258 | |
| 259 | PyDoc_STRVAR(zlib_Compress_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 260 | "flush($self, mode=zlib.Z_FINISH, /)\n" |
| 261 | "--\n" |
| 262 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 263 | "Return a bytes object containing any remaining compressed data.\n" |
| 264 | "\n" |
| 265 | " mode\n" |
| 266 | " One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n" |
| 267 | " If mode == Z_FINISH, the compressor object can no longer be\n" |
| 268 | " used after calling the flush() method. Otherwise, more data\n" |
| 269 | " can still be compressed."); |
| 270 | |
| 271 | #define ZLIB_COMPRESS_FLUSH_METHODDEF \ |
| 272 | {"flush", (PyCFunction)zlib_Compress_flush, METH_VARARGS, zlib_Compress_flush__doc__}, |
| 273 | |
| 274 | static PyObject * |
| 275 | zlib_Compress_flush_impl(compobject *self, int mode); |
| 276 | |
| 277 | static PyObject * |
| 278 | zlib_Compress_flush(compobject *self, PyObject *args) |
| 279 | { |
| 280 | PyObject *return_value = NULL; |
| 281 | int mode = Z_FINISH; |
| 282 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 283 | if (!PyArg_ParseTuple(args, "|i:flush", |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 284 | &mode)) |
| 285 | goto exit; |
| 286 | return_value = zlib_Compress_flush_impl(self, mode); |
| 287 | |
| 288 | exit: |
| 289 | return return_value; |
| 290 | } |
| 291 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 292 | #if defined(HAVE_ZLIB_COPY) |
| 293 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 294 | PyDoc_STRVAR(zlib_Compress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 295 | "copy($self, /)\n" |
| 296 | "--\n" |
| 297 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 298 | "Return a copy of the compression object."); |
| 299 | |
| 300 | #define ZLIB_COMPRESS_COPY_METHODDEF \ |
| 301 | {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__}, |
| 302 | |
| 303 | static PyObject * |
| 304 | zlib_Compress_copy_impl(compobject *self); |
| 305 | |
| 306 | static PyObject * |
| 307 | zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 308 | { |
| 309 | return zlib_Compress_copy_impl(self); |
| 310 | } |
| 311 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 312 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 313 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 314 | #if defined(HAVE_ZLIB_COPY) |
| 315 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 316 | PyDoc_STRVAR(zlib_Decompress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 317 | "copy($self, /)\n" |
| 318 | "--\n" |
| 319 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 320 | "Return a copy of the decompression object."); |
| 321 | |
| 322 | #define ZLIB_DECOMPRESS_COPY_METHODDEF \ |
| 323 | {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__}, |
| 324 | |
| 325 | static PyObject * |
| 326 | zlib_Decompress_copy_impl(compobject *self); |
| 327 | |
| 328 | static PyObject * |
| 329 | zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 330 | { |
| 331 | return zlib_Decompress_copy_impl(self); |
| 332 | } |
| 333 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 334 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 335 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 336 | PyDoc_STRVAR(zlib_Decompress_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 337 | "flush($self, length=zlib.DEF_BUF_SIZE, /)\n" |
| 338 | "--\n" |
| 339 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 340 | "Return a bytes object containing any remaining decompressed data.\n" |
| 341 | "\n" |
| 342 | " length\n" |
| 343 | " the initial size of the output buffer."); |
| 344 | |
| 345 | #define ZLIB_DECOMPRESS_FLUSH_METHODDEF \ |
| 346 | {"flush", (PyCFunction)zlib_Decompress_flush, METH_VARARGS, zlib_Decompress_flush__doc__}, |
| 347 | |
| 348 | static PyObject * |
| 349 | zlib_Decompress_flush_impl(compobject *self, unsigned int length); |
| 350 | |
| 351 | static PyObject * |
| 352 | zlib_Decompress_flush(compobject *self, PyObject *args) |
| 353 | { |
| 354 | PyObject *return_value = NULL; |
| 355 | unsigned int length = DEF_BUF_SIZE; |
| 356 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 357 | if (!PyArg_ParseTuple(args, "|O&:flush", |
Martin Panter | e99e977 | 2015-11-20 08:13:35 +0000 | [diff] [blame] | 358 | capped_uint_converter, &length)) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 359 | goto exit; |
| 360 | return_value = zlib_Decompress_flush_impl(self, length); |
| 361 | |
| 362 | exit: |
| 363 | return return_value; |
| 364 | } |
| 365 | |
| 366 | PyDoc_STRVAR(zlib_adler32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 367 | "adler32($module, data, value=1, /)\n" |
| 368 | "--\n" |
| 369 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 370 | "Compute an Adler-32 checksum of data.\n" |
| 371 | "\n" |
| 372 | " value\n" |
| 373 | " Starting value of the checksum.\n" |
| 374 | "\n" |
| 375 | "The returned checksum is an integer."); |
| 376 | |
| 377 | #define ZLIB_ADLER32_METHODDEF \ |
| 378 | {"adler32", (PyCFunction)zlib_adler32, METH_VARARGS, zlib_adler32__doc__}, |
| 379 | |
| 380 | static PyObject * |
| 381 | zlib_adler32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value); |
| 382 | |
| 383 | static PyObject * |
| 384 | zlib_adler32(PyModuleDef *module, PyObject *args) |
| 385 | { |
| 386 | PyObject *return_value = NULL; |
| 387 | Py_buffer data = {NULL, NULL}; |
| 388 | unsigned int value = 1; |
| 389 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 390 | if (!PyArg_ParseTuple(args, "y*|I:adler32", |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 391 | &data, &value)) |
| 392 | goto exit; |
| 393 | return_value = zlib_adler32_impl(module, &data, value); |
| 394 | |
| 395 | exit: |
| 396 | /* Cleanup for data */ |
| 397 | if (data.obj) |
| 398 | PyBuffer_Release(&data); |
| 399 | |
| 400 | return return_value; |
| 401 | } |
| 402 | |
| 403 | PyDoc_STRVAR(zlib_crc32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 404 | "crc32($module, data, value=0, /)\n" |
| 405 | "--\n" |
| 406 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 407 | "Compute a CRC-32 checksum of data.\n" |
| 408 | "\n" |
| 409 | " value\n" |
| 410 | " Starting value of the checksum.\n" |
| 411 | "\n" |
| 412 | "The returned checksum is an integer."); |
| 413 | |
| 414 | #define ZLIB_CRC32_METHODDEF \ |
| 415 | {"crc32", (PyCFunction)zlib_crc32, METH_VARARGS, zlib_crc32__doc__}, |
| 416 | |
| 417 | static PyObject * |
| 418 | zlib_crc32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value); |
| 419 | |
| 420 | static PyObject * |
| 421 | zlib_crc32(PyModuleDef *module, PyObject *args) |
| 422 | { |
| 423 | PyObject *return_value = NULL; |
| 424 | Py_buffer data = {NULL, NULL}; |
| 425 | unsigned int value = 0; |
| 426 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 427 | if (!PyArg_ParseTuple(args, "y*|I:crc32", |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 428 | &data, &value)) |
| 429 | goto exit; |
| 430 | return_value = zlib_crc32_impl(module, &data, value); |
| 431 | |
| 432 | exit: |
| 433 | /* Cleanup for data */ |
| 434 | if (data.obj) |
| 435 | PyBuffer_Release(&data); |
| 436 | |
| 437 | return return_value; |
| 438 | } |
Larry Hastings | 0759f84 | 2015-04-03 13:09:02 -0700 | [diff] [blame] | 439 | |
| 440 | #ifndef ZLIB_COMPRESS_COPY_METHODDEF |
| 441 | #define ZLIB_COMPRESS_COPY_METHODDEF |
| 442 | #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ |
Martin Panter | b0cb42d | 2016-02-10 10:45:54 +0000 | [diff] [blame] | 443 | /*[clinic end generated code: output=e6f3b79e051ecc35 input=a9049054013a1b77]*/ |