summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-01-17 15:22:18 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-01-17 15:22:18 (GMT)
commit26795baaa812c74087e97f9119ec143451e23daa (patch)
tree2f9926c2fa66ab7d22fa0c842860b42cd38f7726 /Modules/clinic
parente262074ede78087c079094e28bb1d09a40072471 (diff)
downloadcpython-26795baaa812c74087e97f9119ec143451e23daa.zip
cpython-26795baaa812c74087e97f9119ec143451e23daa.tar.gz
cpython-26795baaa812c74087e97f9119ec143451e23daa.tar.bz2
Issue #15955: Add an option to limit output size when decompressing LZMA data.
Patch by Nikolaus Rath and Martin Panter.
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_lzmamodule.c.h37
1 files changed, 23 insertions, 14 deletions
diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h
index c1ad882..a46a152 100644
--- a/Modules/clinic/_lzmamodule.c.h
+++ b/Modules/clinic/_lzmamodule.c.h
@@ -62,34 +62,43 @@ _lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored))
}
PyDoc_STRVAR(_lzma_LZMADecompressor_decompress__doc__,
-"decompress($self, data, /)\n"
+"decompress($self, /, data, max_length=-1)\n"
"--\n"
"\n"
-"Provide data to the decompressor object.\n"
+"Decompresses *data*, returning uncompressed data as bytes.\n"
"\n"
-"Returns a chunk of decompressed data if possible, or b\'\' otherwise.\n"
+"If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
+"decompressed data. If this limit is reached and further output can be\n"
+"produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
+"call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
"\n"
-"Attempting to decompress data after the end of stream is reached\n"
-"raises an EOFError. Any data found after the end of the stream\n"
-"is ignored and saved in the unused_data attribute.");
+"If all of the input data was decompressed and returned (either because this\n"
+"was less than *max_length* bytes, or because *max_length* was negative),\n"
+"*self.needs_input* will be set to True.\n"
+"\n"
+"Attempting to decompress data after the end of stream is reached raises an\n"
+"EOFError. Any data found after the end of the stream is ignored and saved in\n"
+"the unused_data attribute.");
#define _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF \
- {"decompress", (PyCFunction)_lzma_LZMADecompressor_decompress, METH_VARARGS, _lzma_LZMADecompressor_decompress__doc__},
+ {"decompress", (PyCFunction)_lzma_LZMADecompressor_decompress, METH_VARARGS|METH_KEYWORDS, _lzma_LZMADecompressor_decompress__doc__},
static PyObject *
-_lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data);
+_lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data, Py_ssize_t max_length);
static PyObject *
-_lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *args)
+_lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
+ static char *_keywords[] = {"data", "max_length", NULL};
Py_buffer data = {NULL, NULL};
+ Py_ssize_t max_length = -1;
- if (!PyArg_ParseTuple(args,
- "y*:decompress",
- &data))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "y*|n:decompress", _keywords,
+ &data, &max_length))
goto exit;
- return_value = _lzma_LZMADecompressor_decompress_impl(self, &data);
+ return_value = _lzma_LZMADecompressor_decompress_impl(self, &data, max_length);
exit:
/* Cleanup for data */
@@ -242,4 +251,4 @@ exit:
return return_value;
}
-/*[clinic end generated code: output=808fec8216ac712b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d17fac38b09626d8 input=a9049054013a1b77]*/