Debian Codegraph @

Modules/clinic/_lzmamodule.c.h

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