blob: 8e5f96aa143df6b0299ada0e1e4ad977b8438501 [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 Storchaka4a934d42018-11-27 11:27:36 +020017 {"compress", (PyCFunction)(void(*)(void))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 Storchaka4a934d42018-11-27 11:27:36 +020060 {"decompress", (PyCFunction)(void(*)(void))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 Storchaka4a934d42018-11-27 11:27:36 +0200122 {"compressobj", (PyCFunction)(void(*)(void))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 Storchaka4a934d42018-11-27 11:27:36 +0200169 {"decompressobj", (PyCFunction)(void(*)(void))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 Storchaka32d96a22018-12-25 13:23:47 +0200218 if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
219 goto exit;
220 }
221 if (!PyBuffer_IsContiguous(&data, 'C')) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200222 _PyArg_BadArgument("compress", 0, "contiguous buffer", arg);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200223 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300224 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200225 return_value = zlib_Compress_compress_impl(self, &data);
226
227exit:
228 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300229 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200230 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300231 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200232
233 return return_value;
234}
235
236PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300237"decompress($self, data, /, max_length=0)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800238"--\n"
239"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200240"Return a bytes object containing the decompressed version of the data.\n"
241"\n"
242" data\n"
243" The binary data to decompress.\n"
244" max_length\n"
245" The maximum allowable length of the decompressed data.\n"
246" Unconsumed input data will be stored in\n"
247" the unconsumed_tail attribute.\n"
248"\n"
249"After calling this function, some of the input data may still be stored in\n"
250"internal buffers for later processing.\n"
251"Call the flush() method to clear these buffers.");
252
253#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200254 {"decompress", (PyCFunction)(void(*)(void))zlib_Decompress_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200255
256static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400257zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
Martin Panter84544c12016-07-23 03:02:07 +0000258 Py_ssize_t max_length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200259
260static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200261zlib_Decompress_decompress(compobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200262{
263 PyObject *return_value = NULL;
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300264 static const char * const _keywords[] = {"", "max_length", NULL};
265 static _PyArg_Parser _parser = {"y*|O&:decompress", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200266 Py_buffer data = {NULL, NULL};
Martin Panter84544c12016-07-23 03:02:07 +0000267 Py_ssize_t max_length = 0;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200268
Victor Stinner3e1fad62017-01-17 01:29:01 +0100269 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Martin Panter525a9492016-07-23 03:39:49 +0000270 &data, ssize_t_converter, &max_length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200271 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300272 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200273 return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
274
275exit:
276 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300277 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200278 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300279 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200280
281 return return_value;
282}
283
284PyDoc_STRVAR(zlib_Compress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800285"flush($self, mode=zlib.Z_FINISH, /)\n"
286"--\n"
287"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200288"Return a bytes object containing any remaining compressed data.\n"
289"\n"
290" mode\n"
291" One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
292" If mode == Z_FINISH, the compressor object can no longer be\n"
293" used after calling the flush() method. Otherwise, more data\n"
294" can still be compressed.");
295
296#define ZLIB_COMPRESS_FLUSH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200297 {"flush", (PyCFunction)(void(*)(void))zlib_Compress_flush, METH_FASTCALL, zlib_Compress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200298
299static PyObject *
300zlib_Compress_flush_impl(compobject *self, int mode);
301
302static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200303zlib_Compress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200304{
305 PyObject *return_value = NULL;
306 int mode = Z_FINISH;
307
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200308 if (!_PyArg_CheckPositional("flush", nargs, 0, 1)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100309 goto exit;
310 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200311 if (nargs < 1) {
312 goto skip_optional;
313 }
314 if (PyFloat_Check(args[0])) {
315 PyErr_SetString(PyExc_TypeError,
316 "integer argument expected, got float" );
317 goto exit;
318 }
319 mode = _PyLong_AsInt(args[0]);
320 if (mode == -1 && PyErr_Occurred()) {
321 goto exit;
322 }
323skip_optional:
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200324 return_value = zlib_Compress_flush_impl(self, mode);
325
326exit:
327 return return_value;
328}
329
Larry Hastings7726ac92014-01-31 22:03:12 -0800330#if defined(HAVE_ZLIB_COPY)
331
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200332PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800333"copy($self, /)\n"
334"--\n"
335"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200336"Return a copy of the compression object.");
337
338#define ZLIB_COMPRESS_COPY_METHODDEF \
339 {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
340
341static PyObject *
342zlib_Compress_copy_impl(compobject *self);
343
344static PyObject *
345zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
346{
347 return zlib_Compress_copy_impl(self);
348}
349
Larry Hastings7726ac92014-01-31 22:03:12 -0800350#endif /* defined(HAVE_ZLIB_COPY) */
351
Larry Hastings7726ac92014-01-31 22:03:12 -0800352#if defined(HAVE_ZLIB_COPY)
353
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600354PyDoc_STRVAR(zlib_Compress___copy____doc__,
355"__copy__($self, /)\n"
356"--\n"
357"\n");
358
359#define ZLIB_COMPRESS___COPY___METHODDEF \
360 {"__copy__", (PyCFunction)zlib_Compress___copy__, METH_NOARGS, zlib_Compress___copy____doc__},
361
362static PyObject *
363zlib_Compress___copy___impl(compobject *self);
364
365static PyObject *
366zlib_Compress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
367{
368 return zlib_Compress___copy___impl(self);
369}
370
371#endif /* defined(HAVE_ZLIB_COPY) */
372
373#if defined(HAVE_ZLIB_COPY)
374
375PyDoc_STRVAR(zlib_Compress___deepcopy____doc__,
376"__deepcopy__($self, memo, /)\n"
377"--\n"
378"\n");
379
380#define ZLIB_COMPRESS___DEEPCOPY___METHODDEF \
381 {"__deepcopy__", (PyCFunction)zlib_Compress___deepcopy__, METH_O, zlib_Compress___deepcopy____doc__},
382
383#endif /* defined(HAVE_ZLIB_COPY) */
384
385#if defined(HAVE_ZLIB_COPY)
386
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200387PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800388"copy($self, /)\n"
389"--\n"
390"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200391"Return a copy of the decompression object.");
392
393#define ZLIB_DECOMPRESS_COPY_METHODDEF \
394 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
395
396static PyObject *
397zlib_Decompress_copy_impl(compobject *self);
398
399static PyObject *
400zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
401{
402 return zlib_Decompress_copy_impl(self);
403}
404
Larry Hastings7726ac92014-01-31 22:03:12 -0800405#endif /* defined(HAVE_ZLIB_COPY) */
406
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600407#if defined(HAVE_ZLIB_COPY)
408
409PyDoc_STRVAR(zlib_Decompress___copy____doc__,
410"__copy__($self, /)\n"
411"--\n"
412"\n");
413
414#define ZLIB_DECOMPRESS___COPY___METHODDEF \
415 {"__copy__", (PyCFunction)zlib_Decompress___copy__, METH_NOARGS, zlib_Decompress___copy____doc__},
416
417static PyObject *
418zlib_Decompress___copy___impl(compobject *self);
419
420static PyObject *
421zlib_Decompress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
422{
423 return zlib_Decompress___copy___impl(self);
424}
425
426#endif /* defined(HAVE_ZLIB_COPY) */
427
428#if defined(HAVE_ZLIB_COPY)
429
430PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__,
431"__deepcopy__($self, memo, /)\n"
432"--\n"
433"\n");
434
435#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF \
436 {"__deepcopy__", (PyCFunction)zlib_Decompress___deepcopy__, METH_O, zlib_Decompress___deepcopy____doc__},
437
438#endif /* defined(HAVE_ZLIB_COPY) */
439
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200440PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800441"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
442"--\n"
443"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200444"Return a bytes object containing any remaining decompressed data.\n"
445"\n"
446" length\n"
447" the initial size of the output buffer.");
448
449#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200450 {"flush", (PyCFunction)(void(*)(void))zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200451
452static PyObject *
Martin Panter84544c12016-07-23 03:02:07 +0000453zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200454
455static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200456zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200457{
458 PyObject *return_value = NULL;
Martin Panter84544c12016-07-23 03:02:07 +0000459 Py_ssize_t length = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200460
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200461 if (!_PyArg_CheckPositional("flush", nargs, 0, 1)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100462 goto exit;
463 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200464 if (nargs < 1) {
465 goto skip_optional;
466 }
467 if (!ssize_t_converter(args[0], &length)) {
468 goto exit;
469 }
470skip_optional:
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200471 return_value = zlib_Decompress_flush_impl(self, length);
472
473exit:
474 return return_value;
475}
476
477PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800478"adler32($module, data, value=1, /)\n"
479"--\n"
480"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200481"Compute an Adler-32 checksum of data.\n"
482"\n"
483" value\n"
484" Starting value of the checksum.\n"
485"\n"
486"The returned checksum is an integer.");
487
488#define ZLIB_ADLER32_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200489 {"adler32", (PyCFunction)(void(*)(void))zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200490
491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300492zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200493
494static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200495zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200496{
497 PyObject *return_value = NULL;
498 Py_buffer data = {NULL, NULL};
499 unsigned int value = 1;
500
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200501 if (!_PyArg_CheckPositional("adler32", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100502 goto exit;
503 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200504 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
505 goto exit;
506 }
507 if (!PyBuffer_IsContiguous(&data, 'C')) {
508 _PyArg_BadArgument("adler32", 1, "contiguous buffer", args[0]);
509 goto exit;
510 }
511 if (nargs < 2) {
512 goto skip_optional;
513 }
514 if (PyFloat_Check(args[1])) {
515 PyErr_SetString(PyExc_TypeError,
516 "integer argument expected, got float" );
517 goto exit;
518 }
519 value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
520 if (value == (unsigned int)-1 && PyErr_Occurred()) {
521 goto exit;
522 }
523skip_optional:
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200524 return_value = zlib_adler32_impl(module, &data, value);
525
526exit:
527 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200529 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300530 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200531
532 return return_value;
533}
534
535PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800536"crc32($module, data, value=0, /)\n"
537"--\n"
538"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200539"Compute a CRC-32 checksum of data.\n"
540"\n"
541" value\n"
542" Starting value of the checksum.\n"
543"\n"
544"The returned checksum is an integer.");
545
546#define ZLIB_CRC32_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200547 {"crc32", (PyCFunction)(void(*)(void))zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200548
549static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300550zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200551
552static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200553zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200554{
555 PyObject *return_value = NULL;
556 Py_buffer data = {NULL, NULL};
557 unsigned int value = 0;
558
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200559 if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100560 goto exit;
561 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200562 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
563 goto exit;
564 }
565 if (!PyBuffer_IsContiguous(&data, 'C')) {
566 _PyArg_BadArgument("crc32", 1, "contiguous buffer", args[0]);
567 goto exit;
568 }
569 if (nargs < 2) {
570 goto skip_optional;
571 }
572 if (PyFloat_Check(args[1])) {
573 PyErr_SetString(PyExc_TypeError,
574 "integer argument expected, got float" );
575 goto exit;
576 }
577 value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
578 if (value == (unsigned int)-1 && PyErr_Occurred()) {
579 goto exit;
580 }
581skip_optional:
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200582 return_value = zlib_crc32_impl(module, &data, value);
583
584exit:
585 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300586 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200587 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300588 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200589
590 return return_value;
591}
Larry Hastings0759f842015-04-03 13:09:02 -0700592
593#ifndef ZLIB_COMPRESS_COPY_METHODDEF
594 #define ZLIB_COMPRESS_COPY_METHODDEF
595#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Tal Einat4f574092017-11-03 11:09:00 +0200596
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600597#ifndef ZLIB_COMPRESS___COPY___METHODDEF
598 #define ZLIB_COMPRESS___COPY___METHODDEF
599#endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */
600
601#ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF
602 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF
603#endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */
604
Tal Einat4f574092017-11-03 11:09:00 +0200605#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
606 #define ZLIB_DECOMPRESS_COPY_METHODDEF
607#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600608
609#ifndef ZLIB_DECOMPRESS___COPY___METHODDEF
610 #define ZLIB_DECOMPRESS___COPY___METHODDEF
611#endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */
612
613#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
614 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
615#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200616/*[clinic end generated code: output=b3acec2384f18782 input=a9049054013a1b77]*/