blob: 87ad1ea00299af4586602e408650da9caba0f8e2 [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')) {
222 _PyArg_BadArgument("compress", "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
Sylvain74453812017-06-10 06:51:48 +0200308 if (!_PyArg_ParseStack(args, nargs, "|i:flush",
309 &mode)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100310 goto exit;
311 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200312 return_value = zlib_Compress_flush_impl(self, mode);
313
314exit:
315 return return_value;
316}
317
Larry Hastings7726ac92014-01-31 22:03:12 -0800318#if defined(HAVE_ZLIB_COPY)
319
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200320PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800321"copy($self, /)\n"
322"--\n"
323"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200324"Return a copy of the compression object.");
325
326#define ZLIB_COMPRESS_COPY_METHODDEF \
327 {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
328
329static PyObject *
330zlib_Compress_copy_impl(compobject *self);
331
332static PyObject *
333zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
334{
335 return zlib_Compress_copy_impl(self);
336}
337
Larry Hastings7726ac92014-01-31 22:03:12 -0800338#endif /* defined(HAVE_ZLIB_COPY) */
339
Larry Hastings7726ac92014-01-31 22:03:12 -0800340#if defined(HAVE_ZLIB_COPY)
341
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600342PyDoc_STRVAR(zlib_Compress___copy____doc__,
343"__copy__($self, /)\n"
344"--\n"
345"\n");
346
347#define ZLIB_COMPRESS___COPY___METHODDEF \
348 {"__copy__", (PyCFunction)zlib_Compress___copy__, METH_NOARGS, zlib_Compress___copy____doc__},
349
350static PyObject *
351zlib_Compress___copy___impl(compobject *self);
352
353static PyObject *
354zlib_Compress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
355{
356 return zlib_Compress___copy___impl(self);
357}
358
359#endif /* defined(HAVE_ZLIB_COPY) */
360
361#if defined(HAVE_ZLIB_COPY)
362
363PyDoc_STRVAR(zlib_Compress___deepcopy____doc__,
364"__deepcopy__($self, memo, /)\n"
365"--\n"
366"\n");
367
368#define ZLIB_COMPRESS___DEEPCOPY___METHODDEF \
369 {"__deepcopy__", (PyCFunction)zlib_Compress___deepcopy__, METH_O, zlib_Compress___deepcopy____doc__},
370
371#endif /* defined(HAVE_ZLIB_COPY) */
372
373#if defined(HAVE_ZLIB_COPY)
374
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200375PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800376"copy($self, /)\n"
377"--\n"
378"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200379"Return a copy of the decompression object.");
380
381#define ZLIB_DECOMPRESS_COPY_METHODDEF \
382 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
383
384static PyObject *
385zlib_Decompress_copy_impl(compobject *self);
386
387static PyObject *
388zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
389{
390 return zlib_Decompress_copy_impl(self);
391}
392
Larry Hastings7726ac92014-01-31 22:03:12 -0800393#endif /* defined(HAVE_ZLIB_COPY) */
394
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600395#if defined(HAVE_ZLIB_COPY)
396
397PyDoc_STRVAR(zlib_Decompress___copy____doc__,
398"__copy__($self, /)\n"
399"--\n"
400"\n");
401
402#define ZLIB_DECOMPRESS___COPY___METHODDEF \
403 {"__copy__", (PyCFunction)zlib_Decompress___copy__, METH_NOARGS, zlib_Decompress___copy____doc__},
404
405static PyObject *
406zlib_Decompress___copy___impl(compobject *self);
407
408static PyObject *
409zlib_Decompress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
410{
411 return zlib_Decompress___copy___impl(self);
412}
413
414#endif /* defined(HAVE_ZLIB_COPY) */
415
416#if defined(HAVE_ZLIB_COPY)
417
418PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__,
419"__deepcopy__($self, memo, /)\n"
420"--\n"
421"\n");
422
423#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF \
424 {"__deepcopy__", (PyCFunction)zlib_Decompress___deepcopy__, METH_O, zlib_Decompress___deepcopy____doc__},
425
426#endif /* defined(HAVE_ZLIB_COPY) */
427
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200428PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800429"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
430"--\n"
431"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200432"Return a bytes object containing any remaining decompressed data.\n"
433"\n"
434" length\n"
435" the initial size of the output buffer.");
436
437#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200438 {"flush", (PyCFunction)(void(*)(void))zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200439
440static PyObject *
Martin Panter84544c12016-07-23 03:02:07 +0000441zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200442
443static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200444zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200445{
446 PyObject *return_value = NULL;
Martin Panter84544c12016-07-23 03:02:07 +0000447 Py_ssize_t length = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200448
Sylvain74453812017-06-10 06:51:48 +0200449 if (!_PyArg_ParseStack(args, nargs, "|O&:flush",
450 ssize_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100451 goto exit;
452 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200453 return_value = zlib_Decompress_flush_impl(self, length);
454
455exit:
456 return return_value;
457}
458
459PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800460"adler32($module, data, value=1, /)\n"
461"--\n"
462"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200463"Compute an Adler-32 checksum of data.\n"
464"\n"
465" value\n"
466" Starting value of the checksum.\n"
467"\n"
468"The returned checksum is an integer.");
469
470#define ZLIB_ADLER32_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200471 {"adler32", (PyCFunction)(void(*)(void))zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200472
473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300474zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200475
476static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200477zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200478{
479 PyObject *return_value = NULL;
480 Py_buffer data = {NULL, NULL};
481 unsigned int value = 1;
482
Sylvain74453812017-06-10 06:51:48 +0200483 if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32",
484 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100485 goto exit;
486 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200487 return_value = zlib_adler32_impl(module, &data, value);
488
489exit:
490 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300491 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200492 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300493 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200494
495 return return_value;
496}
497
498PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800499"crc32($module, data, value=0, /)\n"
500"--\n"
501"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200502"Compute a CRC-32 checksum of data.\n"
503"\n"
504" value\n"
505" Starting value of the checksum.\n"
506"\n"
507"The returned checksum is an integer.");
508
509#define ZLIB_CRC32_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200510 {"crc32", (PyCFunction)(void(*)(void))zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200511
512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300513zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200514
515static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200516zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200517{
518 PyObject *return_value = NULL;
519 Py_buffer data = {NULL, NULL};
520 unsigned int value = 0;
521
Sylvain74453812017-06-10 06:51:48 +0200522 if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32",
523 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100524 goto exit;
525 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200526 return_value = zlib_crc32_impl(module, &data, value);
527
528exit:
529 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300530 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200531 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300532 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200533
534 return return_value;
535}
Larry Hastings0759f842015-04-03 13:09:02 -0700536
537#ifndef ZLIB_COMPRESS_COPY_METHODDEF
538 #define ZLIB_COMPRESS_COPY_METHODDEF
539#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Tal Einat4f574092017-11-03 11:09:00 +0200540
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600541#ifndef ZLIB_COMPRESS___COPY___METHODDEF
542 #define ZLIB_COMPRESS___COPY___METHODDEF
543#endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */
544
545#ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF
546 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF
547#endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */
548
Tal Einat4f574092017-11-03 11:09:00 +0200549#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
550 #define ZLIB_DECOMPRESS_COPY_METHODDEF
551#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
Zackery Spytzd2cbfff2018-06-27 12:04:51 -0600552
553#ifndef ZLIB_DECOMPRESS___COPY___METHODDEF
554 #define ZLIB_DECOMPRESS___COPY___METHODDEF
555#endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */
556
557#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
558 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
559#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200560/*[clinic end generated code: output=bea1e3c64573d9fd input=a9049054013a1b77]*/