mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	Issue #20193: The zlib module now uses Argument Clinic.
This commit is contained in:
		
							parent
							
								
									62a85b54a3
								
							
						
					
					
						commit
						2c5ddbe030
					
				
					 2 changed files with 610 additions and 310 deletions
				
			
		
							
								
								
									
										411
									
								
								Modules/clinic/zlibmodule.c.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										411
									
								
								Modules/clinic/zlibmodule.c.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,411 @@
 | 
				
			||||||
 | 
					/*[clinic input]
 | 
				
			||||||
 | 
					preserve
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_compress__doc__,
 | 
				
			||||||
 | 
					"compress(module, bytes, level=Z_DEFAULT_COMPRESSION)\n"
 | 
				
			||||||
 | 
					"Returns a bytes object containing compressed data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  bytes\n"
 | 
				
			||||||
 | 
					"    Binary data to be compressed.\n"
 | 
				
			||||||
 | 
					"  level\n"
 | 
				
			||||||
 | 
					"    Compression level, in 0-9.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_COMPRESS_METHODDEF    \
 | 
				
			||||||
 | 
					    {"compress", (PyCFunction)zlib_compress, METH_VARARGS, zlib_compress__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_compress(PyModuleDef *module, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer bytes = {NULL, NULL};
 | 
				
			||||||
 | 
					    int level = Z_DEFAULT_COMPRESSION;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*|i:compress",
 | 
				
			||||||
 | 
					        &bytes, &level))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_compress_impl(module, &bytes, level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for bytes */
 | 
				
			||||||
 | 
					    if (bytes.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&bytes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_decompress__doc__,
 | 
				
			||||||
 | 
					"decompress(module, data, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n"
 | 
				
			||||||
 | 
					"Returns a bytes object containing the uncompressed data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  data\n"
 | 
				
			||||||
 | 
					"    Compressed data.\n"
 | 
				
			||||||
 | 
					"  wbits\n"
 | 
				
			||||||
 | 
					"    The window buffer size.\n"
 | 
				
			||||||
 | 
					"  bufsize\n"
 | 
				
			||||||
 | 
					"    The initial output buffer size.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_DECOMPRESS_METHODDEF    \
 | 
				
			||||||
 | 
					    {"decompress", (PyCFunction)zlib_decompress, METH_VARARGS, zlib_decompress__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, unsigned int bufsize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_decompress(PyModuleDef *module, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer data = {NULL, NULL};
 | 
				
			||||||
 | 
					    int wbits = MAX_WBITS;
 | 
				
			||||||
 | 
					    unsigned int bufsize = DEF_BUF_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*|iO&:decompress",
 | 
				
			||||||
 | 
					        &data, &wbits, uint_converter, &bufsize))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for data */
 | 
				
			||||||
 | 
					    if (data.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_compressobj__doc__,
 | 
				
			||||||
 | 
					"compressobj(module, level=Z_DEFAULT_COMPRESSION, method=DEFLATED, wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=Z_DEFAULT_STRATEGY, zdict=None)\n"
 | 
				
			||||||
 | 
					"Return a compressor object.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  level\n"
 | 
				
			||||||
 | 
					"    The compression level (an integer in the range 0-9; default is 6).\n"
 | 
				
			||||||
 | 
					"    Higher compression levels are slower, but produce smaller results.\n"
 | 
				
			||||||
 | 
					"  method\n"
 | 
				
			||||||
 | 
					"    The compression algorithm.  If given, this must be DEFLATED.\n"
 | 
				
			||||||
 | 
					"  wbits\n"
 | 
				
			||||||
 | 
					"    The base two logarithm of the window size (range: 8..15).\n"
 | 
				
			||||||
 | 
					"  memLevel\n"
 | 
				
			||||||
 | 
					"    Controls the amount of memory used for internal compression state.\n"
 | 
				
			||||||
 | 
					"    Valid values range from 1 to 9.  Higher values result in higher memory\n"
 | 
				
			||||||
 | 
					"    usage, faster compression, and smaller output.\n"
 | 
				
			||||||
 | 
					"  strategy\n"
 | 
				
			||||||
 | 
					"    Used to tune the compression algorithm.  Possible values are\n"
 | 
				
			||||||
 | 
					"    Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
 | 
				
			||||||
 | 
					"  zdict\n"
 | 
				
			||||||
 | 
					"    The predefined compression dictionary - a sequence of bytes\n"
 | 
				
			||||||
 | 
					"    containing subsequences that are likely to occur in the input data.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_COMPRESSOBJ_METHODDEF    \
 | 
				
			||||||
 | 
					    {"compressobj", (PyCFunction)zlib_compressobj, METH_VARARGS|METH_KEYWORDS, zlib_compressobj__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, int memLevel, int strategy, Py_buffer *zdict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_compressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    static char *_keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
 | 
				
			||||||
 | 
					    int level = Z_DEFAULT_COMPRESSION;
 | 
				
			||||||
 | 
					    int method = DEFLATED;
 | 
				
			||||||
 | 
					    int wbits = MAX_WBITS;
 | 
				
			||||||
 | 
					    int memLevel = DEF_MEM_LEVEL;
 | 
				
			||||||
 | 
					    int strategy = Z_DEFAULT_STRATEGY;
 | 
				
			||||||
 | 
					    Py_buffer zdict = {NULL, NULL};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 | 
				
			||||||
 | 
					        "|iiiiiy*:compressobj", _keywords,
 | 
				
			||||||
 | 
					        &level, &method, &wbits, &memLevel, &strategy, &zdict))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for zdict */
 | 
				
			||||||
 | 
					    if (zdict.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&zdict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_decompressobj__doc__,
 | 
				
			||||||
 | 
					"decompressobj(module, wbits=MAX_WBITS, zdict=b\'\')\n"
 | 
				
			||||||
 | 
					"Return a decompressor object.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  wbits\n"
 | 
				
			||||||
 | 
					"    The window buffer size.\n"
 | 
				
			||||||
 | 
					"  zdict\n"
 | 
				
			||||||
 | 
					"    The predefined compression dictionary.  This must be the same\n"
 | 
				
			||||||
 | 
					"    dictionary as used by the compressor that produced the input data.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_DECOMPRESSOBJ_METHODDEF    \
 | 
				
			||||||
 | 
					    {"decompressobj", (PyCFunction)zlib_decompressobj, METH_VARARGS|METH_KEYWORDS, zlib_decompressobj__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_decompressobj_impl(PyModuleDef *module, int wbits, PyObject *zdict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_decompressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    static char *_keywords[] = {"wbits", "zdict", NULL};
 | 
				
			||||||
 | 
					    int wbits = MAX_WBITS;
 | 
				
			||||||
 | 
					    PyObject *zdict = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 | 
				
			||||||
 | 
					        "|iO:decompressobj", _keywords,
 | 
				
			||||||
 | 
					        &wbits, &zdict))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_decompressobj_impl(module, wbits, zdict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Compress_compress__doc__,
 | 
				
			||||||
 | 
					"compress(self, data)\n"
 | 
				
			||||||
 | 
					"Returns a bytes object containing compressed data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  data\n"
 | 
				
			||||||
 | 
					"    Binary data to be compressed.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"After calling this function, some of the input data may still\n"
 | 
				
			||||||
 | 
					"be stored in internal buffers for later processing.\n"
 | 
				
			||||||
 | 
					"Call the flush() method to clear these buffers.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_COMPRESS_COMPRESS_METHODDEF    \
 | 
				
			||||||
 | 
					    {"compress", (PyCFunction)zlib_Compress_compress, METH_VARARGS, zlib_Compress_compress__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_compress_impl(compobject *self, Py_buffer *data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_compress(compobject *self, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer data = {NULL, NULL};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*:compress",
 | 
				
			||||||
 | 
					        &data))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_Compress_compress_impl(self, &data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for data */
 | 
				
			||||||
 | 
					    if (data.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
 | 
				
			||||||
 | 
					"decompress(self, data, max_length=0)\n"
 | 
				
			||||||
 | 
					"Return a bytes object containing the decompressed version of the data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  data\n"
 | 
				
			||||||
 | 
					"    The binary data to decompress.\n"
 | 
				
			||||||
 | 
					"  max_length\n"
 | 
				
			||||||
 | 
					"    The maximum allowable length of the decompressed data.\n"
 | 
				
			||||||
 | 
					"    Unconsumed input data will be stored in\n"
 | 
				
			||||||
 | 
					"    the unconsumed_tail attribute.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"After calling this function, some of the input data may still be stored in\n"
 | 
				
			||||||
 | 
					"internal buffers for later processing.\n"
 | 
				
			||||||
 | 
					"Call the flush() method to clear these buffers.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF    \
 | 
				
			||||||
 | 
					    {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_VARARGS, zlib_Decompress_decompress__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_decompress(compobject *self, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer data = {NULL, NULL};
 | 
				
			||||||
 | 
					    unsigned int max_length = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*|O&:decompress",
 | 
				
			||||||
 | 
					        &data, uint_converter, &max_length))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for data */
 | 
				
			||||||
 | 
					    if (data.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Compress_flush__doc__,
 | 
				
			||||||
 | 
					"flush(self, mode=Z_FINISH)\n"
 | 
				
			||||||
 | 
					"Return a bytes object containing any remaining compressed data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  mode\n"
 | 
				
			||||||
 | 
					"    One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
 | 
				
			||||||
 | 
					"    If mode == Z_FINISH, the compressor object can no longer be\n"
 | 
				
			||||||
 | 
					"    used after calling the flush() method.  Otherwise, more data\n"
 | 
				
			||||||
 | 
					"    can still be compressed.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_COMPRESS_FLUSH_METHODDEF    \
 | 
				
			||||||
 | 
					    {"flush", (PyCFunction)zlib_Compress_flush, METH_VARARGS, zlib_Compress_flush__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_flush_impl(compobject *self, int mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_flush(compobject *self, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    int mode = Z_FINISH;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "|i:flush",
 | 
				
			||||||
 | 
					        &mode))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_Compress_flush_impl(self, mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Compress_copy__doc__,
 | 
				
			||||||
 | 
					"copy(self)\n"
 | 
				
			||||||
 | 
					"Return a copy of the compression object.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_COMPRESS_COPY_METHODDEF    \
 | 
				
			||||||
 | 
					    {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_copy_impl(compobject *self);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return zlib_Compress_copy_impl(self);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Decompress_copy__doc__,
 | 
				
			||||||
 | 
					"copy(self)\n"
 | 
				
			||||||
 | 
					"Return a copy of the decompression object.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_DECOMPRESS_COPY_METHODDEF    \
 | 
				
			||||||
 | 
					    {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_copy_impl(compobject *self);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return zlib_Decompress_copy_impl(self);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_Decompress_flush__doc__,
 | 
				
			||||||
 | 
					"flush(self, length=DEF_BUF_SIZE)\n"
 | 
				
			||||||
 | 
					"Return a bytes object containing any remaining decompressed data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  length\n"
 | 
				
			||||||
 | 
					"    the initial size of the output buffer.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_DECOMPRESS_FLUSH_METHODDEF    \
 | 
				
			||||||
 | 
					    {"flush", (PyCFunction)zlib_Decompress_flush, METH_VARARGS, zlib_Decompress_flush__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_flush_impl(compobject *self, unsigned int length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_Decompress_flush(compobject *self, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    unsigned int length = DEF_BUF_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "|O&:flush",
 | 
				
			||||||
 | 
					        uint_converter, &length))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_Decompress_flush_impl(self, length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_adler32__doc__,
 | 
				
			||||||
 | 
					"adler32(module, data, value=1)\n"
 | 
				
			||||||
 | 
					"Compute an Adler-32 checksum of data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  value\n"
 | 
				
			||||||
 | 
					"    Starting value of the checksum.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"The returned checksum is an integer.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_ADLER32_METHODDEF    \
 | 
				
			||||||
 | 
					    {"adler32", (PyCFunction)zlib_adler32, METH_VARARGS, zlib_adler32__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_adler32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_adler32(PyModuleDef *module, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer data = {NULL, NULL};
 | 
				
			||||||
 | 
					    unsigned int value = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*|I:adler32",
 | 
				
			||||||
 | 
					        &data, &value))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_adler32_impl(module, &data, value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for data */
 | 
				
			||||||
 | 
					    if (data.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PyDoc_STRVAR(zlib_crc32__doc__,
 | 
				
			||||||
 | 
					"crc32(module, data, value=0)\n"
 | 
				
			||||||
 | 
					"Compute a CRC-32 checksum of data.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"  value\n"
 | 
				
			||||||
 | 
					"    Starting value of the checksum.\n"
 | 
				
			||||||
 | 
					"\n"
 | 
				
			||||||
 | 
					"The returned checksum is an integer.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_CRC32_METHODDEF    \
 | 
				
			||||||
 | 
					    {"crc32", (PyCFunction)zlib_crc32, METH_VARARGS, zlib_crc32__doc__},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_crc32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_crc32(PyModuleDef *module, PyObject *args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PyObject *return_value = NULL;
 | 
				
			||||||
 | 
					    Py_buffer data = {NULL, NULL};
 | 
				
			||||||
 | 
					    unsigned int value = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!PyArg_ParseTuple(args,
 | 
				
			||||||
 | 
					        "y*|I:crc32",
 | 
				
			||||||
 | 
					        &data, &value))
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					    return_value = zlib_crc32_impl(module, &data, value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    /* Cleanup for data */
 | 
				
			||||||
 | 
					    if (data.obj)
 | 
				
			||||||
 | 
					       PyBuffer_Release(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return return_value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=04f94bbaf2652717753e237e4021bf6c92ddffdd]*/
 | 
				
			||||||
| 
						 | 
					@ -28,10 +28,9 @@
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
 | 
					#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#define DEF_WBITS MAX_WBITS
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */
 | 
					/* Initial buffer size. */
 | 
				
			||||||
#define DEFAULTALLOC (16*1024)
 | 
					#define DEF_BUF_SIZE (16*1024)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyTypeObject Comptype;
 | 
					static PyTypeObject Comptype;
 | 
				
			||||||
static PyTypeObject Decomptype;
 | 
					static PyTypeObject Decomptype;
 | 
				
			||||||
| 
						 | 
					@ -82,42 +81,13 @@ zlib_error(z_stream zst, int err, char *msg)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*[clinic input]
 | 
					/*[clinic input]
 | 
				
			||||||
 | 
					output preset file
 | 
				
			||||||
module zlib
 | 
					module zlib
 | 
				
			||||||
class zlib.Compress "compobject *" "&Comptype"
 | 
					class zlib.Compress "compobject *" "&Comptype"
 | 
				
			||||||
class zlib.Decompress "compobject *" "&Decomptype"
 | 
					class zlib.Decompress "compobject *" "&Decomptype"
 | 
				
			||||||
[clinic start generated code]*/
 | 
					[clinic start generated code]*/
 | 
				
			||||||
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
 | 
					/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(compressobj__doc__,
 | 
					 | 
				
			||||||
"compressobj(level=-1, method=DEFLATED, wbits=15, memlevel=8,\n"
 | 
					 | 
				
			||||||
"            strategy=Z_DEFAULT_STRATEGY[, zdict])\n"
 | 
					 | 
				
			||||||
" -- Return a compressor object.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"level is the compression level (an integer in the range 0-9; default is 6).\n"
 | 
					 | 
				
			||||||
"Higher compression levels are slower, but produce smaller results.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"method is the compression algorithm. If given, this must be DEFLATED.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"wbits is the base two logarithm of the window size (range: 8..15).\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"memlevel controls the amount of memory used for internal compression state.\n"
 | 
					 | 
				
			||||||
"Valid values range from 1 to 9. Higher values result in higher memory usage,\n"
 | 
					 | 
				
			||||||
"faster compression, and smaller output.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"strategy is used to tune the compression algorithm. Possible values are\n"
 | 
					 | 
				
			||||||
"Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"zdict is the predefined compression dictionary - a sequence of bytes\n"
 | 
					 | 
				
			||||||
"containing subsequences that are likely to occur in the input data.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PyDoc_STRVAR(decompressobj__doc__,
 | 
					 | 
				
			||||||
"decompressobj([wbits[, zdict]]) -- Return a decompressor object.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"Optional arg wbits is the window buffer size.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"Optional arg zdict is the predefined compression dictionary. This must be\n"
 | 
					 | 
				
			||||||
"the same dictionary as used by the compressor that produced the input data.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static compobject *
 | 
					static compobject *
 | 
				
			||||||
newcompobject(PyTypeObject *type)
 | 
					newcompobject(PyTypeObject *type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -165,70 +135,20 @@ PyZlib_Free(voidpf ctx, void *ptr)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*[clinic input]
 | 
					/*[clinic input]
 | 
				
			||||||
 | 
					 | 
				
			||||||
zlib.compress
 | 
					zlib.compress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bytes: Py_buffer
 | 
					    bytes: Py_buffer
 | 
				
			||||||
        Binary data to be compressed.
 | 
					        Binary data to be compressed.
 | 
				
			||||||
    [
 | 
					    level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION
 | 
				
			||||||
    level: int
 | 
					 | 
				
			||||||
        Compression level, in 0-9.
 | 
					        Compression level, in 0-9.
 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
    /
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Returns compressed string.
 | 
					Returns a bytes object containing compressed data.
 | 
				
			||||||
 | 
					 | 
				
			||||||
[clinic start generated code]*/
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(zlib_compress__doc__,
 | 
					 | 
				
			||||||
"compress(module, bytes, [level])\n"
 | 
					 | 
				
			||||||
"Returns compressed string.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"  bytes\n"
 | 
					 | 
				
			||||||
"    Binary data to be compressed.\n"
 | 
					 | 
				
			||||||
"  level\n"
 | 
					 | 
				
			||||||
"    Compression level, in 0-9.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ZLIB_COMPRESS_METHODDEF    \
 | 
					 | 
				
			||||||
    {"compress", (PyCFunction)zlib_compress, METH_VARARGS, zlib_compress__doc__},
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level);
 | 
					zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int level)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=5d7dd4588788efd3516e5f4225050d6413632601]*/
 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_compress(PyModuleDef *module, PyObject *args)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    PyObject *return_value = NULL;
 | 
					 | 
				
			||||||
    Py_buffer bytes = {NULL, NULL};
 | 
					 | 
				
			||||||
    int group_right_1 = 0;
 | 
					 | 
				
			||||||
    int level = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    switch (PyTuple_GET_SIZE(args)) {
 | 
					 | 
				
			||||||
        case 1:
 | 
					 | 
				
			||||||
            if (!PyArg_ParseTuple(args, "y*:compress", &bytes))
 | 
					 | 
				
			||||||
                goto exit;
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case 2:
 | 
					 | 
				
			||||||
            if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level))
 | 
					 | 
				
			||||||
                goto exit;
 | 
					 | 
				
			||||||
            group_right_1 = 1;
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            PyErr_SetString(PyExc_TypeError, "zlib.compress requires 1 to 2 arguments");
 | 
					 | 
				
			||||||
            goto exit;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return_value = zlib_compress_impl(module, &bytes, group_right_1, level);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
exit:
 | 
					 | 
				
			||||||
    /* Cleanup for bytes */
 | 
					 | 
				
			||||||
    if (bytes.obj)
 | 
					 | 
				
			||||||
       PyBuffer_Release(&bytes);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return return_value;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level)
 | 
					 | 
				
			||||||
/*[clinic end generated code: checksum=ce8d4c0a17ecd79c3ffcc032dcdf8ac6830ded1e]*/
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PyObject *ReturnVal = NULL;
 | 
					    PyObject *ReturnVal = NULL;
 | 
				
			||||||
    Byte *input, *output = NULL;
 | 
					    Byte *input, *output = NULL;
 | 
				
			||||||
| 
						 | 
					@ -236,9 +156,6 @@ zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    z_stream zst;
 | 
					    z_stream zst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!group_right_1)
 | 
					 | 
				
			||||||
        level = Z_DEFAULT_COMPRESSION;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ((size_t)bytes->len > UINT_MAX) {
 | 
					    if ((size_t)bytes->len > UINT_MAX) {
 | 
				
			||||||
        PyErr_SetString(PyExc_OverflowError,
 | 
					        PyErr_SetString(PyExc_OverflowError,
 | 
				
			||||||
                        "Size does not fit in an unsigned int");
 | 
					                        "Size does not fit in an unsigned int");
 | 
				
			||||||
| 
						 | 
					@ -312,6 +229,7 @@ zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int
 | 
				
			||||||
class uint_converter(CConverter):
 | 
					class uint_converter(CConverter):
 | 
				
			||||||
    type = 'unsigned int'
 | 
					    type = 'unsigned int'
 | 
				
			||||||
    converter = 'uint_converter'
 | 
					    converter = 'uint_converter'
 | 
				
			||||||
 | 
					    c_ignored_default = "0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[python start generated code]*/
 | 
					[python start generated code]*/
 | 
				
			||||||
/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
 | 
					/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
 | 
				
			||||||
| 
						 | 
					@ -347,35 +265,38 @@ uint_converter(PyObject *obj, void *ptr)
 | 
				
			||||||
    return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(decompress__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"decompress(string[, wbits[, bufsize]]) -- Return decompressed string.\n"
 | 
					zlib.decompress
 | 
				
			||||||
"\n"
 | 
					
 | 
				
			||||||
"Optional arg wbits is the window buffer size.  Optional arg bufsize is\n"
 | 
					    data: Py_buffer
 | 
				
			||||||
"the initial output buffer size.");
 | 
					        Compressed data.
 | 
				
			||||||
 | 
					    wbits: int(c_default="MAX_WBITS") = MAX_WBITS
 | 
				
			||||||
 | 
					        The window buffer size.
 | 
				
			||||||
 | 
					    bufsize: uint(c_default="DEF_BUF_SIZE") = DEF_BUF_SIZE
 | 
				
			||||||
 | 
					        The initial output buffer size.
 | 
				
			||||||
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Returns a bytes object containing the uncompressed data.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_decompress(PyObject *self, PyObject *args)
 | 
					zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, unsigned int bufsize)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=9e5464e72df9cb5fee73df662dbcaed867e01d32]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PyObject *result_str = NULL;
 | 
					    PyObject *result_str = NULL;
 | 
				
			||||||
    Py_buffer pinput;
 | 
					 | 
				
			||||||
    Byte *input;
 | 
					    Byte *input;
 | 
				
			||||||
    unsigned int length;
 | 
					    unsigned int length;
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    int wsize=DEF_WBITS;
 | 
					    unsigned int new_bufsize;
 | 
				
			||||||
    unsigned int bufsize = DEFAULTALLOC, new_bufsize;
 | 
					 | 
				
			||||||
    z_stream zst;
 | 
					    z_stream zst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "y*|iO&:decompress",
 | 
					    if ((size_t)data->len > UINT_MAX) {
 | 
				
			||||||
                          &pinput, &wsize, uint_converter, &bufsize))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ((size_t)pinput.len > UINT_MAX) {
 | 
					 | 
				
			||||||
        PyErr_SetString(PyExc_OverflowError,
 | 
					        PyErr_SetString(PyExc_OverflowError,
 | 
				
			||||||
                        "Size does not fit in an unsigned int");
 | 
					                        "Size does not fit in an unsigned int");
 | 
				
			||||||
        goto error;
 | 
					        goto error;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    input = pinput.buf;
 | 
					    input = data->buf;
 | 
				
			||||||
    length = (unsigned int)pinput.len;
 | 
					    length = (unsigned int)data->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bufsize == 0)
 | 
					    if (bufsize == 0)
 | 
				
			||||||
        bufsize = 1;
 | 
					        bufsize = 1;
 | 
				
			||||||
| 
						 | 
					@ -391,7 +312,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
 | 
				
			||||||
    zst.zfree = PyZlib_Free;
 | 
					    zst.zfree = PyZlib_Free;
 | 
				
			||||||
    zst.next_out = (Byte *)PyBytes_AS_STRING(result_str);
 | 
					    zst.next_out = (Byte *)PyBytes_AS_STRING(result_str);
 | 
				
			||||||
    zst.next_in = (Byte *)input;
 | 
					    zst.next_in = (Byte *)input;
 | 
				
			||||||
    err = inflateInit2(&zst, wsize);
 | 
					    err = inflateInit2(&zst, wbits);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch(err) {
 | 
					    switch(err) {
 | 
				
			||||||
    case(Z_OK):
 | 
					    case(Z_OK):
 | 
				
			||||||
| 
						 | 
					@ -457,32 +378,45 @@ PyZlib_decompress(PyObject *self, PyObject *args)
 | 
				
			||||||
    if (_PyBytes_Resize(&result_str, zst.total_out) < 0)
 | 
					    if (_PyBytes_Resize(&result_str, zst.total_out) < 0)
 | 
				
			||||||
        goto error;
 | 
					        goto error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PyBuffer_Release(&pinput);
 | 
					 | 
				
			||||||
    return result_str;
 | 
					    return result_str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 error:
 | 
					 error:
 | 
				
			||||||
    PyBuffer_Release(&pinput);
 | 
					 | 
				
			||||||
    Py_XDECREF(result_str);
 | 
					    Py_XDECREF(result_str);
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*[clinic input]
 | 
				
			||||||
 | 
					zlib.compressobj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION
 | 
				
			||||||
 | 
					        The compression level (an integer in the range 0-9; default is 6).
 | 
				
			||||||
 | 
					        Higher compression levels are slower, but produce smaller results.
 | 
				
			||||||
 | 
					    method: int(c_default="DEFLATED") = DEFLATED
 | 
				
			||||||
 | 
					        The compression algorithm.  If given, this must be DEFLATED.
 | 
				
			||||||
 | 
					    wbits: int(c_default="MAX_WBITS") = MAX_WBITS
 | 
				
			||||||
 | 
					        The base two logarithm of the window size (range: 8..15).
 | 
				
			||||||
 | 
					    memLevel: int(c_default="DEF_MEM_LEVEL") = DEF_MEM_LEVEL
 | 
				
			||||||
 | 
					        Controls the amount of memory used for internal compression state.
 | 
				
			||||||
 | 
					        Valid values range from 1 to 9.  Higher values result in higher memory
 | 
				
			||||||
 | 
					        usage, faster compression, and smaller output.
 | 
				
			||||||
 | 
					    strategy: int(c_default="Z_DEFAULT_STRATEGY") = Z_DEFAULT_STRATEGY
 | 
				
			||||||
 | 
					        Used to tune the compression algorithm.  Possible values are
 | 
				
			||||||
 | 
					        Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.
 | 
				
			||||||
 | 
					    zdict: Py_buffer = None
 | 
				
			||||||
 | 
					        The predefined compression dictionary - a sequence of bytes
 | 
				
			||||||
 | 
					        containing subsequences that are likely to occur in the input data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Return a compressor object.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_compressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
 | 
					zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, int memLevel, int strategy, Py_buffer *zdict)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=89e5a6c1449caa9ed76f1baad066600e985151a9]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    compobject *self = NULL;
 | 
					    compobject *self = NULL;
 | 
				
			||||||
    int level=Z_DEFAULT_COMPRESSION, method=DEFLATED;
 | 
					    int err;
 | 
				
			||||||
    int wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=0, err;
 | 
					 | 
				
			||||||
    Py_buffer zdict;
 | 
					 | 
				
			||||||
    static char *kwlist[] = {"level", "method", "wbits",
 | 
					 | 
				
			||||||
                             "memLevel", "strategy", "zdict", NULL};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    zdict.buf = NULL; /* Sentinel, so we can tell whether zdict was supplied. */
 | 
					    if (zdict->buf != NULL && (size_t)zdict->len > UINT_MAX) {
 | 
				
			||||||
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiiiy*:compressobj",
 | 
					 | 
				
			||||||
                                     kwlist, &level, &method, &wbits,
 | 
					 | 
				
			||||||
                                     &memLevel, &strategy, &zdict))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (zdict.buf != NULL && (size_t)zdict.len > UINT_MAX) {
 | 
					 | 
				
			||||||
        PyErr_SetString(PyExc_OverflowError,
 | 
					        PyErr_SetString(PyExc_OverflowError,
 | 
				
			||||||
                        "zdict length does not fit in an unsigned int");
 | 
					                        "zdict length does not fit in an unsigned int");
 | 
				
			||||||
        goto error;
 | 
					        goto error;
 | 
				
			||||||
| 
						 | 
					@ -500,11 +434,11 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
 | 
				
			||||||
    switch(err) {
 | 
					    switch(err) {
 | 
				
			||||||
    case (Z_OK):
 | 
					    case (Z_OK):
 | 
				
			||||||
        self->is_initialised = 1;
 | 
					        self->is_initialised = 1;
 | 
				
			||||||
        if (zdict.buf == NULL) {
 | 
					        if (zdict->buf == NULL) {
 | 
				
			||||||
            goto success;
 | 
					            goto success;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            err = deflateSetDictionary(&self->zst,
 | 
					            err = deflateSetDictionary(&self->zst,
 | 
				
			||||||
                                       zdict.buf, (unsigned int)zdict.len);
 | 
					                                       zdict->buf, (unsigned int)zdict->len);
 | 
				
			||||||
            switch (err) {
 | 
					            switch (err) {
 | 
				
			||||||
            case (Z_OK):
 | 
					            case (Z_OK):
 | 
				
			||||||
                goto success;
 | 
					                goto success;
 | 
				
			||||||
| 
						 | 
					@ -532,22 +466,28 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
 | 
				
			||||||
    Py_XDECREF(self);
 | 
					    Py_XDECREF(self);
 | 
				
			||||||
    self = NULL;
 | 
					    self = NULL;
 | 
				
			||||||
 success:
 | 
					 success:
 | 
				
			||||||
    if (zdict.buf != NULL)
 | 
					 | 
				
			||||||
        PyBuffer_Release(&zdict);
 | 
					 | 
				
			||||||
    return (PyObject*)self;
 | 
					    return (PyObject*)self;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					/*[clinic input]
 | 
				
			||||||
PyZlib_decompressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
 | 
					zlib.decompressobj
 | 
				
			||||||
{
 | 
					
 | 
				
			||||||
    static char *kwlist[] = {"wbits", "zdict", NULL};
 | 
					    wbits: int(c_default="MAX_WBITS") = MAX_WBITS
 | 
				
			||||||
    int wbits=DEF_WBITS, err;
 | 
					        The window buffer size.
 | 
				
			||||||
    compobject *self;
 | 
					    zdict: object(c_default="NULL") = b''
 | 
				
			||||||
    PyObject *zdict=NULL;
 | 
					        The predefined compression dictionary.  This must be the same
 | 
				
			||||||
 | 
					        dictionary as used by the compressor that produced the input data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Return a decompressor object.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					zlib_decompressobj_impl(PyModuleDef *module, int wbits, PyObject *zdict)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=8ccd583fbd631798566d415933cd44440c8a74b5]*/
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					    compobject *self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:decompressobj",
 | 
					 | 
				
			||||||
                                     kwlist, &wbits, &zdict))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    if (zdict != NULL && !PyObject_CheckBuffer(zdict)) {
 | 
					    if (zdict != NULL && !PyObject_CheckBuffer(zdict)) {
 | 
				
			||||||
        PyErr_SetString(PyExc_TypeError,
 | 
					        PyErr_SetString(PyExc_TypeError,
 | 
				
			||||||
                        "zdict argument must support the buffer protocol");
 | 
					                        "zdict argument must support the buffer protocol");
 | 
				
			||||||
| 
						 | 
					@ -615,37 +555,41 @@ Decomp_dealloc(compobject *self)
 | 
				
			||||||
    Dealloc(self);
 | 
					    Dealloc(self);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(comp_compress__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"compress(data) -- Return a string containing data compressed.\n"
 | 
					zlib.Compress.compress
 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"After calling this function, some of the input data may still\n"
 | 
					 | 
				
			||||||
"be stored in internal buffers for later processing.\n"
 | 
					 | 
				
			||||||
"Call the flush() method to clear these buffers.");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    data: Py_buffer
 | 
				
			||||||
 | 
					        Binary data to be compressed.
 | 
				
			||||||
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Returns a bytes object containing compressed data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					After calling this function, some of the input data may still
 | 
				
			||||||
 | 
					be stored in internal buffers for later processing.
 | 
				
			||||||
 | 
					Call the flush() method to clear these buffers.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_objcompress(compobject *self, PyObject *args)
 | 
					zlib_Compress_compress_impl(compobject *self, Py_buffer *data)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=5d5cd791cbc6a7f4b6de4ec12c085c88d4d3e31c]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    unsigned int inplen;
 | 
					    unsigned int inplen;
 | 
				
			||||||
    unsigned int length = DEFAULTALLOC, new_length;
 | 
					    unsigned int length = DEF_BUF_SIZE, new_length;
 | 
				
			||||||
    PyObject *RetVal = NULL;
 | 
					    PyObject *RetVal;
 | 
				
			||||||
    Py_buffer pinput;
 | 
					 | 
				
			||||||
    Byte *input;
 | 
					    Byte *input;
 | 
				
			||||||
    unsigned long start_total_out;
 | 
					    unsigned long start_total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "y*:compress", &pinput))
 | 
					    if ((size_t)data->len > UINT_MAX) {
 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    if ((size_t)pinput.len > UINT_MAX) {
 | 
					 | 
				
			||||||
        PyErr_SetString(PyExc_OverflowError,
 | 
					        PyErr_SetString(PyExc_OverflowError,
 | 
				
			||||||
                        "Size does not fit in an unsigned int");
 | 
					                        "Size does not fit in an unsigned int");
 | 
				
			||||||
        goto error_outer;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    input = pinput.buf;
 | 
					    input = data->buf;
 | 
				
			||||||
    inplen = (unsigned int)pinput.len;
 | 
					    inplen = (unsigned int)data->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
 | 
					    if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
 | 
				
			||||||
        goto error_outer;
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ENTER_ZLIB(self);
 | 
					    ENTER_ZLIB(self);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -668,7 +612,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
 | 
				
			||||||
            new_length = UINT_MAX;
 | 
					            new_length = UINT_MAX;
 | 
				
			||||||
        if (_PyBytes_Resize(&RetVal, new_length) < 0) {
 | 
					        if (_PyBytes_Resize(&RetVal, new_length) < 0) {
 | 
				
			||||||
            Py_CLEAR(RetVal);
 | 
					            Py_CLEAR(RetVal);
 | 
				
			||||||
            goto error;
 | 
					            goto done;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        self->zst.next_out =
 | 
					        self->zst.next_out =
 | 
				
			||||||
            (unsigned char *)PyBytes_AS_STRING(RetVal) + length;
 | 
					            (unsigned char *)PyBytes_AS_STRING(RetVal) + length;
 | 
				
			||||||
| 
						 | 
					@ -686,18 +630,15 @@ PyZlib_objcompress(compobject *self, PyObject *args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (err != Z_OK && err != Z_BUF_ERROR) {
 | 
					    if (err != Z_OK && err != Z_BUF_ERROR) {
 | 
				
			||||||
        zlib_error(self->zst, err, "while compressing data");
 | 
					        zlib_error(self->zst, err, "while compressing data");
 | 
				
			||||||
        Py_DECREF(RetVal);
 | 
					        Py_CLEAR(RetVal);
 | 
				
			||||||
        RetVal = NULL;
 | 
					        goto done;
 | 
				
			||||||
        goto error;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) {
 | 
					    if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) {
 | 
				
			||||||
        Py_CLEAR(RetVal);
 | 
					        Py_CLEAR(RetVal);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 error:
 | 
					 done:
 | 
				
			||||||
    LEAVE_ZLIB(self);
 | 
					    LEAVE_ZLIB(self);
 | 
				
			||||||
 error_outer:
 | 
					 | 
				
			||||||
    PyBuffer_Release(&pinput);
 | 
					 | 
				
			||||||
    return RetVal;
 | 
					    return RetVal;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -745,7 +686,6 @@ save_unconsumed_input(compobject *self, int err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*[clinic input]
 | 
					/*[clinic input]
 | 
				
			||||||
 | 
					 | 
				
			||||||
zlib.Decompress.decompress
 | 
					zlib.Decompress.decompress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data: Py_buffer
 | 
					    data: Py_buffer
 | 
				
			||||||
| 
						 | 
					@ -756,61 +696,19 @@ zlib.Decompress.decompress
 | 
				
			||||||
        the unconsumed_tail attribute.
 | 
					        the unconsumed_tail attribute.
 | 
				
			||||||
    /
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Return a string containing the decompressed version of the data.
 | 
					Return a bytes object containing the decompressed version of the data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
After calling this function, some of the input data may still be stored in
 | 
					After calling this function, some of the input data may still be stored in
 | 
				
			||||||
internal buffers for later processing.
 | 
					internal buffers for later processing.
 | 
				
			||||||
Call the flush() method to clear these buffers.
 | 
					Call the flush() method to clear these buffers.
 | 
				
			||||||
[clinic start generated code]*/
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
 | 
					 | 
				
			||||||
"decompress(self, data, max_length=0)\n"
 | 
					 | 
				
			||||||
"Return a string containing the decompressed version of the data.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"  data\n"
 | 
					 | 
				
			||||||
"    The binary data to decompress.\n"
 | 
					 | 
				
			||||||
"  max_length\n"
 | 
					 | 
				
			||||||
"    The maximum allowable length of the decompressed data.\n"
 | 
					 | 
				
			||||||
"    Unconsumed input data will be stored in\n"
 | 
					 | 
				
			||||||
"    the unconsumed_tail attribute.\n"
 | 
					 | 
				
			||||||
"\n"
 | 
					 | 
				
			||||||
"After calling this function, some of the input data may still be stored in\n"
 | 
					 | 
				
			||||||
"internal buffers for later processing.\n"
 | 
					 | 
				
			||||||
"Call the flush() method to clear these buffers.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF    \
 | 
					 | 
				
			||||||
    {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_VARARGS, zlib_Decompress_decompress__doc__},
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_Decompress_decompress(compobject *self, PyObject *args)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    PyObject *return_value = NULL;
 | 
					 | 
				
			||||||
    Py_buffer data = {NULL, NULL};
 | 
					 | 
				
			||||||
    unsigned int max_length = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!PyArg_ParseTuple(args,
 | 
					 | 
				
			||||||
        "y*|O&:decompress",
 | 
					 | 
				
			||||||
        &data, uint_converter, &max_length))
 | 
					 | 
				
			||||||
        goto exit;
 | 
					 | 
				
			||||||
    return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
exit:
 | 
					 | 
				
			||||||
    /* Cleanup for data */
 | 
					 | 
				
			||||||
    if (data.obj)
 | 
					 | 
				
			||||||
       PyBuffer_Release(&data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return return_value;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length)
 | 
					zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length)
 | 
				
			||||||
/*[clinic end generated code: checksum=b7fd2e3b23430f57f5a84817189575bc46464901]*/
 | 
					/*[clinic end generated code: checksum=755cccc9087bfe55486b7e15fa7e2ab60b4c86d6]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    unsigned int old_length, length = DEFAULTALLOC;
 | 
					    unsigned int old_length, length = DEF_BUF_SIZE;
 | 
				
			||||||
    PyObject *RetVal = NULL;
 | 
					    PyObject *RetVal = NULL;
 | 
				
			||||||
    unsigned long start_total_out;
 | 
					    unsigned long start_total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -927,29 +825,31 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int
 | 
				
			||||||
    return RetVal;
 | 
					    return RetVal;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(comp_flush__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"flush( [mode] ) -- Return a string containing any remaining compressed data.\n"
 | 
					zlib.Compress.flush
 | 
				
			||||||
"\n"
 | 
					
 | 
				
			||||||
"mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n"
 | 
					    mode: int(c_default="Z_FINISH") = Z_FINISH
 | 
				
			||||||
"default value used when mode is not specified is Z_FINISH.\n"
 | 
					        One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.
 | 
				
			||||||
"If mode == Z_FINISH, the compressor object can no longer be used after\n"
 | 
					        If mode == Z_FINISH, the compressor object can no longer be
 | 
				
			||||||
"calling the flush() method.  Otherwise, more data can still be compressed.");
 | 
					        used after calling the flush() method.  Otherwise, more data
 | 
				
			||||||
 | 
					        can still be compressed.
 | 
				
			||||||
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Return a bytes object containing any remaining compressed data.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_flush(compobject *self, PyObject *args)
 | 
					zlib_Compress_flush_impl(compobject *self, int mode)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=a203f4cefc9de727aa1d2ea39d11c0a16c32041a]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    unsigned int length = DEFAULTALLOC, new_length;
 | 
					    unsigned int length = DEF_BUF_SIZE, new_length;
 | 
				
			||||||
    PyObject *RetVal;
 | 
					    PyObject *RetVal;
 | 
				
			||||||
    int flushmode = Z_FINISH;
 | 
					 | 
				
			||||||
    unsigned long start_total_out;
 | 
					    unsigned long start_total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "|i:flush", &flushmode))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
 | 
					    /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
 | 
				
			||||||
       doing any work at all; just return an empty string. */
 | 
					       doing any work at all; just return an empty string. */
 | 
				
			||||||
    if (flushmode == Z_NO_FLUSH) {
 | 
					    if (mode == Z_NO_FLUSH) {
 | 
				
			||||||
        return PyBytes_FromStringAndSize(NULL, 0);
 | 
					        return PyBytes_FromStringAndSize(NULL, 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -964,7 +864,7 @@ PyZlib_flush(compobject *self, PyObject *args)
 | 
				
			||||||
    self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
 | 
					    self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Py_BEGIN_ALLOW_THREADS
 | 
					    Py_BEGIN_ALLOW_THREADS
 | 
				
			||||||
    err = deflate(&(self->zst), flushmode);
 | 
					    err = deflate(&(self->zst), mode);
 | 
				
			||||||
    Py_END_ALLOW_THREADS
 | 
					    Py_END_ALLOW_THREADS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* while Z_OK and the output buffer is full, there might be more output,
 | 
					    /* while Z_OK and the output buffer is full, there might be more output,
 | 
				
			||||||
| 
						 | 
					@ -984,14 +884,14 @@ PyZlib_flush(compobject *self, PyObject *args)
 | 
				
			||||||
        length = new_length;
 | 
					        length = new_length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Py_BEGIN_ALLOW_THREADS
 | 
					        Py_BEGIN_ALLOW_THREADS
 | 
				
			||||||
        err = deflate(&(self->zst), flushmode);
 | 
					        err = deflate(&(self->zst), mode);
 | 
				
			||||||
        Py_END_ALLOW_THREADS
 | 
					        Py_END_ALLOW_THREADS
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
 | 
					    /* If mode is Z_FINISH, we also have to call deflateEnd() to free
 | 
				
			||||||
       various data structures. Note we should only get Z_STREAM_END when
 | 
					       various data structures. Note we should only get Z_STREAM_END when
 | 
				
			||||||
       flushmode is Z_FINISH, but checking both for safety*/
 | 
					       mode is Z_FINISH, but checking both for safety*/
 | 
				
			||||||
    if (err == Z_STREAM_END && flushmode == Z_FINISH) {
 | 
					    if (err == Z_STREAM_END && mode == Z_FINISH) {
 | 
				
			||||||
        err = deflateEnd(&(self->zst));
 | 
					        err = deflateEnd(&(self->zst));
 | 
				
			||||||
        if (err != Z_OK) {
 | 
					        if (err != Z_OK) {
 | 
				
			||||||
            zlib_error(self->zst, err, "while finishing compression");
 | 
					            zlib_error(self->zst, err, "while finishing compression");
 | 
				
			||||||
| 
						 | 
					@ -1031,25 +931,9 @@ zlib.Compress.copy
 | 
				
			||||||
Return a copy of the compression object.
 | 
					Return a copy of the compression object.
 | 
				
			||||||
[clinic start generated code]*/
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(zlib_Compress_copy__doc__,
 | 
					 | 
				
			||||||
"copy(self)\n"
 | 
					 | 
				
			||||||
"Return a copy of the compression object.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ZLIB_COMPRESS_COPY_METHODDEF    \
 | 
					 | 
				
			||||||
    {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_Compress_copy_impl(compobject *self);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					 | 
				
			||||||
zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return zlib_Compress_copy_impl(self);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
zlib_Compress_copy_impl(compobject *self)
 | 
					zlib_Compress_copy_impl(compobject *self)
 | 
				
			||||||
/*[clinic end generated code: checksum=7aa841ad51297eb83250f511a76872e88fdc737e]*/
 | 
					/*[clinic end generated code: checksum=5144aa153c21e805afa5c19e5b48cf8e6480b5da]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    compobject *retval = NULL;
 | 
					    compobject *retval = NULL;
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
| 
						 | 
					@ -1099,11 +983,15 @@ error:
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(decomp_copy__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"copy() -- Return a copy of the decompression object.");
 | 
					zlib.Decompress.copy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Return a copy of the decompression object.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_uncopy(compobject *self)
 | 
					zlib_Decompress_copy_impl(compobject *self)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=02a883a2a510c8ccfeef3f89e317a275bfe8c094]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    compobject *retval = NULL;
 | 
					    compobject *retval = NULL;
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
| 
						 | 
					@ -1155,24 +1043,26 @@ error:
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(decomp_flush__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"flush( [length] ) -- Return a string containing any remaining\n"
 | 
					zlib.Decompress.flush
 | 
				
			||||||
"decompressed data. length, if given, is the initial size of the\n"
 | 
					
 | 
				
			||||||
"output buffer.\n"
 | 
					    length: uint(c_default="DEF_BUF_SIZE") = DEF_BUF_SIZE
 | 
				
			||||||
"\n"
 | 
					        the initial size of the output buffer.
 | 
				
			||||||
"The decompressor object can no longer be used after this call.");
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Return a bytes object containing any remaining decompressed data.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_unflush(compobject *self, PyObject *args)
 | 
					zlib_Decompress_flush_impl(compobject *self, unsigned int length)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=db6fb753ab698e22afe3957c9da9e5e77f4bfc08]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int err;
 | 
					    int err;
 | 
				
			||||||
    unsigned int length = DEFAULTALLOC, new_length;
 | 
					    unsigned int new_length;
 | 
				
			||||||
    PyObject * retval = NULL;
 | 
					    PyObject * retval = NULL;
 | 
				
			||||||
    unsigned long start_total_out;
 | 
					    unsigned long start_total_out;
 | 
				
			||||||
    Py_ssize_t size;
 | 
					    Py_ssize_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "|O&:flush", uint_converter, &length))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    if (length == 0) {
 | 
					    if (length == 0) {
 | 
				
			||||||
        PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
 | 
					        PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
| 
						 | 
					@ -1248,12 +1138,12 @@ error:
 | 
				
			||||||
    return retval;
 | 
					    return retval;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlibmodule.clinic.c"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyMethodDef comp_methods[] =
 | 
					static PyMethodDef comp_methods[] =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    {"compress", (binaryfunc)PyZlib_objcompress, METH_VARARGS,
 | 
					    ZLIB_COMPRESS_COMPRESS_METHODDEF
 | 
				
			||||||
                 comp_compress__doc__},
 | 
					    ZLIB_COMPRESS_FLUSH_METHODDEF
 | 
				
			||||||
    {"flush", (binaryfunc)PyZlib_flush, METH_VARARGS,
 | 
					 | 
				
			||||||
              comp_flush__doc__},
 | 
					 | 
				
			||||||
#ifdef HAVE_ZLIB_COPY
 | 
					#ifdef HAVE_ZLIB_COPY
 | 
				
			||||||
    ZLIB_COMPRESS_COPY_METHODDEF
 | 
					    ZLIB_COMPRESS_COPY_METHODDEF
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -1263,11 +1153,9 @@ static PyMethodDef comp_methods[] =
 | 
				
			||||||
static PyMethodDef Decomp_methods[] =
 | 
					static PyMethodDef Decomp_methods[] =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF
 | 
					    ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF
 | 
				
			||||||
    {"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS,
 | 
					    ZLIB_DECOMPRESS_FLUSH_METHODDEF
 | 
				
			||||||
              decomp_flush__doc__},
 | 
					 | 
				
			||||||
#ifdef HAVE_ZLIB_COPY
 | 
					#ifdef HAVE_ZLIB_COPY
 | 
				
			||||||
    {"copy",  (PyCFunction)PyZlib_uncopy, METH_NOARGS,
 | 
					    ZLIB_DECOMPRESS_COPY_METHODDEF
 | 
				
			||||||
              decomp_copy__doc__},
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    {NULL, NULL}
 | 
					    {NULL, NULL}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -1280,95 +1168,95 @@ static PyMemberDef Decomp_members[] = {
 | 
				
			||||||
    {NULL},
 | 
					    {NULL},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(adler32__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n"
 | 
					zlib.adler32
 | 
				
			||||||
"\n"
 | 
					
 | 
				
			||||||
"An optional starting value can be specified.  The returned checksum is\n"
 | 
					    data: Py_buffer
 | 
				
			||||||
"an integer.");
 | 
					    value: unsigned_int(bitwise=True) = 1
 | 
				
			||||||
 | 
					        Starting value of the checksum.
 | 
				
			||||||
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Compute an Adler-32 checksum of data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The returned checksum is an integer.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_adler32(PyObject *self, PyObject *args)
 | 
					zlib_adler32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=51d6d75ee655c78af8c968fdb4c11d97e62c67d5]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned int adler32val = 1;  /* adler32(0L, Z_NULL, 0) */
 | 
					 | 
				
			||||||
    Py_buffer pbuf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "y*|I:adler32", &pbuf, &adler32val))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    /* Releasing the GIL for very small buffers is inefficient
 | 
					    /* Releasing the GIL for very small buffers is inefficient
 | 
				
			||||||
       and may lower performance */
 | 
					       and may lower performance */
 | 
				
			||||||
    if (pbuf.len > 1024*5) {
 | 
					    if (data->len > 1024*5) {
 | 
				
			||||||
        unsigned char *buf = pbuf.buf;
 | 
					        unsigned char *buf = data->buf;
 | 
				
			||||||
        Py_ssize_t len = pbuf.len;
 | 
					        Py_ssize_t len = data->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Py_BEGIN_ALLOW_THREADS
 | 
					        Py_BEGIN_ALLOW_THREADS
 | 
				
			||||||
        /* Avoid truncation of length for very large buffers. adler32() takes
 | 
					        /* Avoid truncation of length for very large buffers. adler32() takes
 | 
				
			||||||
           length as an unsigned int, which may be narrower than Py_ssize_t. */
 | 
					           length as an unsigned int, which may be narrower than Py_ssize_t. */
 | 
				
			||||||
        while ((size_t)len > UINT_MAX) {
 | 
					        while ((size_t)len > UINT_MAX) {
 | 
				
			||||||
            adler32val = adler32(adler32val, buf, UINT_MAX);
 | 
					            value = adler32(value, buf, UINT_MAX);
 | 
				
			||||||
            buf += (size_t) UINT_MAX;
 | 
					            buf += (size_t) UINT_MAX;
 | 
				
			||||||
            len -= (size_t) UINT_MAX;
 | 
					            len -= (size_t) UINT_MAX;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        adler32val = adler32(adler32val, buf, (unsigned int)len);
 | 
					        value = adler32(value, buf, (unsigned int)len);
 | 
				
			||||||
        Py_END_ALLOW_THREADS
 | 
					        Py_END_ALLOW_THREADS
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        adler32val = adler32(adler32val, pbuf.buf, (unsigned int)pbuf.len);
 | 
					        value = adler32(value, data->buf, (unsigned int)data->len);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    PyBuffer_Release(&pbuf);
 | 
					    return PyLong_FromUnsignedLong(value & 0xffffffffU);
 | 
				
			||||||
    return PyLong_FromUnsignedLong(adler32val & 0xffffffffU);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyDoc_STRVAR(crc32__doc__,
 | 
					/*[clinic input]
 | 
				
			||||||
"crc32(string[, start]) -- Compute a CRC-32 checksum of string.\n"
 | 
					zlib.crc32
 | 
				
			||||||
"\n"
 | 
					
 | 
				
			||||||
"An optional starting value can be specified.  The returned checksum is\n"
 | 
					    data: Py_buffer
 | 
				
			||||||
"an integer.");
 | 
					    value: unsigned_int(bitwise=True) = 0
 | 
				
			||||||
 | 
					        Starting value of the checksum.
 | 
				
			||||||
 | 
					    /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Compute a CRC-32 checksum of data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The returned checksum is an integer.
 | 
				
			||||||
 | 
					[clinic start generated code]*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
PyZlib_crc32(PyObject *self, PyObject *args)
 | 
					zlib_crc32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value)
 | 
				
			||||||
 | 
					/*[clinic end generated code: checksum=c1e986e74fe7b62369998a71a81ebeb9b73e8d4c]*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned int crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
 | 
					 | 
				
			||||||
    Py_buffer pbuf;
 | 
					 | 
				
			||||||
    int signed_val;
 | 
					    int signed_val;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "y*|I:crc32", &pbuf, &crc32val))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    /* Releasing the GIL for very small buffers is inefficient
 | 
					    /* Releasing the GIL for very small buffers is inefficient
 | 
				
			||||||
       and may lower performance */
 | 
					       and may lower performance */
 | 
				
			||||||
    if (pbuf.len > 1024*5) {
 | 
					    if (data->len > 1024*5) {
 | 
				
			||||||
        unsigned char *buf = pbuf.buf;
 | 
					        unsigned char *buf = data->buf;
 | 
				
			||||||
        Py_ssize_t len = pbuf.len;
 | 
					        Py_ssize_t len = data->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Py_BEGIN_ALLOW_THREADS
 | 
					        Py_BEGIN_ALLOW_THREADS
 | 
				
			||||||
        /* Avoid truncation of length for very large buffers. crc32() takes
 | 
					        /* Avoid truncation of length for very large buffers. crc32() takes
 | 
				
			||||||
           length as an unsigned int, which may be narrower than Py_ssize_t. */
 | 
					           length as an unsigned int, which may be narrower than Py_ssize_t. */
 | 
				
			||||||
        while ((size_t)len > UINT_MAX) {
 | 
					        while ((size_t)len > UINT_MAX) {
 | 
				
			||||||
            crc32val = crc32(crc32val, buf, UINT_MAX);
 | 
					            value = crc32(value, buf, UINT_MAX);
 | 
				
			||||||
            buf += (size_t) UINT_MAX;
 | 
					            buf += (size_t) UINT_MAX;
 | 
				
			||||||
            len -= (size_t) UINT_MAX;
 | 
					            len -= (size_t) UINT_MAX;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        signed_val = crc32(crc32val, buf, (unsigned int)len);
 | 
					        signed_val = crc32(value, buf, (unsigned int)len);
 | 
				
			||||||
        Py_END_ALLOW_THREADS
 | 
					        Py_END_ALLOW_THREADS
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        signed_val = crc32(crc32val, pbuf.buf, (unsigned int)pbuf.len);
 | 
					        signed_val = crc32(value, data->buf, (unsigned int)data->len);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    PyBuffer_Release(&pbuf);
 | 
					 | 
				
			||||||
    return PyLong_FromUnsignedLong(signed_val & 0xffffffffU);
 | 
					    return PyLong_FromUnsignedLong(signed_val & 0xffffffffU);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyMethodDef zlib_methods[] =
 | 
					static PyMethodDef zlib_methods[] =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    {"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS,
 | 
					    ZLIB_ADLER32_METHODDEF
 | 
				
			||||||
                adler32__doc__},
 | 
					 | 
				
			||||||
    ZLIB_COMPRESS_METHODDEF
 | 
					    ZLIB_COMPRESS_METHODDEF
 | 
				
			||||||
    {"compressobj", (PyCFunction)PyZlib_compressobj, METH_VARARGS|METH_KEYWORDS,
 | 
					    ZLIB_COMPRESSOBJ_METHODDEF
 | 
				
			||||||
                    compressobj__doc__},
 | 
					    ZLIB_CRC32_METHODDEF
 | 
				
			||||||
    {"crc32", (PyCFunction)PyZlib_crc32, METH_VARARGS,
 | 
					    ZLIB_DECOMPRESS_METHODDEF
 | 
				
			||||||
              crc32__doc__},
 | 
					    ZLIB_DECOMPRESSOBJ_METHODDEF
 | 
				
			||||||
    {"decompress", (PyCFunction)PyZlib_decompress, METH_VARARGS,
 | 
					 | 
				
			||||||
                   decompress__doc__},
 | 
					 | 
				
			||||||
    {"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS|METH_KEYWORDS,
 | 
					 | 
				
			||||||
                   decompressobj__doc__},
 | 
					 | 
				
			||||||
    {NULL, NULL}
 | 
					    {NULL, NULL}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1482,6 +1370,7 @@ PyInit_zlib(void)
 | 
				
			||||||
    PyModule_AddIntMacro(m, MAX_WBITS);
 | 
					    PyModule_AddIntMacro(m, MAX_WBITS);
 | 
				
			||||||
    PyModule_AddIntMacro(m, DEFLATED);
 | 
					    PyModule_AddIntMacro(m, DEFLATED);
 | 
				
			||||||
    PyModule_AddIntMacro(m, DEF_MEM_LEVEL);
 | 
					    PyModule_AddIntMacro(m, DEF_MEM_LEVEL);
 | 
				
			||||||
 | 
					    PyModule_AddIntMacro(m, DEF_BUF_SIZE);
 | 
				
			||||||
    PyModule_AddIntMacro(m, Z_BEST_SPEED);
 | 
					    PyModule_AddIntMacro(m, Z_BEST_SPEED);
 | 
				
			||||||
    PyModule_AddIntMacro(m, Z_BEST_COMPRESSION);
 | 
					    PyModule_AddIntMacro(m, Z_BEST_COMPRESSION);
 | 
				
			||||||
    PyModule_AddIntMacro(m, Z_DEFAULT_COMPRESSION);
 | 
					    PyModule_AddIntMacro(m, Z_DEFAULT_COMPRESSION);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue