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