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 | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 31 | if (!_PyArg_ParseStack(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 | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 76 | if (!_PyArg_ParseStack(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 | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 141 | if (!_PyArg_ParseStack(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 | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 183 | if (!_PyArg_ParseStack(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 | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 265 | if (!_PyArg_ParseStack(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 \ |
| 293 | {"flush", (PyCFunction)zlib_Compress_flush, METH_VARARGS, zlib_Compress_flush__doc__}, |
| 294 | |
| 295 | static PyObject * |
| 296 | zlib_Compress_flush_impl(compobject *self, int mode); |
| 297 | |
| 298 | static PyObject * |
| 299 | zlib_Compress_flush(compobject *self, PyObject *args) |
| 300 | { |
| 301 | PyObject *return_value = NULL; |
| 302 | int mode = Z_FINISH; |
| 303 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 304 | if (!PyArg_ParseTuple(args, "|i:flush", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 305 | &mode)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 306 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 307 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 308 | return_value = zlib_Compress_flush_impl(self, mode); |
| 309 | |
| 310 | exit: |
| 311 | return return_value; |
| 312 | } |
| 313 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 314 | #if defined(HAVE_ZLIB_COPY) |
| 315 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 316 | PyDoc_STRVAR(zlib_Compress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 317 | "copy($self, /)\n" |
| 318 | "--\n" |
| 319 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 320 | "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 | |
| 325 | static PyObject * |
| 326 | zlib_Compress_copy_impl(compobject *self); |
| 327 | |
| 328 | static PyObject * |
| 329 | zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 330 | { |
| 331 | return zlib_Compress_copy_impl(self); |
| 332 | } |
| 333 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 334 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 335 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 336 | #if defined(HAVE_ZLIB_COPY) |
| 337 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 338 | PyDoc_STRVAR(zlib_Decompress_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 339 | "copy($self, /)\n" |
| 340 | "--\n" |
| 341 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 342 | "Return a copy of the decompression object."); |
| 343 | |
| 344 | #define ZLIB_DECOMPRESS_COPY_METHODDEF \ |
| 345 | {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__}, |
| 346 | |
| 347 | static PyObject * |
| 348 | zlib_Decompress_copy_impl(compobject *self); |
| 349 | |
| 350 | static PyObject * |
| 351 | zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) |
| 352 | { |
| 353 | return zlib_Decompress_copy_impl(self); |
| 354 | } |
| 355 | |
Larry Hastings | 7726ac9 | 2014-01-31 22:03:12 -0800 | [diff] [blame] | 356 | #endif /* defined(HAVE_ZLIB_COPY) */ |
| 357 | |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 358 | PyDoc_STRVAR(zlib_Decompress_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 359 | "flush($self, length=zlib.DEF_BUF_SIZE, /)\n" |
| 360 | "--\n" |
| 361 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 362 | "Return a bytes object containing any remaining decompressed data.\n" |
| 363 | "\n" |
| 364 | " length\n" |
| 365 | " the initial size of the output buffer."); |
| 366 | |
| 367 | #define ZLIB_DECOMPRESS_FLUSH_METHODDEF \ |
| 368 | {"flush", (PyCFunction)zlib_Decompress_flush, METH_VARARGS, zlib_Decompress_flush__doc__}, |
| 369 | |
| 370 | static PyObject * |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 371 | zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 372 | |
| 373 | static PyObject * |
| 374 | zlib_Decompress_flush(compobject *self, PyObject *args) |
| 375 | { |
| 376 | PyObject *return_value = NULL; |
Martin Panter | 84544c1 | 2016-07-23 03:02:07 +0000 | [diff] [blame] | 377 | Py_ssize_t length = DEF_BUF_SIZE; |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 378 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 379 | if (!PyArg_ParseTuple(args, "|O&:flush", |
Martin Panter | 525a949 | 2016-07-23 03:39:49 +0000 | [diff] [blame] | 380 | ssize_t_converter, &length)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 381 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 382 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 383 | return_value = zlib_Decompress_flush_impl(self, length); |
| 384 | |
| 385 | exit: |
| 386 | return return_value; |
| 387 | } |
| 388 | |
| 389 | PyDoc_STRVAR(zlib_adler32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 390 | "adler32($module, data, value=1, /)\n" |
| 391 | "--\n" |
| 392 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 393 | "Compute an Adler-32 checksum of data.\n" |
| 394 | "\n" |
| 395 | " value\n" |
| 396 | " Starting value of the checksum.\n" |
| 397 | "\n" |
| 398 | "The returned checksum is an integer."); |
| 399 | |
| 400 | #define ZLIB_ADLER32_METHODDEF \ |
| 401 | {"adler32", (PyCFunction)zlib_adler32, METH_VARARGS, zlib_adler32__doc__}, |
| 402 | |
| 403 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 404 | zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 405 | |
| 406 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 407 | zlib_adler32(PyObject *module, PyObject *args) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 408 | { |
| 409 | PyObject *return_value = NULL; |
| 410 | Py_buffer data = {NULL, NULL}; |
| 411 | unsigned int value = 1; |
| 412 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 413 | if (!PyArg_ParseTuple(args, "y*|I:adler32", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 414 | &data, &value)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 415 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 416 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 417 | return_value = zlib_adler32_impl(module, &data, value); |
| 418 | |
| 419 | exit: |
| 420 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 421 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 422 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 423 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 424 | |
| 425 | return return_value; |
| 426 | } |
| 427 | |
| 428 | PyDoc_STRVAR(zlib_crc32__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 429 | "crc32($module, data, value=0, /)\n" |
| 430 | "--\n" |
| 431 | "\n" |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 432 | "Compute a CRC-32 checksum of data.\n" |
| 433 | "\n" |
| 434 | " value\n" |
| 435 | " Starting value of the checksum.\n" |
| 436 | "\n" |
| 437 | "The returned checksum is an integer."); |
| 438 | |
| 439 | #define ZLIB_CRC32_METHODDEF \ |
| 440 | {"crc32", (PyCFunction)zlib_crc32, METH_VARARGS, zlib_crc32__doc__}, |
| 441 | |
| 442 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 443 | zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 444 | |
| 445 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 446 | zlib_crc32(PyObject *module, PyObject *args) |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 447 | { |
| 448 | PyObject *return_value = NULL; |
| 449 | Py_buffer data = {NULL, NULL}; |
| 450 | unsigned int value = 0; |
| 451 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 452 | if (!PyArg_ParseTuple(args, "y*|I:crc32", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 453 | &data, &value)) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 454 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 455 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 456 | return_value = zlib_crc32_impl(module, &data, value); |
| 457 | |
| 458 | exit: |
| 459 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 460 | if (data.obj) { |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 461 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 462 | } |
Serhiy Storchaka | 2c5ddbe | 2014-01-27 00:03:31 +0200 | [diff] [blame] | 463 | |
| 464 | return return_value; |
| 465 | } |
Larry Hastings | 0759f84 | 2015-04-03 13:09:02 -0700 | [diff] [blame] | 466 | |
| 467 | #ifndef ZLIB_COMPRESS_COPY_METHODDEF |
| 468 | #define ZLIB_COMPRESS_COPY_METHODDEF |
| 469 | #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 470 | /*[clinic end generated code: output=3a4e2bfe750423a3 input=a9049054013a1b77]*/ |