| 1 |
/*[clinic input] |
| 2 |
preserve |
| 3 |
[clinic start generated code]*/ |
| 4 |
|
| 5 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 6 |
# include "pycore_gc.h" // PyGC_Head |
| 7 |
# include "pycore_runtime.h" // _Py_ID() |
| 8 |
#endif |
| 9 |
#include "pycore_abstract.h" // _PyNumber_Index() |
| 10 |
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
| 11 |
|
| 12 |
PyDoc_STRVAR(zlib_compress__doc__, |
| 13 |
"compress($module, data, /, level=Z_DEFAULT_COMPRESSION, wbits=MAX_WBITS)\n" |
| 14 |
"--\n" |
| 15 |
"\n" |
| 16 |
"Returns a bytes object containing compressed data.\n" |
| 17 |
"\n" |
| 18 |
" data\n" |
| 19 |
" Binary data to be compressed.\n" |
| 20 |
" level\n" |
| 21 |
" Compression level, in 0-9 or -1.\n" |
| 22 |
" wbits\n" |
| 23 |
" The window buffer size and container format."); |
| 24 |
|
| 25 |
#define ZLIB_COMPRESS_METHODDEF \ |
| 26 |
{"compress", _PyCFunction_CAST(zlib_compress), METH_FASTCALL|METH_KEYWORDS, zlib_compress__doc__}, |
| 27 |
|
| 28 |
static PyObject * |
| 29 |
zlib_compress_impl(PyObject *module, Py_buffer *data, int level, int wbits); |
| 30 |
|
| 31 |
static PyObject * |
| 32 |
zlib_compress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 33 |
{ |
| 34 |
PyObject *return_value = NULL; |
| 35 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 36 |
|
| 37 |
#define NUM_KEYWORDS 2 |
| 38 |
static struct { |
| 39 |
PyGC_Head _this_is_not_used; |
| 40 |
PyObject_VAR_HEAD |
| 41 |
Py_hash_t ob_hash; |
| 42 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 43 |
} _kwtuple = { |
| 44 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 45 |
.ob_hash = -1, |
| 46 |
.ob_item = { &_Py_ID(level), &_Py_ID(wbits), }, |
| 47 |
}; |
| 48 |
#undef NUM_KEYWORDS |
| 49 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 50 |
|
| 51 |
#else // !Py_BUILD_CORE |
| 52 |
# define KWTUPLE NULL |
| 53 |
#endif // !Py_BUILD_CORE |
| 54 |
|
| 55 |
static const char * const _keywords[] = {"", "level", "wbits", NULL}; |
| 56 |
static _PyArg_Parser _parser = { |
| 57 |
.keywords = _keywords, |
| 58 |
.fname = "compress", |
| 59 |
.kwtuple = KWTUPLE, |
| 60 |
}; |
| 61 |
#undef KWTUPLE |
| 62 |
PyObject *argsbuf[3]; |
| 63 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 64 |
Py_buffer data = {NULL, NULL}; |
| 65 |
int level = Z_DEFAULT_COMPRESSION; |
| 66 |
int wbits = MAX_WBITS; |
| 67 |
|
| 68 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 69 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 70 |
if (!args) { |
| 71 |
goto exit; |
| 72 |
} |
| 73 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 74 |
goto exit; |
| 75 |
} |
| 76 |
if (!noptargs) { |
| 77 |
goto skip_optional_pos; |
| 78 |
} |
| 79 |
if (args[1]) { |
| 80 |
level = PyLong_AsInt(args[1]); |
| 81 |
if (level == -1 && PyErr_Occurred()) { |
| 82 |
goto exit; |
| 83 |
} |
| 84 |
if (!--noptargs) { |
| 85 |
goto skip_optional_pos; |
| 86 |
} |
| 87 |
} |
| 88 |
wbits = PyLong_AsInt(args[2]); |
| 89 |
if (wbits == -1 && PyErr_Occurred()) { |
| 90 |
goto exit; |
| 91 |
} |
| 92 |
skip_optional_pos: |
| 93 |
return_value = zlib_compress_impl(module, &data, level, wbits); |
| 94 |
|
| 95 |
exit: |
| 96 |
/* Cleanup for data */ |
| 97 |
if (data.obj) { |
| 98 |
PyBuffer_Release(&data); |
| 99 |
} |
| 100 |
|
| 101 |
return return_value; |
| 102 |
} |
| 103 |
|
| 104 |
PyDoc_STRVAR(zlib_decompress__doc__, |
| 105 |
"decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n" |
| 106 |
"--\n" |
| 107 |
"\n" |
| 108 |
"Returns a bytes object containing the uncompressed data.\n" |
| 109 |
"\n" |
| 110 |
" data\n" |
| 111 |
" Compressed data.\n" |
| 112 |
" wbits\n" |
| 113 |
" The window buffer size and container format.\n" |
| 114 |
" bufsize\n" |
| 115 |
" The initial output buffer size."); |
| 116 |
|
| 117 |
#define ZLIB_DECOMPRESS_METHODDEF \ |
| 118 |
{"decompress", _PyCFunction_CAST(zlib_decompress), METH_FASTCALL|METH_KEYWORDS, zlib_decompress__doc__}, |
| 119 |
|
| 120 |
static PyObject * |
| 121 |
zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits, |
| 122 |
Py_ssize_t bufsize); |
| 123 |
|
| 124 |
static PyObject * |
| 125 |
zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 126 |
{ |
| 127 |
PyObject *return_value = NULL; |
| 128 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 129 |
|
| 130 |
#define NUM_KEYWORDS 2 |
| 131 |
static struct { |
| 132 |
PyGC_Head _this_is_not_used; |
| 133 |
PyObject_VAR_HEAD |
| 134 |
Py_hash_t ob_hash; |
| 135 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 136 |
} _kwtuple = { |
| 137 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 138 |
.ob_hash = -1, |
| 139 |
.ob_item = { &_Py_ID(wbits), &_Py_ID(bufsize), }, |
| 140 |
}; |
| 141 |
#undef NUM_KEYWORDS |
| 142 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 143 |
|
| 144 |
#else // !Py_BUILD_CORE |
| 145 |
# define KWTUPLE NULL |
| 146 |
#endif // !Py_BUILD_CORE |
| 147 |
|
| 148 |
static const char * const _keywords[] = {"", "wbits", "bufsize", NULL}; |
| 149 |
static _PyArg_Parser _parser = { |
| 150 |
.keywords = _keywords, |
| 151 |
.fname = "decompress", |
| 152 |
.kwtuple = KWTUPLE, |
| 153 |
}; |
| 154 |
#undef KWTUPLE |
| 155 |
PyObject *argsbuf[3]; |
| 156 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 157 |
Py_buffer data = {NULL, NULL}; |
| 158 |
int wbits = MAX_WBITS; |
| 159 |
Py_ssize_t bufsize = DEF_BUF_SIZE; |
| 160 |
|
| 161 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 162 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 163 |
if (!args) { |
| 164 |
goto exit; |
| 165 |
} |
| 166 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 167 |
goto exit; |
| 168 |
} |
| 169 |
if (!noptargs) { |
| 170 |
goto skip_optional_pos; |
| 171 |
} |
| 172 |
if (args[1]) { |
| 173 |
wbits = PyLong_AsInt(args[1]); |
| 174 |
if (wbits == -1 && PyErr_Occurred()) { |
| 175 |
goto exit; |
| 176 |
} |
| 177 |
if (!--noptargs) { |
| 178 |
goto skip_optional_pos; |
| 179 |
} |
| 180 |
} |
| 181 |
{ |
| 182 |
Py_ssize_t ival = -1; |
| 183 |
PyObject *iobj = _PyNumber_Index(args[2]); |
| 184 |
if (iobj != NULL) { |
| 185 |
ival = PyLong_AsSsize_t(iobj); |
| 186 |
Py_DECREF(iobj); |
| 187 |
} |
| 188 |
if (ival == -1 && PyErr_Occurred()) { |
| 189 |
goto exit; |
| 190 |
} |
| 191 |
bufsize = ival; |
| 192 |
} |
| 193 |
skip_optional_pos: |
| 194 |
return_value = zlib_decompress_impl(module, &data, wbits, bufsize); |
| 195 |
|
| 196 |
exit: |
| 197 |
/* Cleanup for data */ |
| 198 |
if (data.obj) { |
| 199 |
PyBuffer_Release(&data); |
| 200 |
} |
| 201 |
|
| 202 |
return return_value; |
| 203 |
} |
| 204 |
|
| 205 |
PyDoc_STRVAR(zlib_compressobj__doc__, |
| 206 |
"compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n" |
| 207 |
" wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n" |
| 208 |
" strategy=Z_DEFAULT_STRATEGY, zdict=<unrepresentable>)\n" |
| 209 |
"--\n" |
| 210 |
"\n" |
| 211 |
"Return a compressor object.\n" |
| 212 |
"\n" |
| 213 |
" level\n" |
| 214 |
" The compression level (an integer in the range 0-9 or -1; default is\n" |
| 215 |
" currently equivalent to 6). Higher compression levels are slower,\n" |
| 216 |
" but produce smaller results.\n" |
| 217 |
" method\n" |
| 218 |
" The compression algorithm. If given, this must be DEFLATED.\n" |
| 219 |
" wbits\n" |
| 220 |
" +9 to +15: The base-two logarithm of the window size. Include a zlib\n" |
| 221 |
" container.\n" |
| 222 |
" -9 to -15: Generate a raw stream.\n" |
| 223 |
" +25 to +31: Include a gzip container.\n" |
| 224 |
" memLevel\n" |
| 225 |
" Controls the amount of memory used for internal compression state.\n" |
| 226 |
" Valid values range from 1 to 9. Higher values result in higher memory\n" |
| 227 |
" usage, faster compression, and smaller output.\n" |
| 228 |
" strategy\n" |
| 229 |
" Used to tune the compression algorithm. Possible values are\n" |
| 230 |
" Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n" |
| 231 |
" zdict\n" |
| 232 |
" The predefined compression dictionary - a sequence of bytes\n" |
| 233 |
" containing subsequences that are likely to occur in the input data."); |
| 234 |
|
| 235 |
#define ZLIB_COMPRESSOBJ_METHODDEF \ |
| 236 |
{"compressobj", _PyCFunction_CAST(zlib_compressobj), METH_FASTCALL|METH_KEYWORDS, zlib_compressobj__doc__}, |
| 237 |
|
| 238 |
static PyObject * |
| 239 |
zlib_compressobj_impl(PyObject *module, int level, int method, int wbits, |
| 240 |
int memLevel, int strategy, Py_buffer *zdict); |
| 241 |
|
| 242 |
static PyObject * |
| 243 |
zlib_compressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 244 |
{ |
| 245 |
PyObject *return_value = NULL; |
| 246 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 247 |
|
| 248 |
#define NUM_KEYWORDS 6 |
| 249 |
static struct { |
| 250 |
PyGC_Head _this_is_not_used; |
| 251 |
PyObject_VAR_HEAD |
| 252 |
Py_hash_t ob_hash; |
| 253 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 254 |
} _kwtuple = { |
| 255 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 256 |
.ob_hash = -1, |
| 257 |
.ob_item = { &_Py_ID(level), &_Py_ID(method), &_Py_ID(wbits), &_Py_ID(memLevel), &_Py_ID(strategy), &_Py_ID(zdict), }, |
| 258 |
}; |
| 259 |
#undef NUM_KEYWORDS |
| 260 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 261 |
|
| 262 |
#else // !Py_BUILD_CORE |
| 263 |
# define KWTUPLE NULL |
| 264 |
#endif // !Py_BUILD_CORE |
| 265 |
|
| 266 |
static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL}; |
| 267 |
static _PyArg_Parser _parser = { |
| 268 |
.keywords = _keywords, |
| 269 |
.fname = "compressobj", |
| 270 |
.kwtuple = KWTUPLE, |
| 271 |
}; |
| 272 |
#undef KWTUPLE |
| 273 |
PyObject *argsbuf[6]; |
| 274 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 275 |
int level = Z_DEFAULT_COMPRESSION; |
| 276 |
int method = DEFLATED; |
| 277 |
int wbits = MAX_WBITS; |
| 278 |
int memLevel = DEF_MEM_LEVEL; |
| 279 |
int strategy = Z_DEFAULT_STRATEGY; |
| 280 |
Py_buffer zdict = {NULL, NULL}; |
| 281 |
|
| 282 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 283 |
/*minpos*/ 0, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 284 |
if (!args) { |
| 285 |
goto exit; |
| 286 |
} |
| 287 |
if (!noptargs) { |
| 288 |
goto skip_optional_pos; |
| 289 |
} |
| 290 |
if (args[0]) { |
| 291 |
level = PyLong_AsInt(args[0]); |
| 292 |
if (level == -1 && PyErr_Occurred()) { |
| 293 |
goto exit; |
| 294 |
} |
| 295 |
if (!--noptargs) { |
| 296 |
goto skip_optional_pos; |
| 297 |
} |
| 298 |
} |
| 299 |
if (args[1]) { |
| 300 |
method = PyLong_AsInt(args[1]); |
| 301 |
if (method == -1 && PyErr_Occurred()) { |
| 302 |
goto exit; |
| 303 |
} |
| 304 |
if (!--noptargs) { |
| 305 |
goto skip_optional_pos; |
| 306 |
} |
| 307 |
} |
| 308 |
if (args[2]) { |
| 309 |
wbits = PyLong_AsInt(args[2]); |
| 310 |
if (wbits == -1 && PyErr_Occurred()) { |
| 311 |
goto exit; |
| 312 |
} |
| 313 |
if (!--noptargs) { |
| 314 |
goto skip_optional_pos; |
| 315 |
} |
| 316 |
} |
| 317 |
if (args[3]) { |
| 318 |
memLevel = PyLong_AsInt(args[3]); |
| 319 |
if (memLevel == -1 && PyErr_Occurred()) { |
| 320 |
goto exit; |
| 321 |
} |
| 322 |
if (!--noptargs) { |
| 323 |
goto skip_optional_pos; |
| 324 |
} |
| 325 |
} |
| 326 |
if (args[4]) { |
| 327 |
strategy = PyLong_AsInt(args[4]); |
| 328 |
if (strategy == -1 && PyErr_Occurred()) { |
| 329 |
goto exit; |
| 330 |
} |
| 331 |
if (!--noptargs) { |
| 332 |
goto skip_optional_pos; |
| 333 |
} |
| 334 |
} |
| 335 |
if (PyObject_GetBuffer(args[5], &zdict, PyBUF_SIMPLE) != 0) { |
| 336 |
goto exit; |
| 337 |
} |
| 338 |
skip_optional_pos: |
| 339 |
return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict); |
| 340 |
|
| 341 |
exit: |
| 342 |
/* Cleanup for zdict */ |
| 343 |
if (zdict.obj) { |
| 344 |
PyBuffer_Release(&zdict); |
| 345 |
} |
| 346 |
|
| 347 |
return return_value; |
| 348 |
} |
| 349 |
|
| 350 |
PyDoc_STRVAR(zlib_decompressobj__doc__, |
| 351 |
"decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n" |
| 352 |
"--\n" |
| 353 |
"\n" |
| 354 |
"Return a decompressor object.\n" |
| 355 |
"\n" |
| 356 |
" wbits\n" |
| 357 |
" The window buffer size and container format.\n" |
| 358 |
" zdict\n" |
| 359 |
" The predefined compression dictionary. This must be the same\n" |
| 360 |
" dictionary as used by the compressor that produced the input data."); |
| 361 |
|
| 362 |
#define ZLIB_DECOMPRESSOBJ_METHODDEF \ |
| 363 |
{"decompressobj", _PyCFunction_CAST(zlib_decompressobj), METH_FASTCALL|METH_KEYWORDS, zlib_decompressobj__doc__}, |
| 364 |
|
| 365 |
static PyObject * |
| 366 |
zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict); |
| 367 |
|
| 368 |
static PyObject * |
| 369 |
zlib_decompressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 370 |
{ |
| 371 |
PyObject *return_value = NULL; |
| 372 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 373 |
|
| 374 |
#define NUM_KEYWORDS 2 |
| 375 |
static struct { |
| 376 |
PyGC_Head _this_is_not_used; |
| 377 |
PyObject_VAR_HEAD |
| 378 |
Py_hash_t ob_hash; |
| 379 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 380 |
} _kwtuple = { |
| 381 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 382 |
.ob_hash = -1, |
| 383 |
.ob_item = { &_Py_ID(wbits), &_Py_ID(zdict), }, |
| 384 |
}; |
| 385 |
#undef NUM_KEYWORDS |
| 386 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 387 |
|
| 388 |
#else // !Py_BUILD_CORE |
| 389 |
# define KWTUPLE NULL |
| 390 |
#endif // !Py_BUILD_CORE |
| 391 |
|
| 392 |
static const char * const _keywords[] = {"wbits", "zdict", NULL}; |
| 393 |
static _PyArg_Parser _parser = { |
| 394 |
.keywords = _keywords, |
| 395 |
.fname = "decompressobj", |
| 396 |
.kwtuple = KWTUPLE, |
| 397 |
}; |
| 398 |
#undef KWTUPLE |
| 399 |
PyObject *argsbuf[2]; |
| 400 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 401 |
int wbits = MAX_WBITS; |
| 402 |
PyObject *zdict = NULL; |
| 403 |
|
| 404 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 405 |
/*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 406 |
if (!args) { |
| 407 |
goto exit; |
| 408 |
} |
| 409 |
if (!noptargs) { |
| 410 |
goto skip_optional_pos; |
| 411 |
} |
| 412 |
if (args[0]) { |
| 413 |
wbits = PyLong_AsInt(args[0]); |
| 414 |
if (wbits == -1 && PyErr_Occurred()) { |
| 415 |
goto exit; |
| 416 |
} |
| 417 |
if (!--noptargs) { |
| 418 |
goto skip_optional_pos; |
| 419 |
} |
| 420 |
} |
| 421 |
zdict = args[1]; |
| 422 |
skip_optional_pos: |
| 423 |
return_value = zlib_decompressobj_impl(module, wbits, zdict); |
| 424 |
|
| 425 |
exit: |
| 426 |
return return_value; |
| 427 |
} |
| 428 |
|
| 429 |
PyDoc_STRVAR(zlib_Compress_compress__doc__, |
| 430 |
"compress($self, data, /)\n" |
| 431 |
"--\n" |
| 432 |
"\n" |
| 433 |
"Returns a bytes object containing compressed data.\n" |
| 434 |
"\n" |
| 435 |
" data\n" |
| 436 |
" Binary data to be compressed.\n" |
| 437 |
"\n" |
| 438 |
"After calling this function, some of the input data may still\n" |
| 439 |
"be stored in internal buffers for later processing.\n" |
| 440 |
"Call the flush() method to clear these buffers."); |
| 441 |
|
| 442 |
#define ZLIB_COMPRESS_COMPRESS_METHODDEF \ |
| 443 |
{"compress", _PyCFunction_CAST(zlib_Compress_compress), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_compress__doc__}, |
| 444 |
|
| 445 |
static PyObject * |
| 446 |
zlib_Compress_compress_impl(compobject *self, PyTypeObject *cls, |
| 447 |
Py_buffer *data); |
| 448 |
|
| 449 |
static PyObject * |
| 450 |
zlib_Compress_compress(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 451 |
{ |
| 452 |
PyObject *return_value = NULL; |
| 453 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 454 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 455 |
#else |
| 456 |
# define KWTUPLE NULL |
| 457 |
#endif |
| 458 |
|
| 459 |
static const char * const _keywords[] = {"", NULL}; |
| 460 |
static _PyArg_Parser _parser = { |
| 461 |
.keywords = _keywords, |
| 462 |
.fname = "compress", |
| 463 |
.kwtuple = KWTUPLE, |
| 464 |
}; |
| 465 |
#undef KWTUPLE |
| 466 |
PyObject *argsbuf[1]; |
| 467 |
Py_buffer data = {NULL, NULL}; |
| 468 |
|
| 469 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 470 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 471 |
if (!args) { |
| 472 |
goto exit; |
| 473 |
} |
| 474 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 475 |
goto exit; |
| 476 |
} |
| 477 |
return_value = zlib_Compress_compress_impl((compobject *)self, cls, &data); |
| 478 |
|
| 479 |
exit: |
| 480 |
/* Cleanup for data */ |
| 481 |
if (data.obj) { |
| 482 |
PyBuffer_Release(&data); |
| 483 |
} |
| 484 |
|
| 485 |
return return_value; |
| 486 |
} |
| 487 |
|
| 488 |
PyDoc_STRVAR(zlib_Decompress_decompress__doc__, |
| 489 |
"decompress($self, data, /, max_length=0)\n" |
| 490 |
"--\n" |
| 491 |
"\n" |
| 492 |
"Return a bytes object containing the decompressed version of the data.\n" |
| 493 |
"\n" |
| 494 |
" data\n" |
| 495 |
" The binary data to decompress.\n" |
| 496 |
" max_length\n" |
| 497 |
" The maximum allowable length of the decompressed data.\n" |
| 498 |
" Unconsumed input data will be stored in\n" |
| 499 |
" the unconsumed_tail attribute.\n" |
| 500 |
"\n" |
| 501 |
"After calling this function, some of the input data may still be\n" |
| 502 |
"stored in internal buffers for later processing.\n" |
| 503 |
"Call the flush() method to clear these buffers."); |
| 504 |
|
| 505 |
#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \ |
| 506 |
{"decompress", _PyCFunction_CAST(zlib_Decompress_decompress), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__}, |
| 507 |
|
| 508 |
static PyObject * |
| 509 |
zlib_Decompress_decompress_impl(compobject *self, PyTypeObject *cls, |
| 510 |
Py_buffer *data, Py_ssize_t max_length); |
| 511 |
|
| 512 |
static PyObject * |
| 513 |
zlib_Decompress_decompress(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 514 |
{ |
| 515 |
PyObject *return_value = NULL; |
| 516 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 517 |
|
| 518 |
#define NUM_KEYWORDS 1 |
| 519 |
static struct { |
| 520 |
PyGC_Head _this_is_not_used; |
| 521 |
PyObject_VAR_HEAD |
| 522 |
Py_hash_t ob_hash; |
| 523 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 524 |
} _kwtuple = { |
| 525 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 526 |
.ob_hash = -1, |
| 527 |
.ob_item = { &_Py_ID(max_length), }, |
| 528 |
}; |
| 529 |
#undef NUM_KEYWORDS |
| 530 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 531 |
|
| 532 |
#else // !Py_BUILD_CORE |
| 533 |
# define KWTUPLE NULL |
| 534 |
#endif // !Py_BUILD_CORE |
| 535 |
|
| 536 |
static const char * const _keywords[] = {"", "max_length", NULL}; |
| 537 |
static _PyArg_Parser _parser = { |
| 538 |
.keywords = _keywords, |
| 539 |
.fname = "decompress", |
| 540 |
.kwtuple = KWTUPLE, |
| 541 |
}; |
| 542 |
#undef KWTUPLE |
| 543 |
PyObject *argsbuf[2]; |
| 544 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 545 |
Py_buffer data = {NULL, NULL}; |
| 546 |
Py_ssize_t max_length = 0; |
| 547 |
|
| 548 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 549 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 550 |
if (!args) { |
| 551 |
goto exit; |
| 552 |
} |
| 553 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 554 |
goto exit; |
| 555 |
} |
| 556 |
if (!noptargs) { |
| 557 |
goto skip_optional_pos; |
| 558 |
} |
| 559 |
{ |
| 560 |
Py_ssize_t ival = -1; |
| 561 |
PyObject *iobj = _PyNumber_Index(args[1]); |
| 562 |
if (iobj != NULL) { |
| 563 |
ival = PyLong_AsSsize_t(iobj); |
| 564 |
Py_DECREF(iobj); |
| 565 |
} |
| 566 |
if (ival == -1 && PyErr_Occurred()) { |
| 567 |
goto exit; |
| 568 |
} |
| 569 |
max_length = ival; |
| 570 |
} |
| 571 |
skip_optional_pos: |
| 572 |
return_value = zlib_Decompress_decompress_impl((compobject *)self, cls, &data, max_length); |
| 573 |
|
| 574 |
exit: |
| 575 |
/* Cleanup for data */ |
| 576 |
if (data.obj) { |
| 577 |
PyBuffer_Release(&data); |
| 578 |
} |
| 579 |
|
| 580 |
return return_value; |
| 581 |
} |
| 582 |
|
| 583 |
PyDoc_STRVAR(zlib_Compress_flush__doc__, |
| 584 |
"flush($self, mode=zlib.Z_FINISH, /)\n" |
| 585 |
"--\n" |
| 586 |
"\n" |
| 587 |
"Return a bytes object containing any remaining compressed data.\n" |
| 588 |
"\n" |
| 589 |
" mode\n" |
| 590 |
" One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n" |
| 591 |
" If mode == Z_FINISH, the compressor object can no longer be\n" |
| 592 |
" used after calling the flush() method. Otherwise, more data\n" |
| 593 |
" can still be compressed."); |
| 594 |
|
| 595 |
#define ZLIB_COMPRESS_FLUSH_METHODDEF \ |
| 596 |
{"flush", _PyCFunction_CAST(zlib_Compress_flush), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_flush__doc__}, |
| 597 |
|
| 598 |
static PyObject * |
| 599 |
zlib_Compress_flush_impl(compobject *self, PyTypeObject *cls, int mode); |
| 600 |
|
| 601 |
static PyObject * |
| 602 |
zlib_Compress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 603 |
{ |
| 604 |
PyObject *return_value = NULL; |
| 605 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 606 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 607 |
#else |
| 608 |
# define KWTUPLE NULL |
| 609 |
#endif |
| 610 |
|
| 611 |
static const char * const _keywords[] = {"", NULL}; |
| 612 |
static _PyArg_Parser _parser = { |
| 613 |
.keywords = _keywords, |
| 614 |
.fname = "flush", |
| 615 |
.kwtuple = KWTUPLE, |
| 616 |
}; |
| 617 |
#undef KWTUPLE |
| 618 |
PyObject *argsbuf[1]; |
| 619 |
int mode = Z_FINISH; |
| 620 |
|
| 621 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 622 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 623 |
if (!args) { |
| 624 |
goto exit; |
| 625 |
} |
| 626 |
if (nargs < 1) { |
| 627 |
goto skip_optional_posonly; |
| 628 |
} |
| 629 |
mode = PyLong_AsInt(args[0]); |
| 630 |
if (mode == -1 && PyErr_Occurred()) { |
| 631 |
goto exit; |
| 632 |
} |
| 633 |
skip_optional_posonly: |
| 634 |
return_value = zlib_Compress_flush_impl((compobject *)self, cls, mode); |
| 635 |
|
| 636 |
exit: |
| 637 |
return return_value; |
| 638 |
} |
| 639 |
|
| 640 |
#if defined(HAVE_ZLIB_COPY) |
| 641 |
|
| 642 |
PyDoc_STRVAR(zlib_Compress_copy__doc__, |
| 643 |
"copy($self, /)\n" |
| 644 |
"--\n" |
| 645 |
"\n" |
| 646 |
"Return a copy of the compression object."); |
| 647 |
|
| 648 |
#define ZLIB_COMPRESS_COPY_METHODDEF \ |
| 649 |
{"copy", _PyCFunction_CAST(zlib_Compress_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress_copy__doc__}, |
| 650 |
|
| 651 |
static PyObject * |
| 652 |
zlib_Compress_copy_impl(compobject *self, PyTypeObject *cls); |
| 653 |
|
| 654 |
static PyObject * |
| 655 |
zlib_Compress_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 656 |
{ |
| 657 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 658 |
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); |
| 659 |
return NULL; |
| 660 |
} |
| 661 |
return zlib_Compress_copy_impl((compobject *)self, cls); |
| 662 |
} |
| 663 |
|
| 664 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 665 |
|
| 666 |
#if defined(HAVE_ZLIB_COPY) |
| 667 |
|
| 668 |
PyDoc_STRVAR(zlib_Compress___copy____doc__, |
| 669 |
"__copy__($self, /)\n" |
| 670 |
"--\n" |
| 671 |
"\n"); |
| 672 |
|
| 673 |
#define ZLIB_COMPRESS___COPY___METHODDEF \ |
| 674 |
{"__copy__", _PyCFunction_CAST(zlib_Compress___copy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress___copy____doc__}, |
| 675 |
|
| 676 |
static PyObject * |
| 677 |
zlib_Compress___copy___impl(compobject *self, PyTypeObject *cls); |
| 678 |
|
| 679 |
static PyObject * |
| 680 |
zlib_Compress___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 681 |
{ |
| 682 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 683 |
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments"); |
| 684 |
return NULL; |
| 685 |
} |
| 686 |
return zlib_Compress___copy___impl((compobject *)self, cls); |
| 687 |
} |
| 688 |
|
| 689 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 690 |
|
| 691 |
#if defined(HAVE_ZLIB_COPY) |
| 692 |
|
| 693 |
PyDoc_STRVAR(zlib_Compress___deepcopy____doc__, |
| 694 |
"__deepcopy__($self, memo, /)\n" |
| 695 |
"--\n" |
| 696 |
"\n"); |
| 697 |
|
| 698 |
#define ZLIB_COMPRESS___DEEPCOPY___METHODDEF \ |
| 699 |
{"__deepcopy__", _PyCFunction_CAST(zlib_Compress___deepcopy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Compress___deepcopy____doc__}, |
| 700 |
|
| 701 |
static PyObject * |
| 702 |
zlib_Compress___deepcopy___impl(compobject *self, PyTypeObject *cls, |
| 703 |
PyObject *memo); |
| 704 |
|
| 705 |
static PyObject * |
| 706 |
zlib_Compress___deepcopy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 707 |
{ |
| 708 |
PyObject *return_value = NULL; |
| 709 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 710 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 711 |
#else |
| 712 |
# define KWTUPLE NULL |
| 713 |
#endif |
| 714 |
|
| 715 |
static const char * const _keywords[] = {"", NULL}; |
| 716 |
static _PyArg_Parser _parser = { |
| 717 |
.keywords = _keywords, |
| 718 |
.fname = "__deepcopy__", |
| 719 |
.kwtuple = KWTUPLE, |
| 720 |
}; |
| 721 |
#undef KWTUPLE |
| 722 |
PyObject *argsbuf[1]; |
| 723 |
PyObject *memo; |
| 724 |
|
| 725 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 726 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 727 |
if (!args) { |
| 728 |
goto exit; |
| 729 |
} |
| 730 |
memo = args[0]; |
| 731 |
return_value = zlib_Compress___deepcopy___impl((compobject *)self, cls, memo); |
| 732 |
|
| 733 |
exit: |
| 734 |
return return_value; |
| 735 |
} |
| 736 |
|
| 737 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 738 |
|
| 739 |
#if defined(HAVE_ZLIB_COPY) |
| 740 |
|
| 741 |
PyDoc_STRVAR(zlib_Decompress_copy__doc__, |
| 742 |
"copy($self, /)\n" |
| 743 |
"--\n" |
| 744 |
"\n" |
| 745 |
"Return a copy of the decompression object."); |
| 746 |
|
| 747 |
#define ZLIB_DECOMPRESS_COPY_METHODDEF \ |
| 748 |
{"copy", _PyCFunction_CAST(zlib_Decompress_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_copy__doc__}, |
| 749 |
|
| 750 |
static PyObject * |
| 751 |
zlib_Decompress_copy_impl(compobject *self, PyTypeObject *cls); |
| 752 |
|
| 753 |
static PyObject * |
| 754 |
zlib_Decompress_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 755 |
{ |
| 756 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 757 |
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); |
| 758 |
return NULL; |
| 759 |
} |
| 760 |
return zlib_Decompress_copy_impl((compobject *)self, cls); |
| 761 |
} |
| 762 |
|
| 763 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 764 |
|
| 765 |
#if defined(HAVE_ZLIB_COPY) |
| 766 |
|
| 767 |
PyDoc_STRVAR(zlib_Decompress___copy____doc__, |
| 768 |
"__copy__($self, /)\n" |
| 769 |
"--\n" |
| 770 |
"\n"); |
| 771 |
|
| 772 |
#define ZLIB_DECOMPRESS___COPY___METHODDEF \ |
| 773 |
{"__copy__", _PyCFunction_CAST(zlib_Decompress___copy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress___copy____doc__}, |
| 774 |
|
| 775 |
static PyObject * |
| 776 |
zlib_Decompress___copy___impl(compobject *self, PyTypeObject *cls); |
| 777 |
|
| 778 |
static PyObject * |
| 779 |
zlib_Decompress___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 780 |
{ |
| 781 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 782 |
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments"); |
| 783 |
return NULL; |
| 784 |
} |
| 785 |
return zlib_Decompress___copy___impl((compobject *)self, cls); |
| 786 |
} |
| 787 |
|
| 788 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 789 |
|
| 790 |
#if defined(HAVE_ZLIB_COPY) |
| 791 |
|
| 792 |
PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__, |
| 793 |
"__deepcopy__($self, memo, /)\n" |
| 794 |
"--\n" |
| 795 |
"\n"); |
| 796 |
|
| 797 |
#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF \ |
| 798 |
{"__deepcopy__", _PyCFunction_CAST(zlib_Decompress___deepcopy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress___deepcopy____doc__}, |
| 799 |
|
| 800 |
static PyObject * |
| 801 |
zlib_Decompress___deepcopy___impl(compobject *self, PyTypeObject *cls, |
| 802 |
PyObject *memo); |
| 803 |
|
| 804 |
static PyObject * |
| 805 |
zlib_Decompress___deepcopy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 806 |
{ |
| 807 |
PyObject *return_value = NULL; |
| 808 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 809 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 810 |
#else |
| 811 |
# define KWTUPLE NULL |
| 812 |
#endif |
| 813 |
|
| 814 |
static const char * const _keywords[] = {"", NULL}; |
| 815 |
static _PyArg_Parser _parser = { |
| 816 |
.keywords = _keywords, |
| 817 |
.fname = "__deepcopy__", |
| 818 |
.kwtuple = KWTUPLE, |
| 819 |
}; |
| 820 |
#undef KWTUPLE |
| 821 |
PyObject *argsbuf[1]; |
| 822 |
PyObject *memo; |
| 823 |
|
| 824 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 825 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 826 |
if (!args) { |
| 827 |
goto exit; |
| 828 |
} |
| 829 |
memo = args[0]; |
| 830 |
return_value = zlib_Decompress___deepcopy___impl((compobject *)self, cls, memo); |
| 831 |
|
| 832 |
exit: |
| 833 |
return return_value; |
| 834 |
} |
| 835 |
|
| 836 |
#endif /* defined(HAVE_ZLIB_COPY) */ |
| 837 |
|
| 838 |
PyDoc_STRVAR(zlib_Decompress_flush__doc__, |
| 839 |
"flush($self, length=zlib.DEF_BUF_SIZE, /)\n" |
| 840 |
"--\n" |
| 841 |
"\n" |
| 842 |
"Return a bytes object containing any remaining decompressed data.\n" |
| 843 |
"\n" |
| 844 |
" length\n" |
| 845 |
" the initial size of the output buffer."); |
| 846 |
|
| 847 |
#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \ |
| 848 |
{"flush", _PyCFunction_CAST(zlib_Decompress_flush), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_flush__doc__}, |
| 849 |
|
| 850 |
static PyObject * |
| 851 |
zlib_Decompress_flush_impl(compobject *self, PyTypeObject *cls, |
| 852 |
Py_ssize_t length); |
| 853 |
|
| 854 |
static PyObject * |
| 855 |
zlib_Decompress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 856 |
{ |
| 857 |
PyObject *return_value = NULL; |
| 858 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 859 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 860 |
#else |
| 861 |
# define KWTUPLE NULL |
| 862 |
#endif |
| 863 |
|
| 864 |
static const char * const _keywords[] = {"", NULL}; |
| 865 |
static _PyArg_Parser _parser = { |
| 866 |
.keywords = _keywords, |
| 867 |
.fname = "flush", |
| 868 |
.kwtuple = KWTUPLE, |
| 869 |
}; |
| 870 |
#undef KWTUPLE |
| 871 |
PyObject *argsbuf[1]; |
| 872 |
Py_ssize_t length = DEF_BUF_SIZE; |
| 873 |
|
| 874 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 875 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 876 |
if (!args) { |
| 877 |
goto exit; |
| 878 |
} |
| 879 |
if (nargs < 1) { |
| 880 |
goto skip_optional_posonly; |
| 881 |
} |
| 882 |
{ |
| 883 |
Py_ssize_t ival = -1; |
| 884 |
PyObject *iobj = _PyNumber_Index(args[0]); |
| 885 |
if (iobj != NULL) { |
| 886 |
ival = PyLong_AsSsize_t(iobj); |
| 887 |
Py_DECREF(iobj); |
| 888 |
} |
| 889 |
if (ival == -1 && PyErr_Occurred()) { |
| 890 |
goto exit; |
| 891 |
} |
| 892 |
length = ival; |
| 893 |
} |
| 894 |
skip_optional_posonly: |
| 895 |
return_value = zlib_Decompress_flush_impl((compobject *)self, cls, length); |
| 896 |
|
| 897 |
exit: |
| 898 |
return return_value; |
| 899 |
} |
| 900 |
|
| 901 |
PyDoc_STRVAR(zlib_ZlibDecompressor_decompress__doc__, |
| 902 |
"decompress($self, /, data, max_length=-1)\n" |
| 903 |
"--\n" |
| 904 |
"\n" |
| 905 |
"Decompress *data*, returning uncompressed data as bytes.\n" |
| 906 |
"\n" |
| 907 |
"If *max_length* is nonnegative, returns at most *max_length* bytes\n" |
| 908 |
"of decompressed data. If this limit is reached and further output\n" |
| 909 |
"can be produced, *self.needs_input* will be set to ``False``. In\n" |
| 910 |
"this case, the next call to *decompress()* may provide *data* as b\'\'\n" |
| 911 |
"to obtain more of the output.\n" |
| 912 |
"\n" |
| 913 |
"If all of the input data was decompressed and returned (either\n" |
| 914 |
"because this was less than *max_length* bytes, or because\n" |
| 915 |
"*max_length* was negative), *self.needs_input* will be set to True.\n" |
| 916 |
"\n" |
| 917 |
"Attempting to decompress data after the end of stream is reached\n" |
| 918 |
"raises an EOFError. Any data found after the end of the stream is\n" |
| 919 |
"ignored and saved in the unused_data attribute."); |
| 920 |
|
| 921 |
#define ZLIB_ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF \ |
| 922 |
{"decompress", _PyCFunction_CAST(zlib_ZlibDecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, zlib_ZlibDecompressor_decompress__doc__}, |
| 923 |
|
| 924 |
static PyObject * |
| 925 |
zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self, |
| 926 |
Py_buffer *data, Py_ssize_t max_length); |
| 927 |
|
| 928 |
static PyObject * |
| 929 |
zlib_ZlibDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 930 |
{ |
| 931 |
PyObject *return_value = NULL; |
| 932 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 933 |
|
| 934 |
#define NUM_KEYWORDS 2 |
| 935 |
static struct { |
| 936 |
PyGC_Head _this_is_not_used; |
| 937 |
PyObject_VAR_HEAD |
| 938 |
Py_hash_t ob_hash; |
| 939 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 940 |
} _kwtuple = { |
| 941 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 942 |
.ob_hash = -1, |
| 943 |
.ob_item = { &_Py_ID(data), &_Py_ID(max_length), }, |
| 944 |
}; |
| 945 |
#undef NUM_KEYWORDS |
| 946 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 947 |
|
| 948 |
#else // !Py_BUILD_CORE |
| 949 |
# define KWTUPLE NULL |
| 950 |
#endif // !Py_BUILD_CORE |
| 951 |
|
| 952 |
static const char * const _keywords[] = {"data", "max_length", NULL}; |
| 953 |
static _PyArg_Parser _parser = { |
| 954 |
.keywords = _keywords, |
| 955 |
.fname = "decompress", |
| 956 |
.kwtuple = KWTUPLE, |
| 957 |
}; |
| 958 |
#undef KWTUPLE |
| 959 |
PyObject *argsbuf[2]; |
| 960 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 961 |
Py_buffer data = {NULL, NULL}; |
| 962 |
Py_ssize_t max_length = -1; |
| 963 |
|
| 964 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 965 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 966 |
if (!args) { |
| 967 |
goto exit; |
| 968 |
} |
| 969 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 970 |
goto exit; |
| 971 |
} |
| 972 |
if (!noptargs) { |
| 973 |
goto skip_optional_pos; |
| 974 |
} |
| 975 |
{ |
| 976 |
Py_ssize_t ival = -1; |
| 977 |
PyObject *iobj = _PyNumber_Index(args[1]); |
| 978 |
if (iobj != NULL) { |
| 979 |
ival = PyLong_AsSsize_t(iobj); |
| 980 |
Py_DECREF(iobj); |
| 981 |
} |
| 982 |
if (ival == -1 && PyErr_Occurred()) { |
| 983 |
goto exit; |
| 984 |
} |
| 985 |
max_length = ival; |
| 986 |
} |
| 987 |
skip_optional_pos: |
| 988 |
return_value = zlib_ZlibDecompressor_decompress_impl((ZlibDecompressor *)self, &data, max_length); |
| 989 |
|
| 990 |
exit: |
| 991 |
/* Cleanup for data */ |
| 992 |
if (data.obj) { |
| 993 |
PyBuffer_Release(&data); |
| 994 |
} |
| 995 |
|
| 996 |
return return_value; |
| 997 |
} |
| 998 |
|
| 999 |
PyDoc_STRVAR(zlib_adler32__doc__, |
| 1000 |
"adler32($module, data, value=1, /)\n" |
| 1001 |
"--\n" |
| 1002 |
"\n" |
| 1003 |
"Compute an Adler-32 checksum of data.\n" |
| 1004 |
"\n" |
| 1005 |
" value\n" |
| 1006 |
" Starting value of the checksum.\n" |
| 1007 |
"\n" |
| 1008 |
"The returned checksum is an integer."); |
| 1009 |
|
| 1010 |
#define ZLIB_ADLER32_METHODDEF \ |
| 1011 |
{"adler32", _PyCFunction_CAST(zlib_adler32), METH_FASTCALL, zlib_adler32__doc__}, |
| 1012 |
|
| 1013 |
static PyObject * |
| 1014 |
zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
| 1015 |
|
| 1016 |
static PyObject * |
| 1017 |
zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1018 |
{ |
| 1019 |
PyObject *return_value = NULL; |
| 1020 |
Py_buffer data = {NULL, NULL}; |
| 1021 |
unsigned int value = 1; |
| 1022 |
|
| 1023 |
if (!_PyArg_CheckPositional("adler32", nargs, 1, 2)) { |
| 1024 |
goto exit; |
| 1025 |
} |
| 1026 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1027 |
goto exit; |
| 1028 |
} |
| 1029 |
if (nargs < 2) { |
| 1030 |
goto skip_optional; |
| 1031 |
} |
| 1032 |
value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
| 1033 |
if (value == (unsigned int)-1 && PyErr_Occurred()) { |
| 1034 |
goto exit; |
| 1035 |
} |
| 1036 |
skip_optional: |
| 1037 |
return_value = zlib_adler32_impl(module, &data, value); |
| 1038 |
|
| 1039 |
exit: |
| 1040 |
/* Cleanup for data */ |
| 1041 |
if (data.obj) { |
| 1042 |
PyBuffer_Release(&data); |
| 1043 |
} |
| 1044 |
|
| 1045 |
return return_value; |
| 1046 |
} |
| 1047 |
|
| 1048 |
PyDoc_STRVAR(zlib_crc32__doc__, |
| 1049 |
"crc32($module, data, value=0, /)\n" |
| 1050 |
"--\n" |
| 1051 |
"\n" |
| 1052 |
"Compute a CRC-32 checksum of data.\n" |
| 1053 |
"\n" |
| 1054 |
" value\n" |
| 1055 |
" Starting value of the checksum.\n" |
| 1056 |
"\n" |
| 1057 |
"The returned checksum is an integer."); |
| 1058 |
|
| 1059 |
#define ZLIB_CRC32_METHODDEF \ |
| 1060 |
{"crc32", _PyCFunction_CAST(zlib_crc32), METH_FASTCALL, zlib_crc32__doc__}, |
| 1061 |
|
| 1062 |
static unsigned int |
| 1063 |
zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value); |
| 1064 |
|
| 1065 |
static PyObject * |
| 1066 |
zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1067 |
{ |
| 1068 |
PyObject *return_value = NULL; |
| 1069 |
Py_buffer data = {NULL, NULL}; |
| 1070 |
unsigned int value = 0; |
| 1071 |
unsigned int _return_value; |
| 1072 |
|
| 1073 |
if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) { |
| 1074 |
goto exit; |
| 1075 |
} |
| 1076 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1077 |
goto exit; |
| 1078 |
} |
| 1079 |
if (nargs < 2) { |
| 1080 |
goto skip_optional; |
| 1081 |
} |
| 1082 |
value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
| 1083 |
if (value == (unsigned int)-1 && PyErr_Occurred()) { |
| 1084 |
goto exit; |
| 1085 |
} |
| 1086 |
skip_optional: |
| 1087 |
_return_value = zlib_crc32_impl(module, &data, value); |
| 1088 |
if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
| 1089 |
goto exit; |
| 1090 |
} |
| 1091 |
return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 1092 |
|
| 1093 |
exit: |
| 1094 |
/* Cleanup for data */ |
| 1095 |
if (data.obj) { |
| 1096 |
PyBuffer_Release(&data); |
| 1097 |
} |
| 1098 |
|
| 1099 |
return return_value; |
| 1100 |
} |
| 1101 |
|
| 1102 |
#ifndef ZLIB_COMPRESS_COPY_METHODDEF |
| 1103 |
#define ZLIB_COMPRESS_COPY_METHODDEF |
| 1104 |
#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ |
| 1105 |
|
| 1106 |
#ifndef ZLIB_COMPRESS___COPY___METHODDEF |
| 1107 |
#define ZLIB_COMPRESS___COPY___METHODDEF |
| 1108 |
#endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */ |
| 1109 |
|
| 1110 |
#ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF |
| 1111 |
#define ZLIB_COMPRESS___DEEPCOPY___METHODDEF |
| 1112 |
#endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */ |
| 1113 |
|
| 1114 |
#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF |
| 1115 |
#define ZLIB_DECOMPRESS_COPY_METHODDEF |
| 1116 |
#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */ |
| 1117 |
|
| 1118 |
#ifndef ZLIB_DECOMPRESS___COPY___METHODDEF |
| 1119 |
#define ZLIB_DECOMPRESS___COPY___METHODDEF |
| 1120 |
#endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */ |
| 1121 |
|
| 1122 |
#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF |
| 1123 |
#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF |
| 1124 |
#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ |
| 1125 |
/*[clinic end generated code: output=99936d9996e595ff input=a9049054013a1b77]*/ |