cpython: 7ba9642fc800 (original) (raw)

--- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -298,36 +298,37 @@ parse_filter_spec_bcj(PyObject *spec) return options; } -static void * -parse_filter_spec(lzma_filter *f, PyObject *spec) +static int +lzma_filter_converter(PyObject *spec, void *ptr) {

switch (f->id) { case LZMA_FILTER_LZMA1: case LZMA_FILTER_LZMA2: f->options = parse_filter_spec_lzma(spec);

@@ -335,10 +336,10 @@ parse_filter_spec(lzma_filter *f, PyObje case LZMA_FILTER_ARMTHUMB: case LZMA_FILTER_SPARC: f->options = parse_filter_spec_bcj(spec);

@@ -468,6 +469,36 @@ error: } +/[clinic input] +output preset file +module _lzma +class _lzma.LZMACompressor +class _lzma.LZMADecompressor +[clinic start generated code]/ +/[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]/ + +#include "_lzmamodule.clinic.c" + +/*[python input] + +class lzma_vli_converter(CConverter):

+ +class lzma_filter_converter(CConverter):

+

+ +[python start generated code]/ +/[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]/ + + / LZMACompressor class. */ static PyObject @@ -512,44 +543,51 @@ error: return NULL; } -PyDoc_STRVAR(Compressor_compress_doc, -"compress(data) -> bytes\n" -"\n" -"Provide data to the compressor object. Returns a chunk of\n" -"compressed data if possible, or b"" otherwise.\n" -"\n" -"When you have finished providing data to the compressor, call the\n" -"flush() method to finish the conversion process.\n"); +/[clinic input] +_lzma.LZMACompressor.compress +

+ +Provide data to the compressor object. + +Returns a chunk of compressed data if possible, or b'' otherwise. + +When you have finished providing data to the compressor, call the +flush() method to finish the compression process. +[clinic start generated code]*/ static PyObject * -Compressor_compress(Compressor *self, PyObject *args) +_lzma_LZMACompressor_compress_impl(Compressor self, Py_buffer data) +/[clinic end generated code: checksum=31f615136963e00f26f8be33440ec1e3604565ba]/ {

- ACQUIRE_LOCK(self); if (self->flushed) PyErr_SetString(PyExc_ValueError, "Compressor has been flushed"); else

-PyDoc_STRVAR(Compressor_flush_doc, -"flush() -> bytes\n" -"\n" -"Finish the compression process. Returns the compressed data left\n" -"in internal buffers.\n" -"\n" -"The compressor object cannot be used after this method is called.\n"); +/*[clinic input] +_lzma.LZMACompressor.flush +

+ +Finish the compression process. + +Returns the compressed data left in internal buffers. + +The compressor object may not be used after this method is called. +[clinic start generated code]*/ static PyObject * -Compressor_flush(Compressor *self, PyObject noargs) +_lzma_LZMACompressor_flush_impl(Compressor self) +/[clinic end generated code: checksum=fec21f3e22504f500606ba60e1ba70d79eb22188]/ { PyObject *result = NULL; @@ -650,6 +688,39 @@ Compressor_init_raw(lzma_stream lzs, Py return 0; } +/[-clinic input] +_lzma.LZMACompressor.init +

+

+

+

+ +Create a compressor object for compressing data incrementally. + +The settings used by the compressor can be specified either as a +preset compression level (with the 'preset' argument), or in detail +as a custom filter chain (with the 'filters' argument). For FORMAT_XZ +and FORMAT_ALONE, the default is to use the PRESET_DEFAULT preset +level. For FORMAT_RAW, the caller must always specify a filter chain; +the raw compressor does not support preset compression levels. + +For one-shot compression, use the compress() function instead. +[-clinic start generated code]*/ static int Compressor_init(Compressor *self, PyObject *args, PyObject *kwargs) { @@ -739,10 +810,8 @@ Compressor_dealloc(Compressor *self) } static PyMethodDef Compressor_methods[] = {

-PyDoc_STRVAR(Decompressor_decompress_doc, -"decompress(data) -> bytes\n" -"\n" -"Provide data to the decompressor object. Returns a chunk of\n" -"decompressed data if possible, or b"" otherwise.\n" -"\n" -"Attempting to decompress data after the end of the stream is\n" -"reached raises an EOFError. Any data found after the end of the\n" -"stream is ignored, and saved in the unused_data attribute.\n"); +/*[clinic input] +_lzma.LZMADecompressor.decompress +

+ +Provide data to the decompressor object. + +Returns a chunk of decompressed data if possible, or b'' otherwise. + +Attempting to decompress data after the end of stream is reached +raises an EOFError. Any data found after the end of the stream +is ignored and saved in the unused_data attribute. +[clinic start generated code]*/ static PyObject * -Decompressor_decompress(Decompressor *self, PyObject *args) +_lzma_LZMADecompressor_decompress_impl(Decompressor self, Py_buffer data) +/[clinic end generated code: checksum=d86e78da7ff0ff219d511275b16b79476da8922e]/ {

- ACQUIRE_LOCK(self); if (self->eof) PyErr_SetString(PyExc_EOFError, "Already at end of stream"); else

@@ -925,38 +996,56 @@ Decompressor_init_raw(lzma_stream lzs, return 0; } +/[clinic input] +_lzma.LZMADecompressor.init +

+

+

+ +Create a decompressor object for decompressing data incrementally. + +For one-shot decompression, use the decompress() function instead. +[clinic start generated code]*/ + static int -Decompressor_init(Decompressor *self, PyObject *args, PyObject *kwargs) +_lzma_LZMADecompressor___init___impl(Decompressor *self, int format, PyObject memlimit, PyObject filters) +/[clinic end generated code: checksum=9b119f6f2cc2d7a8e5be41c164a6c080ee82d0c2]/ {

-

@@ -982,27 +1071,27 @@ Decompressor_init(Decompressor *self, Py switch (format) { case FORMAT_AUTO:

case FORMAT_XZ:

case FORMAT_ALONE: self->check = LZMA_CHECK_NONE;

case FORMAT_RAW: self->check = LZMA_CHECK_NONE;

@@ -1034,8 +1123,7 @@ Decompressor_dealloc(Decompressor *self) } static PyMethodDef Decompressor_methods[] = {

+ +Test whether the given integrity check is supported. + +Always returns True for CHECK_NONE and CHECK_CRC32. +[clinic start generated code]*/ static PyObject * -is_check_supported(PyObject *self, PyObject args) +_lzma_is_check_supported_impl(PyModuleDef module, int check_id) +/[clinic end generated code: checksum=bb828e90e00ad96ed61f66719c2fca7fde637418]/ {

-

- return PyBool_FromLong(lzma_check_is_supported(check_id)); } -PyDoc_STRVAR(_encode_filter_properties_doc, -"_encode_filter_properties(filter) -> bytes\n" -"\n" -"Return a bytes object encoding the options (properties) of the filter\n" -"specified by filter (a dict).\n" -"\n" -"The result does not include the filter ID itself, only the options.\n"); +/*[clinic input] +_lzma._encode_filter_properties

+ +Return a bytes object encoding the options (properties) of the filter specified by filter (a dict). + +The result does not include the filter ID itself, only the options. +[clinic start generated code]*/ static PyObject * -_encode_filter_properties(PyObject *self, PyObject args) +_lzma__encode_filter_properties_impl(PyModuleDef module, lzma_filter filter) +/[clinic end generated code: checksum=b5fe690acd6b61d1abfc32f522ada5bdcf9b13da]/ {

-

- lzret = lzma_properties_size(&encoded_size, &filter); if (catch_lzma_error(lzret)) goto error; @@ -1179,37 +1240,36 @@ static PyObject * if (catch_lzma_error(lzret)) goto error;

-PyDoc_STRVAR(_decode_filter_properties_doc, -"_decode_filter_properties(filter_id, encoded_props) -> dict\n" -"\n" -"Return a dict describing a filter with ID filter_id, and options\n" -"(properties) decoded from the bytes object encoded_props.\n"); +/*[clinic input] +_lzma._decode_filter_properties

+ +Return a bytes object encoding the options (properties) of the filter specified by filter (a dict). + +The result does not include the filter ID itself, only the options. +[clinic start generated code]*/ static PyObject * -_decode_filter_properties(PyObject *self, PyObject *args) +_lzma__decode_filter_properties_impl(PyModuleDef module, lzma_vli filter_id, Py_buffer encoded_props) +/[clinic end generated code: checksum=235f7f5345d48744dcd21f781dafbbf05a717538]/ {

lzret = lzma_properties_decode(

@@ -1225,12 +1285,9 @@ static PyObject / Module initialization. */ static PyMethodDef module_methods[] = {

new file mode 100644 --- /dev/null +++ b/Modules/lzmamodule.clinic.c @@ -0,0 +1,231 @@ +/[clinic input] +preserve +[clinic start generated code]/ + +PyDoc_STRVAR(lzma_LZMACompressor_compress__doc, +"compress(self, data)\n" +"Provide data to the compressor object.\n" +"\n" +"Returns a chunk of compressed data if possible, or b'' otherwise.\n" +"\n" +"When you have finished providing data to the compressor, call the\n" +"flush() method to finish the compression process."); + +#define _LZMA_LZMACOMPRESSOR_COMPRESS_METHODDEF [](#l2.18)

+ +static PyObject * +_lzma_LZMACompressor_compress_impl(Compressor *self, Py_buffer *data); + +static PyObject * +_lzma_LZMACompressor_compress(Compressor *self, PyObject *args) +{

+

+ +exit:

+

+} + +PyDoc_STRVAR(lzma_LZMACompressor_flush__doc_, +"flush(self)\n" +"Finish the compression process.\n" +"\n" +"Returns the compressed data left in internal buffers.\n" +"\n" +"The compressor object may not be used after this method is called."); + +#define _LZMA_LZMACOMPRESSOR_FLUSH_METHODDEF [](#l2.52)

+ +static PyObject * +_lzma_LZMACompressor_flush_impl(Compressor *self); + +static PyObject * +_lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored)) +{

+} + +PyDoc_STRVAR(lzma_LZMADecompressor_decompress__doc_, +"decompress(self, data)\n" +"Provide data to the decompressor object.\n" +"\n" +"Returns a chunk of decompressed data if possible, or b'' otherwise.\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."); + +#define _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF [](#l2.74)

+ +static PyObject * +_lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data); + +static PyObject * +_lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *args) +{

+

+ +exit:

+

+} + +PyDoc_STRVAR(lzma_LZMADecompressor___init____doc_, +"LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)\n" +"Create a decompressor object for decompressing data incrementally.\n" +"\n" +" format\n" +" Specifies the container format of the input stream. If this is\n" +" FORMAT_AUTO (the default), the decompressor will automatically detect\n" +" whether the input is FORMAT_XZ or FORMAT_ALONE. Streams created with\n" +" FORMAT_RAW cannot be autodetected.\n" +" memlimit\n" +" Limit the amount of memory used by the decompressor. This will cause\n" +" decompression to fail if the input cannot be decompressed within the\n" +" given limit.\n" +" filters\n" +" A custom filter chain. This argument is required for FORMAT_RAW, and\n" +" not accepted with any other format. When provided, this should be a\n" +" sequence of dicts, each indicating the ID and options for a single\n" +" filter.\n" +"\n" +"For one-shot decompression, use the decompress() function instead."); + +static int +lzma_LZMADecompressor___init___impl(Decompressor *self, int format, PyObject *memlimit, PyObject *filters); + +static int +lzma_LZMADecompressor___init(PyObject *self, PyObject *args, PyObject *kwargs) +{

+

+ +exit:

+} + +PyDoc_STRVAR(lzma_is_check_supported__doc_, +"is_check_supported(module, check_id)\n" +"Test whether the given integrity check is supported.\n" +"\n" +"Always returns True for CHECK_NONE and CHECK_CRC32."); + +#define _LZMA_IS_CHECK_SUPPORTED_METHODDEF [](#l2.149)

+ +static PyObject * +_lzma_is_check_supported_impl(PyModuleDef *module, int check_id); + +static PyObject * +_lzma_is_check_supported(PyModuleDef *module, PyObject *args) +{

+

+ +exit:

+} + +PyDoc_STRVAR(lzma__encode_filter_properties__doc_, +"_encode_filter_properties(module, filter)\n" +"Return a bytes object encoding the options (properties) of the filter specified by filter (a dict).\n" +"\n" +"The result does not include the filter ID itself, only the options."); + +#define _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF [](#l2.177)

+ +static PyObject * +_lzma__encode_filter_properties_impl(PyModuleDef *module, lzma_filter filter); + +static PyObject * +_lzma__encode_filter_properties(PyModuleDef *module, PyObject *args) +{

+

+ +exit:

+

+} + +PyDoc_STRVAR(lzma__decode_filter_properties__doc_, +"_decode_filter_properties(module, filter_id, encoded_props)\n" +"Return a bytes object encoding the options (properties) of the filter specified by filter (a dict).\n" +"\n" +"The result does not include the filter ID itself, only the options."); + +#define _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF [](#l2.209)

+ +static PyObject * +_lzma__decode_filter_properties_impl(PyModuleDef *module, lzma_vli filter_id, Py_buffer *encoded_props); + +static PyObject * +_lzma__decode_filter_properties(PyModuleDef *module, PyObject *args) +{

+

+ +exit:

+

+} +/[clinic end generated code: checksum=b4b90dcbd0c9c349c3a94e26a7eecf71aab179a0]/