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)(void(*)(void))zlib_compress, METH_FASTCALL|METH_KEYWORDS, 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 * const * args,Py_ssize_t nargs,PyObject * kwnames)23 zlib_compress(PyObject *module, PyObject *const *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 = {NULL, _keywords, "compress", 0};
28 PyObject *argsbuf[2];
29 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
30 Py_buffer data = {NULL, NULL};
31 int level = Z_DEFAULT_COMPRESSION;
32
33 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
34 if (!args) {
35 goto exit;
36 }
37 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
38 goto exit;
39 }
40 if (!PyBuffer_IsContiguous(&data, 'C')) {
41 _PyArg_BadArgument("compress", "argument 1", "contiguous buffer", args[0]);
42 goto exit;
43 }
44 if (!noptargs) {
45 goto skip_optional_pos;
46 }
47 level = _PyLong_AsInt(args[1]);
48 if (level == -1 && PyErr_Occurred()) {
49 goto exit;
50 }
51 skip_optional_pos:
52 return_value = zlib_compress_impl(module, &data, level);
53
54 exit:
55 /* Cleanup for data */
56 if (data.obj) {
57 PyBuffer_Release(&data);
58 }
59
60 return return_value;
61 }
62
63 PyDoc_STRVAR(zlib_decompress__doc__,
64 "decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n"
65 "--\n"
66 "\n"
67 "Returns a bytes object containing the uncompressed data.\n"
68 "\n"
69 " data\n"
70 " Compressed data.\n"
71 " wbits\n"
72 " The window buffer size and container format.\n"
73 " bufsize\n"
74 " The initial output buffer size.");
75
76 #define ZLIB_DECOMPRESS_METHODDEF \
77 {"decompress", (PyCFunction)(void(*)(void))zlib_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_decompress__doc__},
78
79 static PyObject *
80 zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits,
81 Py_ssize_t bufsize);
82
83 static PyObject *
zlib_decompress(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)84 zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
85 {
86 PyObject *return_value = NULL;
87 static const char * const _keywords[] = {"", "wbits", "bufsize", NULL};
88 static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
89 PyObject *argsbuf[3];
90 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
91 Py_buffer data = {NULL, NULL};
92 int wbits = MAX_WBITS;
93 Py_ssize_t bufsize = DEF_BUF_SIZE;
94
95 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
96 if (!args) {
97 goto exit;
98 }
99 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
100 goto exit;
101 }
102 if (!PyBuffer_IsContiguous(&data, 'C')) {
103 _PyArg_BadArgument("decompress", "argument 1", "contiguous buffer", args[0]);
104 goto exit;
105 }
106 if (!noptargs) {
107 goto skip_optional_pos;
108 }
109 if (args[1]) {
110 wbits = _PyLong_AsInt(args[1]);
111 if (wbits == -1 && PyErr_Occurred()) {
112 goto exit;
113 }
114 if (!--noptargs) {
115 goto skip_optional_pos;
116 }
117 }
118 {
119 Py_ssize_t ival = -1;
120 PyObject *iobj = _PyNumber_Index(args[2]);
121 if (iobj != NULL) {
122 ival = PyLong_AsSsize_t(iobj);
123 Py_DECREF(iobj);
124 }
125 if (ival == -1 && PyErr_Occurred()) {
126 goto exit;
127 }
128 bufsize = ival;
129 }
130 skip_optional_pos:
131 return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
132
133 exit:
134 /* Cleanup for data */
135 if (data.obj) {
136 PyBuffer_Release(&data);
137 }
138
139 return return_value;
140 }
141
142 PyDoc_STRVAR(zlib_compressobj__doc__,
143 "compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n"
144 " wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n"
145 " strategy=Z_DEFAULT_STRATEGY, zdict=None)\n"
146 "--\n"
147 "\n"
148 "Return a compressor object.\n"
149 "\n"
150 " level\n"
151 " The compression level (an integer in the range 0-9 or -1; default is\n"
152 " currently equivalent to 6). Higher compression levels are slower,\n"
153 " but produce smaller results.\n"
154 " method\n"
155 " The compression algorithm. If given, this must be DEFLATED.\n"
156 " wbits\n"
157 " +9 to +15: The base-two logarithm of the window size. Include a zlib\n"
158 " container.\n"
159 " -9 to -15: Generate a raw stream.\n"
160 " +25 to +31: Include a gzip container.\n"
161 " memLevel\n"
162 " Controls the amount of memory used for internal compression state.\n"
163 " Valid values range from 1 to 9. Higher values result in higher memory\n"
164 " usage, faster compression, and smaller output.\n"
165 " strategy\n"
166 " Used to tune the compression algorithm. Possible values are\n"
167 " Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
168 " zdict\n"
169 " The predefined compression dictionary - a sequence of bytes\n"
170 " containing subsequences that are likely to occur in the input data.");
171
172 #define ZLIB_COMPRESSOBJ_METHODDEF \
173 {"compressobj", (PyCFunction)(void(*)(void))zlib_compressobj, METH_FASTCALL|METH_KEYWORDS, zlib_compressobj__doc__},
174
175 static PyObject *
176 zlib_compressobj_impl(PyObject *module, int level, int method, int wbits,
177 int memLevel, int strategy, Py_buffer *zdict);
178
179 static PyObject *
zlib_compressobj(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)180 zlib_compressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
181 {
182 PyObject *return_value = NULL;
183 static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
184 static _PyArg_Parser _parser = {NULL, _keywords, "compressobj", 0};
185 PyObject *argsbuf[6];
186 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
187 int level = Z_DEFAULT_COMPRESSION;
188 int method = DEFLATED;
189 int wbits = MAX_WBITS;
190 int memLevel = DEF_MEM_LEVEL;
191 int strategy = Z_DEFAULT_STRATEGY;
192 Py_buffer zdict = {NULL, NULL};
193
194 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 6, 0, argsbuf);
195 if (!args) {
196 goto exit;
197 }
198 if (!noptargs) {
199 goto skip_optional_pos;
200 }
201 if (args[0]) {
202 level = _PyLong_AsInt(args[0]);
203 if (level == -1 && PyErr_Occurred()) {
204 goto exit;
205 }
206 if (!--noptargs) {
207 goto skip_optional_pos;
208 }
209 }
210 if (args[1]) {
211 method = _PyLong_AsInt(args[1]);
212 if (method == -1 && PyErr_Occurred()) {
213 goto exit;
214 }
215 if (!--noptargs) {
216 goto skip_optional_pos;
217 }
218 }
219 if (args[2]) {
220 wbits = _PyLong_AsInt(args[2]);
221 if (wbits == -1 && PyErr_Occurred()) {
222 goto exit;
223 }
224 if (!--noptargs) {
225 goto skip_optional_pos;
226 }
227 }
228 if (args[3]) {
229 memLevel = _PyLong_AsInt(args[3]);
230 if (memLevel == -1 && PyErr_Occurred()) {
231 goto exit;
232 }
233 if (!--noptargs) {
234 goto skip_optional_pos;
235 }
236 }
237 if (args[4]) {
238 strategy = _PyLong_AsInt(args[4]);
239 if (strategy == -1 && PyErr_Occurred()) {
240 goto exit;
241 }
242 if (!--noptargs) {
243 goto skip_optional_pos;
244 }
245 }
246 if (PyObject_GetBuffer(args[5], &zdict, PyBUF_SIMPLE) != 0) {
247 goto exit;
248 }
249 if (!PyBuffer_IsContiguous(&zdict, 'C')) {
250 _PyArg_BadArgument("compressobj", "argument 'zdict'", "contiguous buffer", args[5]);
251 goto exit;
252 }
253 skip_optional_pos:
254 return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
255
256 exit:
257 /* Cleanup for zdict */
258 if (zdict.obj) {
259 PyBuffer_Release(&zdict);
260 }
261
262 return return_value;
263 }
264
265 PyDoc_STRVAR(zlib_decompressobj__doc__,
266 "decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n"
267 "--\n"
268 "\n"
269 "Return a decompressor object.\n"
270 "\n"
271 " wbits\n"
272 " The window buffer size and container format.\n"
273 " zdict\n"
274 " The predefined compression dictionary. This must be the same\n"
275 " dictionary as used by the compressor that produced the input data.");
276
277 #define ZLIB_DECOMPRESSOBJ_METHODDEF \
278 {"decompressobj", (PyCFunction)(void(*)(void))zlib_decompressobj, METH_FASTCALL|METH_KEYWORDS, zlib_decompressobj__doc__},
279
280 static PyObject *
281 zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict);
282
283 static PyObject *
zlib_decompressobj(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)284 zlib_decompressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
285 {
286 PyObject *return_value = NULL;
287 static const char * const _keywords[] = {"wbits", "zdict", NULL};
288 static _PyArg_Parser _parser = {NULL, _keywords, "decompressobj", 0};
289 PyObject *argsbuf[2];
290 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
291 int wbits = MAX_WBITS;
292 PyObject *zdict = NULL;
293
294 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
295 if (!args) {
296 goto exit;
297 }
298 if (!noptargs) {
299 goto skip_optional_pos;
300 }
301 if (args[0]) {
302 wbits = _PyLong_AsInt(args[0]);
303 if (wbits == -1 && PyErr_Occurred()) {
304 goto exit;
305 }
306 if (!--noptargs) {
307 goto skip_optional_pos;
308 }
309 }
310 zdict = args[1];
311 skip_optional_pos:
312 return_value = zlib_decompressobj_impl(module, wbits, zdict);
313
314 exit:
315 return return_value;
316 }
317
318 PyDoc_STRVAR(zlib_Compress_compress__doc__,
319 "compress($self, data, /)\n"
320 "--\n"
321 "\n"
322 "Returns a bytes object containing compressed data.\n"
323 "\n"
324 " data\n"
325 " Binary data to be compressed.\n"
326 "\n"
327 "After calling this function, some of the input data may still\n"
328 "be stored in internal buffers for later processing.\n"
329 "Call the flush() method to clear these buffers.");
330
331 #define ZLIB_COMPRESS_COMPRESS_METHODDEF \
332 {"compress", (PyCFunction)(void(*)(void))zlib_Compress_compress, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_compress__doc__},
333
334 static PyObject *
335 zlib_Compress_compress_impl(compobject *self, PyTypeObject *cls,
336 Py_buffer *data);
337
338 static PyObject *
zlib_Compress_compress(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)339 zlib_Compress_compress(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
340 {
341 PyObject *return_value = NULL;
342 static const char * const _keywords[] = {"", NULL};
343 static _PyArg_Parser _parser = {"y*:compress", _keywords, 0};
344 Py_buffer data = {NULL, NULL};
345
346 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
347 &data)) {
348 goto exit;
349 }
350 return_value = zlib_Compress_compress_impl(self, cls, &data);
351
352 exit:
353 /* Cleanup for data */
354 if (data.obj) {
355 PyBuffer_Release(&data);
356 }
357
358 return return_value;
359 }
360
361 PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
362 "decompress($self, data, /, max_length=0)\n"
363 "--\n"
364 "\n"
365 "Return a bytes object containing the decompressed version of the data.\n"
366 "\n"
367 " data\n"
368 " The binary data to decompress.\n"
369 " max_length\n"
370 " The maximum allowable length of the decompressed data.\n"
371 " Unconsumed input data will be stored in\n"
372 " the unconsumed_tail attribute.\n"
373 "\n"
374 "After calling this function, some of the input data may still be stored in\n"
375 "internal buffers for later processing.\n"
376 "Call the flush() method to clear these buffers.");
377
378 #define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \
379 {"decompress", (PyCFunction)(void(*)(void))zlib_Decompress_decompress, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__},
380
381 static PyObject *
382 zlib_Decompress_decompress_impl(compobject *self, PyTypeObject *cls,
383 Py_buffer *data, Py_ssize_t max_length);
384
385 static PyObject *
zlib_Decompress_decompress(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)386 zlib_Decompress_decompress(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
387 {
388 PyObject *return_value = NULL;
389 static const char * const _keywords[] = {"", "max_length", NULL};
390 static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0};
391 Py_buffer data = {NULL, NULL};
392 Py_ssize_t max_length = 0;
393
394 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
395 &data, &max_length)) {
396 goto exit;
397 }
398 return_value = zlib_Decompress_decompress_impl(self, cls, &data, max_length);
399
400 exit:
401 /* Cleanup for data */
402 if (data.obj) {
403 PyBuffer_Release(&data);
404 }
405
406 return return_value;
407 }
408
409 PyDoc_STRVAR(zlib_Compress_flush__doc__,
410 "flush($self, mode=zlib.Z_FINISH, /)\n"
411 "--\n"
412 "\n"
413 "Return a bytes object containing any remaining compressed data.\n"
414 "\n"
415 " mode\n"
416 " One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
417 " If mode == Z_FINISH, the compressor object can no longer be\n"
418 " used after calling the flush() method. Otherwise, more data\n"
419 " can still be compressed.");
420
421 #define ZLIB_COMPRESS_FLUSH_METHODDEF \
422 {"flush", (PyCFunction)(void(*)(void))zlib_Compress_flush, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_flush__doc__},
423
424 static PyObject *
425 zlib_Compress_flush_impl(compobject *self, PyTypeObject *cls, int mode);
426
427 static PyObject *
zlib_Compress_flush(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)428 zlib_Compress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
429 {
430 PyObject *return_value = NULL;
431 static const char * const _keywords[] = {"", NULL};
432 static _PyArg_Parser _parser = {"|i:flush", _keywords, 0};
433 int mode = Z_FINISH;
434
435 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
436 &mode)) {
437 goto exit;
438 }
439 return_value = zlib_Compress_flush_impl(self, cls, mode);
440
441 exit:
442 return return_value;
443 }
444
445 #if defined(HAVE_ZLIB_COPY)
446
447 PyDoc_STRVAR(zlib_Compress_copy__doc__,
448 "copy($self, /)\n"
449 "--\n"
450 "\n"
451 "Return a copy of the compression object.");
452
453 #define ZLIB_COMPRESS_COPY_METHODDEF \
454 {"copy", (PyCFunction)(void(*)(void))zlib_Compress_copy, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_copy__doc__},
455
456 static PyObject *
457 zlib_Compress_copy_impl(compobject *self, PyTypeObject *cls);
458
459 static PyObject *
zlib_Compress_copy(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)460 zlib_Compress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461 {
462 PyObject *return_value = NULL;
463 static const char * const _keywords[] = { NULL};
464 static _PyArg_Parser _parser = {":copy", _keywords, 0};
465
466 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
467 )) {
468 goto exit;
469 }
470 return_value = zlib_Compress_copy_impl(self, cls);
471
472 exit:
473 return return_value;
474 }
475
476 #endif /* defined(HAVE_ZLIB_COPY) */
477
478 #if defined(HAVE_ZLIB_COPY)
479
480 PyDoc_STRVAR(zlib_Compress___copy____doc__,
481 "__copy__($self, /)\n"
482 "--\n"
483 "\n");
484
485 #define ZLIB_COMPRESS___COPY___METHODDEF \
486 {"__copy__", (PyCFunction)(void(*)(void))zlib_Compress___copy__, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress___copy____doc__},
487
488 static PyObject *
489 zlib_Compress___copy___impl(compobject *self, PyTypeObject *cls);
490
491 static PyObject *
zlib_Compress___copy__(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)492 zlib_Compress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
493 {
494 PyObject *return_value = NULL;
495 static const char * const _keywords[] = { NULL};
496 static _PyArg_Parser _parser = {":__copy__", _keywords, 0};
497
498 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
499 )) {
500 goto exit;
501 }
502 return_value = zlib_Compress___copy___impl(self, cls);
503
504 exit:
505 return return_value;
506 }
507
508 #endif /* defined(HAVE_ZLIB_COPY) */
509
510 #if defined(HAVE_ZLIB_COPY)
511
512 PyDoc_STRVAR(zlib_Compress___deepcopy____doc__,
513 "__deepcopy__($self, memo, /)\n"
514 "--\n"
515 "\n");
516
517 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF \
518 {"__deepcopy__", (PyCFunction)(void(*)(void))zlib_Compress___deepcopy__, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress___deepcopy____doc__},
519
520 static PyObject *
521 zlib_Compress___deepcopy___impl(compobject *self, PyTypeObject *cls,
522 PyObject *memo);
523
524 static PyObject *
zlib_Compress___deepcopy__(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)525 zlib_Compress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
526 {
527 PyObject *return_value = NULL;
528 static const char * const _keywords[] = {"", NULL};
529 static _PyArg_Parser _parser = {"O:__deepcopy__", _keywords, 0};
530 PyObject *memo;
531
532 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
533 &memo)) {
534 goto exit;
535 }
536 return_value = zlib_Compress___deepcopy___impl(self, cls, memo);
537
538 exit:
539 return return_value;
540 }
541
542 #endif /* defined(HAVE_ZLIB_COPY) */
543
544 #if defined(HAVE_ZLIB_COPY)
545
546 PyDoc_STRVAR(zlib_Decompress_copy__doc__,
547 "copy($self, /)\n"
548 "--\n"
549 "\n"
550 "Return a copy of the decompression object.");
551
552 #define ZLIB_DECOMPRESS_COPY_METHODDEF \
553 {"copy", (PyCFunction)(void(*)(void))zlib_Decompress_copy, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_copy__doc__},
554
555 static PyObject *
556 zlib_Decompress_copy_impl(compobject *self, PyTypeObject *cls);
557
558 static PyObject *
zlib_Decompress_copy(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)559 zlib_Decompress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
560 {
561 PyObject *return_value = NULL;
562 static const char * const _keywords[] = { NULL};
563 static _PyArg_Parser _parser = {":copy", _keywords, 0};
564
565 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
566 )) {
567 goto exit;
568 }
569 return_value = zlib_Decompress_copy_impl(self, cls);
570
571 exit:
572 return return_value;
573 }
574
575 #endif /* defined(HAVE_ZLIB_COPY) */
576
577 #if defined(HAVE_ZLIB_COPY)
578
579 PyDoc_STRVAR(zlib_Decompress___copy____doc__,
580 "__copy__($self, /)\n"
581 "--\n"
582 "\n");
583
584 #define ZLIB_DECOMPRESS___COPY___METHODDEF \
585 {"__copy__", (PyCFunction)(void(*)(void))zlib_Decompress___copy__, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress___copy____doc__},
586
587 static PyObject *
588 zlib_Decompress___copy___impl(compobject *self, PyTypeObject *cls);
589
590 static PyObject *
zlib_Decompress___copy__(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)591 zlib_Decompress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
592 {
593 PyObject *return_value = NULL;
594 static const char * const _keywords[] = { NULL};
595 static _PyArg_Parser _parser = {":__copy__", _keywords, 0};
596
597 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
598 )) {
599 goto exit;
600 }
601 return_value = zlib_Decompress___copy___impl(self, cls);
602
603 exit:
604 return return_value;
605 }
606
607 #endif /* defined(HAVE_ZLIB_COPY) */
608
609 #if defined(HAVE_ZLIB_COPY)
610
611 PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__,
612 "__deepcopy__($self, memo, /)\n"
613 "--\n"
614 "\n");
615
616 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF \
617 {"__deepcopy__", (PyCFunction)(void(*)(void))zlib_Decompress___deepcopy__, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress___deepcopy____doc__},
618
619 static PyObject *
620 zlib_Decompress___deepcopy___impl(compobject *self, PyTypeObject *cls,
621 PyObject *memo);
622
623 static PyObject *
zlib_Decompress___deepcopy__(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)624 zlib_Decompress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
625 {
626 PyObject *return_value = NULL;
627 static const char * const _keywords[] = {"", NULL};
628 static _PyArg_Parser _parser = {"O:__deepcopy__", _keywords, 0};
629 PyObject *memo;
630
631 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
632 &memo)) {
633 goto exit;
634 }
635 return_value = zlib_Decompress___deepcopy___impl(self, cls, memo);
636
637 exit:
638 return return_value;
639 }
640
641 #endif /* defined(HAVE_ZLIB_COPY) */
642
643 PyDoc_STRVAR(zlib_Decompress_flush__doc__,
644 "flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
645 "--\n"
646 "\n"
647 "Return a bytes object containing any remaining decompressed data.\n"
648 "\n"
649 " length\n"
650 " the initial size of the output buffer.");
651
652 #define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
653 {"flush", (PyCFunction)(void(*)(void))zlib_Decompress_flush, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_flush__doc__},
654
655 static PyObject *
656 zlib_Decompress_flush_impl(compobject *self, PyTypeObject *cls,
657 Py_ssize_t length);
658
659 static PyObject *
zlib_Decompress_flush(compobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)660 zlib_Decompress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
661 {
662 PyObject *return_value = NULL;
663 static const char * const _keywords[] = {"", NULL};
664 static _PyArg_Parser _parser = {"|n:flush", _keywords, 0};
665 Py_ssize_t length = DEF_BUF_SIZE;
666
667 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
668 &length)) {
669 goto exit;
670 }
671 return_value = zlib_Decompress_flush_impl(self, cls, length);
672
673 exit:
674 return return_value;
675 }
676
677 PyDoc_STRVAR(zlib_adler32__doc__,
678 "adler32($module, data, value=1, /)\n"
679 "--\n"
680 "\n"
681 "Compute an Adler-32 checksum of data.\n"
682 "\n"
683 " value\n"
684 " Starting value of the checksum.\n"
685 "\n"
686 "The returned checksum is an integer.");
687
688 #define ZLIB_ADLER32_METHODDEF \
689 {"adler32", (PyCFunction)(void(*)(void))zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
690
691 static PyObject *
692 zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
693
694 static PyObject *
zlib_adler32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)695 zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
696 {
697 PyObject *return_value = NULL;
698 Py_buffer data = {NULL, NULL};
699 unsigned int value = 1;
700
701 if (!_PyArg_CheckPositional("adler32", nargs, 1, 2)) {
702 goto exit;
703 }
704 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
705 goto exit;
706 }
707 if (!PyBuffer_IsContiguous(&data, 'C')) {
708 _PyArg_BadArgument("adler32", "argument 1", "contiguous buffer", args[0]);
709 goto exit;
710 }
711 if (nargs < 2) {
712 goto skip_optional;
713 }
714 value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
715 if (value == (unsigned int)-1 && PyErr_Occurred()) {
716 goto exit;
717 }
718 skip_optional:
719 return_value = zlib_adler32_impl(module, &data, value);
720
721 exit:
722 /* Cleanup for data */
723 if (data.obj) {
724 PyBuffer_Release(&data);
725 }
726
727 return return_value;
728 }
729
730 PyDoc_STRVAR(zlib_crc32__doc__,
731 "crc32($module, data, value=0, /)\n"
732 "--\n"
733 "\n"
734 "Compute a CRC-32 checksum of data.\n"
735 "\n"
736 " value\n"
737 " Starting value of the checksum.\n"
738 "\n"
739 "The returned checksum is an integer.");
740
741 #define ZLIB_CRC32_METHODDEF \
742 {"crc32", (PyCFunction)(void(*)(void))zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
743
744 static PyObject *
745 zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
746
747 static PyObject *
zlib_crc32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)748 zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
749 {
750 PyObject *return_value = NULL;
751 Py_buffer data = {NULL, NULL};
752 unsigned int value = 0;
753
754 if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
755 goto exit;
756 }
757 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
758 goto exit;
759 }
760 if (!PyBuffer_IsContiguous(&data, 'C')) {
761 _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
762 goto exit;
763 }
764 if (nargs < 2) {
765 goto skip_optional;
766 }
767 value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
768 if (value == (unsigned int)-1 && PyErr_Occurred()) {
769 goto exit;
770 }
771 skip_optional:
772 return_value = zlib_crc32_impl(module, &data, value);
773
774 exit:
775 /* Cleanup for data */
776 if (data.obj) {
777 PyBuffer_Release(&data);
778 }
779
780 return return_value;
781 }
782
783 #ifndef ZLIB_COMPRESS_COPY_METHODDEF
784 #define ZLIB_COMPRESS_COPY_METHODDEF
785 #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
786
787 #ifndef ZLIB_COMPRESS___COPY___METHODDEF
788 #define ZLIB_COMPRESS___COPY___METHODDEF
789 #endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */
790
791 #ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF
792 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF
793 #endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */
794
795 #ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
796 #define ZLIB_DECOMPRESS_COPY_METHODDEF
797 #endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
798
799 #ifndef ZLIB_DECOMPRESS___COPY___METHODDEF
800 #define ZLIB_DECOMPRESS___COPY___METHODDEF
801 #endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */
802
803 #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
804 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
805 #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
806 /*[clinic end generated code: output=6736bae59fab268b input=a9049054013a1b77]*/
807