Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(zlib_compress__doc__, |
Serhiy Storchaka | 95657cd | 2016-06-25 22:43:05 +0300 | [diff] [blame] | 6 | "compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 9 | "Returns a bytes object containing compressed data.\n" |
| 10 | "\n" |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 11 | " data\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 12 | " Binary data to be compressed.\n" |
| 13 | " level\n" |
Martin Panter | b0cb42d | 2016-02-10 10:45:54 +0000 | [diff] [blame] | 14 | " Compression level, in 0-9 or -1."); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 15 | |
| 16 | #define ZLIB_COMPRESS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 17 | {"compress", (PyCFunction)zlib_compress, METH_FASTCALL, zlib_compress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 20 | zlib_compress_impl(PyObject *module, Py_buffer *data, int level); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 21 | |
| 22 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 23 | zlib_compress(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 24 | { |
| 25 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 26 | static const char * const _keywords[] = {"", "level", NULL}; |
| 27 | static _PyArg_Parser _parser = {"y*|i:compress", _keywords, 0}; |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 28 | Py_buffer data = {NULL, NULL}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 29 | int level = Z_DEFAULT_COMPRESSION; |
| 30 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 31 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 32 | &data, &level)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 33 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 34 | } |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 35 | return_value = zlib_compress_impl(module, &data, level); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 36 | |
| 37 | exit: |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 38 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 39 | if (data.obj) { |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 40 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 41 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 42 | |
| 43 | return return_value; |
| 44 | } |
| 45 | |
| 46 | PyDoc_STRVAR(zlib_decompress__doc__, |
Serhiy Storchaka | 15f3228 | 2016-08-15 10:06:16 +0300 | [diff] [blame] | 47 | "decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 48 | "--\n" |
| 49 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 50 | "Returns a bytes object containing the uncompressed data.\n" |
| 51 | "\n" |
| 52 | " data\n" |
| 53 | " Compressed data.\n" |
| 54 | " wbits\n" |
Martin Panter | 0fdf41d | 2016-05-27 07:32:11 +0000 | [diff] [blame] | 55 | " The window buffer size and container format.\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 56 | " bufsize\n" |
| 57 | " The initial output buffer size."); |
| 58 | |
| 59 | #define ZLIB_DECOMPRESS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 60 | {"decompress", (PyCFunction)zlib_decompress, METH_FASTCALL, zlib_decompress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 61 | |
| 62 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 63 | zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits, |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 64 | Py_ssize_t bufsize); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 65 | |
| 66 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 67 | zlib_decompress(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 68 | { |
| 69 | PyObject *return_value = NULL; |
Serhiy Storchaka | 15f3228 | 2016-08-15 10:06:16 +0300 | [diff] [blame] | 70 | static const char * const _keywords[] = {"", "wbits", "bufsize", NULL}; |
| 71 | static _PyArg_Parser _parser = {"y*|iO&:decompress", _keywords, 0}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 72 | Py_buffer data = {NULL, NULL}; |
| 73 | int wbits = MAX_WBITS; |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 74 | Py_ssize_t bufsize = DEF_BUF_SIZE; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 75 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 76 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Martin Panter | 525a949 | 2016-07-23 03:39:49 +0000 | [diff] [blame] | 77 | &data, &wbits, ssize_t_converter, &bufsize)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 78 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 79 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 80 | return_value = zlib_decompress_impl(module, &data, wbits, bufsize); |
| 81 | |
| 82 | exit: |
| 83 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 84 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 85 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 86 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 87 | |
| 88 | return return_value; |
| 89 | } |
| 90 | |
| 91 | PyDoc_STRVAR(zlib_compressobj__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 92 | "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 Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 97 | "Return a compressor object.\n" |
| 98 | "\n" |
| 99 | " level\n" |
Martin Panter | 567d513 | 2016-02-03 07:06:33 +0000 | [diff] [blame] | 100 | " 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 Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 103 | " method\n" |
| 104 | " The compression algorithm. If given, this must be DEFLATED.\n" |
| 105 | " wbits\n" |
Martin Panter | 0fdf41d | 2016-05-27 07:32:11 +0000 | [diff] [blame] | 106 | " +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 Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 110 | " 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 \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 122 | {"compressobj", (PyCFunction)zlib_compressobj, METH_FASTCALL, zlib_compressobj__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 123 | |
| 124 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 125 | zlib_compressobj_impl(PyObject *module, int level, int method, int wbits, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 126 | int memLevel, int strategy, Py_buffer *zdict); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 127 | |
| 128 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 129 | zlib_compressobj(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 130 | { |
| 131 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 132 | static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL}; |
| 133 | static _PyArg_Parser _parser = {"|iiiiiy*:compressobj", _keywords, 0}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 134 | 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 Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 141 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 142 | &level, &method, &wbits, &memLevel, &strategy, &zdict)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 143 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 144 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 145 | return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict); |
| 146 | |
| 147 | exit: |
| 148 | /* Cleanup for zdict */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 149 | if (zdict.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 150 | PyBuffer_Release(&zdict); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 151 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 152 | |
| 153 | return return_value; |
| 154 | } |
| 155 | |
| 156 | PyDoc_STRVAR(zlib_decompressobj__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 157 | "decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n" |
| 158 | "--\n" |
| 159 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 160 | "Return a decompressor object.\n" |
| 161 | "\n" |
| 162 | " wbits\n" |
Martin Panter | 0fdf41d | 2016-05-27 07:32:11 +0000 | [diff] [blame] | 163 | " The window buffer size and container format.\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 164 | " 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 \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 169 | {"decompressobj", (PyCFunction)zlib_decompressobj, METH_FASTCALL, zlib_decompressobj__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 170 | |
| 171 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 172 | zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 173 | |
| 174 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 175 | zlib_decompressobj(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 176 | { |
| 177 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 178 | static const char * const _keywords[] = {"wbits", "zdict", NULL}; |
| 179 | static _PyArg_Parser _parser = {"|iO:decompressobj", _keywords, 0}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 180 | int wbits = MAX_WBITS; |
| 181 | PyObject *zdict = NULL; |
| 182 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 183 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 184 | &wbits, &zdict)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 185 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 186 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 187 | return_value = zlib_decompressobj_impl(module, wbits, zdict); |
| 188 | |
| 189 | exit: |
| 190 | return return_value; |
| 191 | } |
| 192 | |
| 193 | PyDoc_STRVAR(zlib_Compress_compress__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 194 | "compress($self, data, /)\n" |
| 195 | "--\n" |
| 196 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 197 | "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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 207 | {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 208 | |
| 209 | static PyObject * |
| 210 | zlib_Compress_compress_impl(compobject *self, Py_buffer *data); |
| 211 | |
| 212 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 213 | zlib_Compress_compress(compobject *self, PyObject *arg) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 214 | { |
| 215 | PyObject *return_value = NULL; |
| 216 | Py_buffer data = {NULL, NULL}; |
| 217 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 218 | if (!PyArg_Parse(arg, "y*:compress", &data)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 219 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 220 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 221 | return_value = zlib_Compress_compress_impl(self, &data); |
| 222 | |
| 223 | exit: |
| 224 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 225 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 226 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 227 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 228 | |
| 229 | return return_value; |
| 230 | } |
| 231 | |
| 232 | PyDoc_STRVAR(zlib_Decompress_decompress__doc__, |
Serhiy Storchaka | 15f3228 | 2016-08-15 10:06:16 +0300 | [diff] [blame] | 233 | "decompress($self, data, /, max_length=0)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 234 | "--\n" |
| 235 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 236 | "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 \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 250 | {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_FASTCALL, zlib_Decompress_decompress__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 251 | |
| 252 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 253 | zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 254 | Py_ssize_t max_length); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 255 | |
| 256 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 257 | zlib_Decompress_decompress(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 258 | { |
| 259 | PyObject *return_value = NULL; |
Serhiy Storchaka | 15f3228 | 2016-08-15 10:06:16 +0300 | [diff] [blame] | 260 | static const char * const _keywords[] = {"", "max_length", NULL}; |
| 261 | static _PyArg_Parser _parser = {"y*|O&:decompress", _keywords, 0}; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 262 | Py_buffer data = {NULL, NULL}; |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 263 | Py_ssize_t max_length = 0; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 264 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 265 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Martin Panter | 525a949 | 2016-07-23 03:39:49 +0000 | [diff] [blame] | 266 | &data, ssize_t_converter, &max_length)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 267 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 268 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 269 | return_value = zlib_Decompress_decompress_impl(self, &data, max_length); |
| 270 | |
| 271 | exit: |
| 272 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 273 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 274 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 275 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 276 | |
| 277 | return return_value; |
| 278 | } |
| 279 | |
| 280 | PyDoc_STRVAR(zlib_Compress_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 281 | "flush($self, mode=zlib.Z_FINISH, /)\n" |
| 282 | "--\n" |
| 283 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 284 | "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 Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 293 | {"flush", (PyCFunction)zlib_Compress_flush, METH_FASTCALL, zlib_Compress_flush__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 294 | |
| 295 | static PyObject * |
| 296 | zlib_Compress_flush_impl(compobject *self, int mode); |
| 297 | |
| 298 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 299 | zlib_Compress_flush(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 300 | { |
| 301 | PyObject *return_value = NULL; |
| 302 | int mode = Z_FINISH; |
| 303 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 304 | if (!_PyArg_NoStackKeywords("flush", kwnames)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 305 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 306 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 307 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 308 | if (!_PyArg_ParseStack(args, nargs, "|i:flush", |
| 309 | &mode)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 310 | goto exit; |
| 311 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 312 | return_value = zlib_Compress_flush_impl(self, mode); |
| 313 | |
| 314 | exit: |
| 315 | return return_value; |
| 316 | } |
| 317 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 318 | #if defined(HAVE_ZLIB_COPY) |
| 319 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 320 | PyDoc_STRVAR(zlib_Compress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 321 | "copy($self, /)\n" |
| 322 | "--\n" |
| 323 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 324 | "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 | |
| 329 | static PyObject * |
| 330 | zlib_Compress_copy_impl(compobject *self); |
| 331 | |
| 332 | static PyObject * |
| 333 | zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 334 | { |
| 335 | return zlib_Compress_copy_impl(self); |
| 336 | } |
| 337 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 338 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 339 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 340 | #if defined(HAVE_ZLIB_COPY) |
| 341 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 342 | PyDoc_STRVAR(zlib_Decompress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 343 | "copy($self, /)\n" |
| 344 | "--\n" |
| 345 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 346 | "Return a copy of the decompression object."); |
| 347 | |
| 348 | #define ZLIB_DECOMPRESS_COPY_METHODDEF \ |
| 349 | {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__}, |
| 350 | |
| 351 | static PyObject * |
| 352 | zlib_Decompress_copy_impl(compobject *self); |
| 353 | |
| 354 | static PyObject * |
| 355 | zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 356 | { |
| 357 | return zlib_Decompress_copy_impl(self); |
| 358 | } |
| 359 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 360 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 361 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 362 | PyDoc_STRVAR(zlib_Decompress_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 363 | "flush($self, length=zlib.DEF_BUF_SIZE, /)\n" |
| 364 | "--\n" |
| 365 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 366 | "Return a bytes object containing any remaining decompressed data.\n" |
| 367 | "\n" |
| 368 | " length\n" |
| 369 | " the initial size of the output buffer."); |
| 370 | |
| 371 | #define ZLIB_DECOMPRESS_FLUSH_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 372 | {"flush", (PyCFunction)zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 373 | |
| 374 | static PyObject * |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 375 | zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 376 | |
| 377 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 378 | zlib_Decompress_flush(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 379 | { |
| 380 | PyObject *return_value = NULL; |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 381 | Py_ssize_t length = DEF_BUF_SIZE; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 382 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 383 | if (!_PyArg_NoStackKeywords("flush", kwnames)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 384 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 385 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 386 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 387 | if (!_PyArg_ParseStack(args, nargs, "|O&:flush", |
| 388 | ssize_t_converter, &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 389 | goto exit; |
| 390 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 391 | return_value = zlib_Decompress_flush_impl(self, length); |
| 392 | |
| 393 | exit: |
| 394 | return return_value; |
| 395 | } |
| 396 | |
| 397 | PyDoc_STRVAR(zlib_adler32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 398 | "adler32($module, data, value=1, /)\n" |
| 399 | "--\n" |
| 400 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 401 | "Compute an Adler-32 checksum of data.\n" |
| 402 | "\n" |
| 403 | " value\n" |
| 404 | " Starting value of the checksum.\n" |
| 405 | "\n" |
| 406 | "The returned checksum is an integer."); |
| 407 | |
| 408 | #define ZLIB_ADLER32_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 409 | {"adler32", (PyCFunction)zlib_adler32, METH_FASTCALL, zlib_adler32__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 410 | |
| 411 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 412 | zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 413 | |
| 414 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 415 | zlib_adler32(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 416 | { |
| 417 | PyObject *return_value = NULL; |
| 418 | Py_buffer data = {NULL, NULL}; |
| 419 | unsigned int value = 1; |
| 420 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 421 | if (!_PyArg_NoStackKeywords("adler32", kwnames)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 422 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 423 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 424 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 425 | if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32", |
| 426 | &data, &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 427 | goto exit; |
| 428 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 429 | return_value = zlib_adler32_impl(module, &data, value); |
| 430 | |
| 431 | exit: |
| 432 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 433 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 434 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 435 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 436 | |
| 437 | return return_value; |
| 438 | } |
| 439 | |
| 440 | PyDoc_STRVAR(zlib_crc32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 441 | "crc32($module, data, value=0, /)\n" |
| 442 | "--\n" |
| 443 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 444 | "Compute a CRC-32 checksum of data.\n" |
| 445 | "\n" |
| 446 | " value\n" |
| 447 | " Starting value of the checksum.\n" |
| 448 | "\n" |
| 449 | "The returned checksum is an integer."); |
| 450 | |
| 451 | #define ZLIB_CRC32_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 452 | {"crc32", (PyCFunction)zlib_crc32, METH_FASTCALL, zlib_crc32__doc__}, |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 453 | |
| 454 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 455 | zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 456 | |
| 457 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 458 | zlib_crc32(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 459 | { |
| 460 | PyObject *return_value = NULL; |
| 461 | Py_buffer data = {NULL, NULL}; |
| 462 | unsigned int value = 0; |
| 463 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 464 | if (!_PyArg_NoStackKeywords("crc32", kwnames)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 465 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 466 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 467 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 468 | if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32", |
| 469 | &data, &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 470 | goto exit; |
| 471 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 472 | return_value = zlib_crc32_impl(module, &data, value); |
| 473 | |
| 474 | exit: |
| 475 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 476 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 477 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 478 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 479 | |
| 480 | return return_value; |
| 481 | } |
Larry Hastings | 0759f84 | 2015-04-03 13:09:02 -0700 | [diff] [blame] | 482 | |
| 483 | #ifndef ZLIB_COMPRESS_COPY_METHODDEF |
| 484 | #define ZLIB_COMPRESS_COPY_METHODDEF |
| 485 | #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 486 | /*[clinic end generated code: output=c7abf02e091bcad3 input=a9049054013a1b77]*/ |