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