(root)/
Python-3.12.0/
Modules/
clinic/
_lzmamodule.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6  #  include "pycore_gc.h"            // PyGC_Head
       7  #  include "pycore_runtime.h"       // _Py_ID()
       8  #endif
       9  
      10  
      11  PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__,
      12  "compress($self, data, /)\n"
      13  "--\n"
      14  "\n"
      15  "Provide data to the compressor object.\n"
      16  "\n"
      17  "Returns a chunk of compressed data if possible, or b\'\' otherwise.\n"
      18  "\n"
      19  "When you have finished providing data to the compressor, call the\n"
      20  "flush() method to finish the compression process.");
      21  
      22  #define _LZMA_LZMACOMPRESSOR_COMPRESS_METHODDEF    \
      23      {"compress", (PyCFunction)_lzma_LZMACompressor_compress, METH_O, _lzma_LZMACompressor_compress__doc__},
      24  
      25  static PyObject *
      26  _lzma_LZMACompressor_compress_impl(Compressor *self, Py_buffer *data);
      27  
      28  static PyObject *
      29  _lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
      30  {
      31      PyObject *return_value = NULL;
      32      Py_buffer data = {NULL, NULL};
      33  
      34      if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
      35          goto exit;
      36      }
      37      if (!PyBuffer_IsContiguous(&data, 'C')) {
      38          _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
      39          goto exit;
      40      }
      41      return_value = _lzma_LZMACompressor_compress_impl(self, &data);
      42  
      43  exit:
      44      /* Cleanup for data */
      45      if (data.obj) {
      46         PyBuffer_Release(&data);
      47      }
      48  
      49      return return_value;
      50  }
      51  
      52  PyDoc_STRVAR(_lzma_LZMACompressor_flush__doc__,
      53  "flush($self, /)\n"
      54  "--\n"
      55  "\n"
      56  "Finish the compression process.\n"
      57  "\n"
      58  "Returns the compressed data left in internal buffers.\n"
      59  "\n"
      60  "The compressor object may not be used after this method is called.");
      61  
      62  #define _LZMA_LZMACOMPRESSOR_FLUSH_METHODDEF    \
      63      {"flush", (PyCFunction)_lzma_LZMACompressor_flush, METH_NOARGS, _lzma_LZMACompressor_flush__doc__},
      64  
      65  static PyObject *
      66  _lzma_LZMACompressor_flush_impl(Compressor *self);
      67  
      68  static PyObject *
      69  _lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored))
      70  {
      71      return _lzma_LZMACompressor_flush_impl(self);
      72  }
      73  
      74  PyDoc_STRVAR(_lzma_LZMADecompressor_decompress__doc__,
      75  "decompress($self, /, data, max_length=-1)\n"
      76  "--\n"
      77  "\n"
      78  "Decompress *data*, returning uncompressed data as bytes.\n"
      79  "\n"
      80  "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
      81  "decompressed data. If this limit is reached and further output can be\n"
      82  "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
      83  "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
      84  "\n"
      85  "If all of the input data was decompressed and returned (either because this\n"
      86  "was less than *max_length* bytes, or because *max_length* was negative),\n"
      87  "*self.needs_input* will be set to True.\n"
      88  "\n"
      89  "Attempting to decompress data after the end of stream is reached raises an\n"
      90  "EOFError.  Any data found after the end of the stream is ignored and saved in\n"
      91  "the unused_data attribute.");
      92  
      93  #define _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF    \
      94      {"decompress", _PyCFunction_CAST(_lzma_LZMADecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _lzma_LZMADecompressor_decompress__doc__},
      95  
      96  static PyObject *
      97  _lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data,
      98                                         Py_ssize_t max_length);
      99  
     100  static PyObject *
     101  _lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     102  {
     103      PyObject *return_value = NULL;
     104      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     105  
     106      #define NUM_KEYWORDS 2
     107      static struct {
     108          PyGC_Head _this_is_not_used;
     109          PyObject_VAR_HEAD
     110          PyObject *ob_item[NUM_KEYWORDS];
     111      } _kwtuple = {
     112          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     113          .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
     114      };
     115      #undef NUM_KEYWORDS
     116      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     117  
     118      #else  // !Py_BUILD_CORE
     119      #  define KWTUPLE NULL
     120      #endif  // !Py_BUILD_CORE
     121  
     122      static const char * const _keywords[] = {"data", "max_length", NULL};
     123      static _PyArg_Parser _parser = {
     124          .keywords = _keywords,
     125          .fname = "decompress",
     126          .kwtuple = KWTUPLE,
     127      };
     128      #undef KWTUPLE
     129      PyObject *argsbuf[2];
     130      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     131      Py_buffer data = {NULL, NULL};
     132      Py_ssize_t max_length = -1;
     133  
     134      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
     135      if (!args) {
     136          goto exit;
     137      }
     138      if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     139          goto exit;
     140      }
     141      if (!PyBuffer_IsContiguous(&data, 'C')) {
     142          _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
     143          goto exit;
     144      }
     145      if (!noptargs) {
     146          goto skip_optional_pos;
     147      }
     148      {
     149          Py_ssize_t ival = -1;
     150          PyObject *iobj = _PyNumber_Index(args[1]);
     151          if (iobj != NULL) {
     152              ival = PyLong_AsSsize_t(iobj);
     153              Py_DECREF(iobj);
     154          }
     155          if (ival == -1 && PyErr_Occurred()) {
     156              goto exit;
     157          }
     158          max_length = ival;
     159      }
     160  skip_optional_pos:
     161      return_value = _lzma_LZMADecompressor_decompress_impl(self, &data, max_length);
     162  
     163  exit:
     164      /* Cleanup for data */
     165      if (data.obj) {
     166         PyBuffer_Release(&data);
     167      }
     168  
     169      return return_value;
     170  }
     171  
     172  PyDoc_STRVAR(_lzma_LZMADecompressor__doc__,
     173  "LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)\n"
     174  "--\n"
     175  "\n"
     176  "Create a decompressor object for decompressing data incrementally.\n"
     177  "\n"
     178  "  format\n"
     179  "    Specifies the container format of the input stream.  If this is\n"
     180  "    FORMAT_AUTO (the default), the decompressor will automatically detect\n"
     181  "    whether the input is FORMAT_XZ or FORMAT_ALONE.  Streams created with\n"
     182  "    FORMAT_RAW cannot be autodetected.\n"
     183  "  memlimit\n"
     184  "    Limit the amount of memory used by the decompressor.  This will cause\n"
     185  "    decompression to fail if the input cannot be decompressed within the\n"
     186  "    given limit.\n"
     187  "  filters\n"
     188  "    A custom filter chain.  This argument is required for FORMAT_RAW, and\n"
     189  "    not accepted with any other format.  When provided, this should be a\n"
     190  "    sequence of dicts, each indicating the ID and options for a single\n"
     191  "    filter.\n"
     192  "\n"
     193  "For one-shot decompression, use the decompress() function instead.");
     194  
     195  static PyObject *
     196  _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
     197                              PyObject *memlimit, PyObject *filters);
     198  
     199  static PyObject *
     200  _lzma_LZMADecompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     201  {
     202      PyObject *return_value = NULL;
     203      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     204  
     205      #define NUM_KEYWORDS 3
     206      static struct {
     207          PyGC_Head _this_is_not_used;
     208          PyObject_VAR_HEAD
     209          PyObject *ob_item[NUM_KEYWORDS];
     210      } _kwtuple = {
     211          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     212          .ob_item = { &_Py_ID(format), &_Py_ID(memlimit), &_Py_ID(filters), },
     213      };
     214      #undef NUM_KEYWORDS
     215      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     216  
     217      #else  // !Py_BUILD_CORE
     218      #  define KWTUPLE NULL
     219      #endif  // !Py_BUILD_CORE
     220  
     221      static const char * const _keywords[] = {"format", "memlimit", "filters", NULL};
     222      static _PyArg_Parser _parser = {
     223          .keywords = _keywords,
     224          .fname = "LZMADecompressor",
     225          .kwtuple = KWTUPLE,
     226      };
     227      #undef KWTUPLE
     228      PyObject *argsbuf[3];
     229      PyObject * const *fastargs;
     230      Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     231      Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
     232      int format = FORMAT_AUTO;
     233      PyObject *memlimit = Py_None;
     234      PyObject *filters = Py_None;
     235  
     236      fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
     237      if (!fastargs) {
     238          goto exit;
     239      }
     240      if (!noptargs) {
     241          goto skip_optional_pos;
     242      }
     243      if (fastargs[0]) {
     244          format = _PyLong_AsInt(fastargs[0]);
     245          if (format == -1 && PyErr_Occurred()) {
     246              goto exit;
     247          }
     248          if (!--noptargs) {
     249              goto skip_optional_pos;
     250          }
     251      }
     252      if (fastargs[1]) {
     253          memlimit = fastargs[1];
     254          if (!--noptargs) {
     255              goto skip_optional_pos;
     256          }
     257      }
     258      filters = fastargs[2];
     259  skip_optional_pos:
     260      return_value = _lzma_LZMADecompressor_impl(type, format, memlimit, filters);
     261  
     262  exit:
     263      return return_value;
     264  }
     265  
     266  PyDoc_STRVAR(_lzma_is_check_supported__doc__,
     267  "is_check_supported($module, check_id, /)\n"
     268  "--\n"
     269  "\n"
     270  "Test whether the given integrity check is supported.\n"
     271  "\n"
     272  "Always returns True for CHECK_NONE and CHECK_CRC32.");
     273  
     274  #define _LZMA_IS_CHECK_SUPPORTED_METHODDEF    \
     275      {"is_check_supported", (PyCFunction)_lzma_is_check_supported, METH_O, _lzma_is_check_supported__doc__},
     276  
     277  static PyObject *
     278  _lzma_is_check_supported_impl(PyObject *module, int check_id);
     279  
     280  static PyObject *
     281  _lzma_is_check_supported(PyObject *module, PyObject *arg)
     282  {
     283      PyObject *return_value = NULL;
     284      int check_id;
     285  
     286      check_id = _PyLong_AsInt(arg);
     287      if (check_id == -1 && PyErr_Occurred()) {
     288          goto exit;
     289      }
     290      return_value = _lzma_is_check_supported_impl(module, check_id);
     291  
     292  exit:
     293      return return_value;
     294  }
     295  
     296  PyDoc_STRVAR(_lzma__decode_filter_properties__doc__,
     297  "_decode_filter_properties($module, filter_id, encoded_props, /)\n"
     298  "--\n"
     299  "\n"
     300  "Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict).\n"
     301  "\n"
     302  "The result does not include the filter ID itself, only the options.");
     303  
     304  #define _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF    \
     305      {"_decode_filter_properties", _PyCFunction_CAST(_lzma__decode_filter_properties), METH_FASTCALL, _lzma__decode_filter_properties__doc__},
     306  
     307  static PyObject *
     308  _lzma__decode_filter_properties_impl(PyObject *module, lzma_vli filter_id,
     309                                       Py_buffer *encoded_props);
     310  
     311  static PyObject *
     312  _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     313  {
     314      PyObject *return_value = NULL;
     315      lzma_vli filter_id;
     316      Py_buffer encoded_props = {NULL, NULL};
     317  
     318      if (!_PyArg_CheckPositional("_decode_filter_properties", nargs, 2, 2)) {
     319          goto exit;
     320      }
     321      if (!lzma_vli_converter(args[0], &filter_id)) {
     322          goto exit;
     323      }
     324      if (PyObject_GetBuffer(args[1], &encoded_props, PyBUF_SIMPLE) != 0) {
     325          goto exit;
     326      }
     327      if (!PyBuffer_IsContiguous(&encoded_props, 'C')) {
     328          _PyArg_BadArgument("_decode_filter_properties", "argument 2", "contiguous buffer", args[1]);
     329          goto exit;
     330      }
     331      return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
     332  
     333  exit:
     334      /* Cleanup for encoded_props */
     335      if (encoded_props.obj) {
     336         PyBuffer_Release(&encoded_props);
     337      }
     338  
     339      return return_value;
     340  }
     341  /*[clinic end generated code: output=96c1fbdada1ef232 input=a9049054013a1b77]*/