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(PyObject *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((Compressor *)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(PyObject *self, PyObject *Py_UNUSED(ignored))
67 {
68 return _lzma_LZMACompressor_flush_impl((Compressor *)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(PyObject *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 Py_hash_t ob_hash;
108 PyObject *ob_item[NUM_KEYWORDS];
109 } _kwtuple = {
110 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
111 .ob_hash = -1,
112 .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
113 };
114 #undef NUM_KEYWORDS
115 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
116
117 #else // !Py_BUILD_CORE
118 # define KWTUPLE NULL
119 #endif // !Py_BUILD_CORE
120
121 static const char * const _keywords[] = {"data", "max_length", NULL};
122 static _PyArg_Parser _parser = {
123 .keywords = _keywords,
124 .fname = "decompress",
125 .kwtuple = KWTUPLE,
126 };
127 #undef KWTUPLE
128 PyObject *argsbuf[2];
129 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
130 Py_buffer data = {NULL, NULL};
131 Py_ssize_t max_length = -1;
132
133 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
134 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 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 (!noptargs) {
142 goto skip_optional_pos;
143 }
144 {
145 Py_ssize_t ival = -1;
146 PyObject *iobj = _PyNumber_Index(args[1]);
147 if (iobj != NULL) {
148 ival = PyLong_AsSsize_t(iobj);
149 Py_DECREF(iobj);
150 }
151 if (ival == -1 && PyErr_Occurred()) {
152 goto exit;
153 }
154 max_length = ival;
155 }
156 skip_optional_pos:
157 return_value = _lzma_LZMADecompressor_decompress_impl((Decompressor *)self, &data, max_length);
158
159 exit:
160 /* Cleanup for data */
161 if (data.obj) {
162 PyBuffer_Release(&data);
163 }
164
165 return return_value;
166 }
167
168 PyDoc_STRVAR(_lzma_LZMADecompressor__doc__,
169 "LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)\n"
170 "--\n"
171 "\n"
172 "Create a decompressor object for decompressing data incrementally.\n"
173 "\n"
174 " format\n"
175 " Specifies the container format of the input stream. If this is\n"
176 " FORMAT_AUTO (the default), the decompressor will automatically detect\n"
177 " whether the input is FORMAT_XZ or FORMAT_ALONE. Streams created with\n"
178 " FORMAT_RAW cannot be autodetected.\n"
179 " memlimit\n"
180 " Limit the amount of memory used by the decompressor. This will cause\n"
181 " decompression to fail if the input cannot be decompressed within the\n"
182 " given limit.\n"
183 " filters\n"
184 " A custom filter chain. This argument is required for FORMAT_RAW, and\n"
185 " not accepted with any other format. When provided, this should be a\n"
186 " sequence of dicts, each indicating the ID and options for a single\n"
187 " filter.\n"
188 "\n"
189 "For one-shot decompression, use the decompress() function instead.");
190
191 static PyObject *
192 _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
193 PyObject *memlimit, PyObject *filters);
194
195 static PyObject *
196 _lzma_LZMADecompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
197 {
198 PyObject *return_value = NULL;
199 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
200
201 #define NUM_KEYWORDS 3
202 static struct {
203 PyGC_Head _this_is_not_used;
204 PyObject_VAR_HEAD
205 Py_hash_t ob_hash;
206 PyObject *ob_item[NUM_KEYWORDS];
207 } _kwtuple = {
208 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
209 .ob_hash = -1,
210 .ob_item = { &_Py_ID(format), &_Py_ID(memlimit), &_Py_ID(filters), },
211 };
212 #undef NUM_KEYWORDS
213 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
214
215 #else // !Py_BUILD_CORE
216 # define KWTUPLE NULL
217 #endif // !Py_BUILD_CORE
218
219 static const char * const _keywords[] = {"format", "memlimit", "filters", NULL};
220 static _PyArg_Parser _parser = {
221 .keywords = _keywords,
222 .fname = "LZMADecompressor",
223 .kwtuple = KWTUPLE,
224 };
225 #undef KWTUPLE
226 PyObject *argsbuf[3];
227 PyObject * const *fastargs;
228 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
229 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
230 int format = FORMAT_AUTO;
231 PyObject *memlimit = Py_None;
232 PyObject *filters = Py_None;
233
234 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
235 /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
236 if (!fastargs) {
237 goto exit;
238 }
239 if (!noptargs) {
240 goto skip_optional_pos;
241 }
242 if (fastargs[0]) {
243 format = PyLong_AsInt(fastargs[0]);
244 if (format == -1 && PyErr_Occurred()) {
245 goto exit;
246 }
247 if (!--noptargs) {
248 goto skip_optional_pos;
249 }
250 }
251 if (fastargs[1]) {
252 memlimit = fastargs[1];
253 if (!--noptargs) {
254 goto skip_optional_pos;
255 }
256 }
257 filters = fastargs[2];
258 skip_optional_pos:
259 return_value = _lzma_LZMADecompressor_impl(type, format, memlimit, filters);
260
261 exit:
262 return return_value;
263 }
264
265 PyDoc_STRVAR(_lzma_is_check_supported__doc__,
266 "is_check_supported($module, check_id, /)\n"
267 "--\n"
268 "\n"
269 "Test whether the given integrity check is supported.\n"
270 "\n"
271 "Always returns True for CHECK_NONE and CHECK_CRC32.");
272
273 #define _LZMA_IS_CHECK_SUPPORTED_METHODDEF \
274 {"is_check_supported", (PyCFunction)_lzma_is_check_supported, METH_O, _lzma_is_check_supported__doc__},
275
276 static PyObject *
277 _lzma_is_check_supported_impl(PyObject *module, int check_id);
278
279 static PyObject *
280 _lzma_is_check_supported(PyObject *module, PyObject *arg)
281 {
282 PyObject *return_value = NULL;
283 int check_id;
284
285 check_id = PyLong_AsInt(arg);
286 if (check_id == -1 && PyErr_Occurred()) {
287 goto exit;
288 }
289 return_value = _lzma_is_check_supported_impl(module, check_id);
290
291 exit:
292 return return_value;
293 }
294
295 PyDoc_STRVAR(_lzma__decode_filter_properties__doc__,
296 "_decode_filter_properties($module, filter_id, encoded_props, /)\n"
297 "--\n"
298 "\n"
299 "Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict).\n"
300 "\n"
301 "The result does not include the filter ID itself, only the options.");
302
303 #define _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF \
304 {"_decode_filter_properties", _PyCFunction_CAST(_lzma__decode_filter_properties), METH_FASTCALL, _lzma__decode_filter_properties__doc__},
305
306 static PyObject *
307 _lzma__decode_filter_properties_impl(PyObject *module, lzma_vli filter_id,
308 Py_buffer *encoded_props);
309
310 static PyObject *
311 _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
312 {
313 PyObject *return_value = NULL;
314 lzma_vli filter_id;
315 Py_buffer encoded_props = {NULL, NULL};
316
317 if (!_PyArg_CheckPositional("_decode_filter_properties", nargs, 2, 2)) {
318 goto exit;
319 }
320 if (!lzma_vli_converter(args[0], &filter_id)) {
321 goto exit;
322 }
323 if (PyObject_GetBuffer(args[1], &encoded_props, PyBUF_SIMPLE) != 0) {
324 goto exit;
325 }
326 return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
327
328 exit:
329 /* Cleanup for encoded_props */
330 if (encoded_props.obj) {
331 PyBuffer_Release(&encoded_props);
332 }
333
334 return return_value;
335 }
336 /*[clinic end generated code: output=6386084cb43d2533 input=a9049054013a1b77]*/