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