blob: 99db052bf2faa9cd73a9fe59a2ed347f619ae44a [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__,
Serhiy Storchaka95657cd2016-06-25 22:43:05 +03006"compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -08007"--\n"
8"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +02009"Returns a bytes object containing compressed data.\n"
10"\n"
Martin Panter1fe0d132016-02-10 10:06:36 +000011" data\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020012" Binary data to be compressed.\n"
13" level\n"
Martin Panterb0cb42d2016-02-10 10:45:54 +000014" Compression level, in 0-9 or -1.");
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020015
16#define ZLIB_COMPRESS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030017 {"compress", (PyCFunction)zlib_compress, METH_FASTCALL|METH_KEYWORDS, zlib_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020018
19static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +030020zlib_compress_impl(PyObject *module, Py_buffer *data, int level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020021
22static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020023zlib_compress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020024{
25 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030026 static const char * const _keywords[] = {"", "level", NULL};
27 static _PyArg_Parser _parser = {"y*|i:compress", _keywords, 0};
Martin Panter1fe0d132016-02-10 10:06:36 +000028 Py_buffer data = {NULL, NULL};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020029 int level = Z_DEFAULT_COMPRESSION;
30
Victor Stinner3e1fad62017-01-17 01:29:01 +010031 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030032 &data, &level)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030034 }
Martin Panter1fe0d132016-02-10 10:06:36 +000035 return_value = zlib_compress_impl(module, &data, level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020036
37exit:
Martin Panter1fe0d132016-02-10 10:06:36 +000038 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030039 if (data.obj) {
Martin Panter1fe0d132016-02-10 10:06:36 +000040 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030041 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020042
43 return return_value;
44}
45
46PyDoc_STRVAR(zlib_decompress__doc__,
Serhiy Storchaka15f32282016-08-15 10:06:16 +030047"decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -080048"--\n"
49"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020050"Returns a bytes object containing the uncompressed data.\n"
51"\n"
52" data\n"
53" Compressed data.\n"
54" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +000055" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020056" bufsize\n"
57" The initial output buffer size.");
58
59#define ZLIB_DECOMPRESS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030060 {"decompress", (PyCFunction)zlib_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_decompress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020061
62static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030063zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits,
Martin Panter84544c12016-07-23 03:02:07 +000064 Py_ssize_t bufsize);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020065
66static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020067zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020068{
69 PyObject *return_value = NULL;
Serhiy Storchaka15f32282016-08-15 10:06:16 +030070 static const char * const _keywords[] = {"", "wbits", "bufsize", NULL};
71 static _PyArg_Parser _parser = {"y*|iO&:decompress", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020072 Py_buffer data = {NULL, NULL};
73 int wbits = MAX_WBITS;
Martin Panter84544c12016-07-23 03:02:07 +000074 Py_ssize_t bufsize = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020075
Victor Stinner3e1fad62017-01-17 01:29:01 +010076 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Martin Panter525a9492016-07-23 03:39:49 +000077 &data, &wbits, ssize_t_converter, &bufsize)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030079 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020080 return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
81
82exit:
83 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020085 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020087
88 return return_value;
89}
90
91PyDoc_STRVAR(zlib_compressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080092"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"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020097"Return a compressor object.\n"
98"\n"
99" level\n"
Martin Panter567d5132016-02-03 07:06:33 +0000100" 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"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200103" method\n"
104" The compression algorithm. If given, this must be DEFLATED.\n"
105" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000106" +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"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200110" 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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300122 {"compressobj", (PyCFunction)zlib_compressobj, METH_FASTCALL|METH_KEYWORDS, zlib_compressobj__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200123
124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300125zlib_compressobj_impl(PyObject *module, int level, int method, int wbits,
Larry Hastings89964c42015-04-14 18:07:59 -0400126 int memLevel, int strategy, Py_buffer *zdict);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200127
128static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200129zlib_compressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200130{
131 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300132 static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
133 static _PyArg_Parser _parser = {"|iiiiiy*:compressobj", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200134 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
Victor Stinner3e1fad62017-01-17 01:29:01 +0100141 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300142 &level, &method, &wbits, &memLevel, &strategy, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200143 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300144 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200145 return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
146
147exit:
148 /* Cleanup for zdict */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 if (zdict.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200150 PyBuffer_Release(&zdict);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200152
153 return return_value;
154}
155
156PyDoc_STRVAR(zlib_decompressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800157"decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n"
158"--\n"
159"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200160"Return a decompressor object.\n"
161"\n"
162" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000163" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200164" 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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300169 {"decompressobj", (PyCFunction)zlib_decompressobj, METH_FASTCALL|METH_KEYWORDS, zlib_decompressobj__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200170
171static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300172zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200173
174static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200175zlib_decompressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200176{
177 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300178 static const char * const _keywords[] = {"wbits", "zdict", NULL};
179 static _PyArg_Parser _parser = {"|iO:decompressobj", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200180 int wbits = MAX_WBITS;
181 PyObject *zdict = NULL;
182
Victor Stinner3e1fad62017-01-17 01:29:01 +0100183 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300184 &wbits, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200185 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300186 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200187 return_value = zlib_decompressobj_impl(module, wbits, zdict);
188
189exit:
190 return return_value;
191}
192
193PyDoc_STRVAR(zlib_Compress_compress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800194"compress($self, data, /)\n"
195"--\n"
196"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200197"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 \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300207 {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200208
209static PyObject *
210zlib_Compress_compress_impl(compobject *self, Py_buffer *data);
211
212static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300213zlib_Compress_compress(compobject *self, PyObject *arg)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200214{
215 PyObject *return_value = NULL;
216 Py_buffer data = {NULL, NULL};
217
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300218 if (!PyArg_Parse(arg, "y*:compress", &data)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200219 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300220 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200221 return_value = zlib_Compress_compress_impl(self, &data);
222
223exit:
224 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300225 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200226 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300227 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200228
229 return return_value;
230}
231
232PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300233"decompress($self, data, /, max_length=0)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800234"--\n"
235"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200236"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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300250 {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200251
252static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400253zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
Martin Panter84544c12016-07-23 03:02:07 +0000254 Py_ssize_t max_length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200255
256static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200257zlib_Decompress_decompress(compobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200258{
259 PyObject *return_value = NULL;
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300260 static const char * const _keywords[] = {"", "max_length", NULL};
261 static _PyArg_Parser _parser = {"y*|O&:decompress", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200262 Py_buffer data = {NULL, NULL};
Martin Panter84544c12016-07-23 03:02:07 +0000263 Py_ssize_t max_length = 0;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200264
Victor Stinner3e1fad62017-01-17 01:29:01 +0100265 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Martin Panter525a9492016-07-23 03:39:49 +0000266 &data, ssize_t_converter, &max_length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200267 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300268 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200269 return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
270
271exit:
272 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300273 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200274 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300275 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200276
277 return return_value;
278}
279
280PyDoc_STRVAR(zlib_Compress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800281"flush($self, mode=zlib.Z_FINISH, /)\n"
282"--\n"
283"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200284"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 \
Victor Stinner259f0e42017-01-17 01:35:17 +0100293 {"flush", (PyCFunction)zlib_Compress_flush, METH_FASTCALL, zlib_Compress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200294
295static PyObject *
296zlib_Compress_flush_impl(compobject *self, int mode);
297
298static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200299zlib_Compress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200300{
301 PyObject *return_value = NULL;
302 int mode = Z_FINISH;
303
Sylvain74453812017-06-10 06:51:48 +0200304 if (!_PyArg_ParseStack(args, nargs, "|i:flush",
305 &mode)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100306 goto exit;
307 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200308 return_value = zlib_Compress_flush_impl(self, mode);
309
310exit:
311 return return_value;
312}
313
Larry Hastings7726ac92014-01-31 22:03:12 -0800314#if defined(HAVE_ZLIB_COPY)
315
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200316PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800317"copy($self, /)\n"
318"--\n"
319"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200320"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
325static PyObject *
326zlib_Compress_copy_impl(compobject *self);
327
328static PyObject *
329zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
330{
331 return zlib_Compress_copy_impl(self);
332}
333
Larry Hastings7726ac92014-01-31 22:03:12 -0800334#endif /* defined(HAVE_ZLIB_COPY) */
335
Larry Hastings7726ac92014-01-31 22:03:12 -0800336#if defined(HAVE_ZLIB_COPY)
337
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600338PyDoc_STRVAR(zlib_Compress___copy____doc__,
339"__copy__($self, /)\n"
340"--\n"
341"\n");
342
343#define ZLIB_COMPRESS___COPY___METHODDEF \
344 {"__copy__", (PyCFunction)zlib_Compress___copy__, METH_NOARGS, zlib_Compress___copy____doc__},
345
346static PyObject *
347zlib_Compress___copy___impl(compobject *self);
348
349static PyObject *
350zlib_Compress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
351{
352 return zlib_Compress___copy___impl(self);
353}
354
355#endif /* defined(HAVE_ZLIB_COPY) */
356
357#if defined(HAVE_ZLIB_COPY)
358
359PyDoc_STRVAR(zlib_Compress___deepcopy____doc__,
360"__deepcopy__($self, memo, /)\n"
361"--\n"
362"\n");
363
364#define ZLIB_COMPRESS___DEEPCOPY___METHODDEF \
365 {"__deepcopy__", (PyCFunction)zlib_Compress___deepcopy__, METH_O, zlib_Compress___deepcopy____doc__},
366
367#endif /* defined(HAVE_ZLIB_COPY) */
368
369#if defined(HAVE_ZLIB_COPY)
370
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200371PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800372"copy($self, /)\n"
373"--\n"
374"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200375"Return a copy of the decompression object.");
376
377#define ZLIB_DECOMPRESS_COPY_METHODDEF \
378 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
379
380static PyObject *
381zlib_Decompress_copy_impl(compobject *self);
382
383static PyObject *
384zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
385{
386 return zlib_Decompress_copy_impl(self);
387}
388
Larry Hastings7726ac92014-01-31 22:03:12 -0800389#endif /* defined(HAVE_ZLIB_COPY) */
390
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600391#if defined(HAVE_ZLIB_COPY)
392
393PyDoc_STRVAR(zlib_Decompress___copy____doc__,
394"__copy__($self, /)\n"
395"--\n"
396"\n");
397
398#define ZLIB_DECOMPRESS___COPY___METHODDEF \
399 {"__copy__", (PyCFunction)zlib_Decompress___copy__, METH_NOARGS, zlib_Decompress___copy____doc__},
400
401static PyObject *
402zlib_Decompress___copy___impl(compobject *self);
403
404static PyObject *
405zlib_Decompress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
406{
407 return zlib_Decompress___copy___impl(self);
408}
409
410#endif /* defined(HAVE_ZLIB_COPY) */
411
412#if defined(HAVE_ZLIB_COPY)
413
414PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__,
415"__deepcopy__($self, memo, /)\n"
416"--\n"
417"\n");
418
419#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF \
420 {"__deepcopy__", (PyCFunction)zlib_Decompress___deepcopy__, METH_O, zlib_Decompress___deepcopy____doc__},
421
422#endif /* defined(HAVE_ZLIB_COPY) */
423
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200424PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800425"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
426"--\n"
427"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200428"Return a bytes object containing any remaining decompressed data.\n"
429"\n"
430" length\n"
431" the initial size of the output buffer.");
432
433#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100434 {"flush", (PyCFunction)zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200435
436static PyObject *
Martin Panter84544c12016-07-23 03:02:07 +0000437zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200438
439static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200440zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200441{
442 PyObject *return_value = NULL;
Martin Panter84544c12016-07-23 03:02:07 +0000443 Py_ssize_t length = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200444
Sylvain74453812017-06-10 06:51:48 +0200445 if (!_PyArg_ParseStack(args, nargs, "|O&:flush",
446 ssize_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100447 goto exit;
448 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200449 return_value = zlib_Decompress_flush_impl(self, length);
450
451exit:
452 return return_value;
453}
454
455PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800456"adler32($module, data, value=1, /)\n"
457"--\n"
458"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200459"Compute an Adler-32 checksum of data.\n"
460"\n"
461" value\n"
462" Starting value of the checksum.\n"
463"\n"
464"The returned checksum is an integer.");
465
466#define ZLIB_ADLER32_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100467 {"adler32", (PyCFunction)zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200468
469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300470zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200471
472static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200473zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200474{
475 PyObject *return_value = NULL;
476 Py_buffer data = {NULL, NULL};
477 unsigned int value = 1;
478
Sylvain74453812017-06-10 06:51:48 +0200479 if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32",
480 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100481 goto exit;
482 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200483 return_value = zlib_adler32_impl(module, &data, value);
484
485exit:
486 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300487 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200488 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300489 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200490
491 return return_value;
492}
493
494PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800495"crc32($module, data, value=0, /)\n"
496"--\n"
497"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200498"Compute a CRC-32 checksum of data.\n"
499"\n"
500" value\n"
501" Starting value of the checksum.\n"
502"\n"
503"The returned checksum is an integer.");
504
505#define ZLIB_CRC32_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100506 {"crc32", (PyCFunction)zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200507
508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300509zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200510
511static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200512zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200513{
514 PyObject *return_value = NULL;
515 Py_buffer data = {NULL, NULL};
516 unsigned int value = 0;
517
Sylvain74453812017-06-10 06:51:48 +0200518 if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32",
519 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100520 goto exit;
521 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200522 return_value = zlib_crc32_impl(module, &data, value);
523
524exit:
525 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300526 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200527 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200529
530 return return_value;
531}
Larry Hastings0759f842015-04-03 13:09:02 -0700532
533#ifndef ZLIB_COMPRESS_COPY_METHODDEF
534 #define ZLIB_COMPRESS_COPY_METHODDEF
535#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Tal Einat4f574092017-11-03 11:09:00 +0200536
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600537#ifndef ZLIB_COMPRESS___COPY___METHODDEF
538 #define ZLIB_COMPRESS___COPY___METHODDEF
539#endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */
540
541#ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF
542 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF
543#endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */
544
Tal Einat4f574092017-11-03 11:09:00 +0200545#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
546 #define ZLIB_DECOMPRESS_COPY_METHODDEF
547#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600548
549#ifndef ZLIB_DECOMPRESS___COPY___METHODDEF
550 #define ZLIB_DECOMPRESS___COPY___METHODDEF
551#endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */
552
553#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
554 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
555#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
556/*[clinic end generated code: output=d46c646770146ade input=a9049054013a1b77]*/