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\n"
78 "of decompressed data. If this limit is reached and further output\n"
79 "can be produced, *self.needs_input* will be set to ``False``. In\n"
80 "this case, the next call to *decompress()* may provide *data* as b\'\'\n"
81 "to obtain more of the output.\n"
82 "\n"
83 "If all of the input data was decompressed and returned (either\n"
84 "because this was less than *max_length* bytes, or because\n"
85 "*max_length* was negative), *self.needs_input* will be set to True.\n"
86 "\n"
87 "Attempting to decompress data after the end of stream is reached\n"
88 "raises an EOFError. Any data found after the end of the stream is\n"
89 "ignored and saved in the unused_data attribute.");
90
91 #define _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF \
92 {"decompress", _PyCFunction_CAST(_lzma_LZMADecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _lzma_LZMADecompressor_decompress__doc__},
93
94 static PyObject *
95 _lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data,
96 Py_ssize_t max_length);
97
98 static PyObject *
99 _lzma_LZMADecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
100 {
101 PyObject *return_value = NULL;
102 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
103
104 #define NUM_KEYWORDS 2
105 static struct {
106 PyGC_Head _this_is_not_used;
107 PyObject_VAR_HEAD
108 Py_hash_t ob_hash;
109 PyObject *ob_item[NUM_KEYWORDS];
110 } _kwtuple = {
111 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
112 .ob_hash = -1,
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,
135 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
136 if (!args) {
137 goto exit;
138 }
139 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
140 goto exit;
141 }
142 if (!noptargs) {
143 goto skip_optional_pos;
144 }
145 {
146 Py_ssize_t ival = -1;
147 PyObject *iobj = _PyNumber_Index(args[1]);
148 if (iobj != NULL) {
149 ival = PyLong_AsSsize_t(iobj);
150 Py_DECREF(iobj);
151 }
152 if (ival == -1 && PyErr_Occurred()) {
153 goto exit;
154 }
155 max_length = ival;
156 }
157 skip_optional_pos:
158 return_value = _lzma_LZMADecompressor_decompress_impl((Decompressor *)self, &data, max_length);
159
160 exit:
161 /* Cleanup for data */
162 if (data.obj) {
163 PyBuffer_Release(&data);
164 }
165
166 return return_value;
167 }
168
169 PyDoc_STRVAR(_lzma_LZMADecompressor__doc__,
170 "LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)\n"
171 "--\n"
172 "\n"
173 "Create a decompressor object for decompressing data incrementally.\n"
174 "\n"
175 " format\n"
176 " Specifies the container format of the input stream. If this is\n"
177 " FORMAT_AUTO (the default), the decompressor will automatically detect\n"
178 " whether the input is FORMAT_XZ or FORMAT_ALONE. Streams created with\n"
179 " FORMAT_RAW cannot be autodetected.\n"
180 " memlimit\n"
181 " Limit the amount of memory used by the decompressor. This will cause\n"
182 " decompression to fail if the input cannot be decompressed within the\n"
183 " given limit.\n"
184 " filters\n"
185 " A custom filter chain. This argument is required for FORMAT_RAW, and\n"
186 " not accepted with any other format. When provided, this should be a\n"
187 " sequence of dicts, each indicating the ID and options for a single\n"
188 " filter.\n"
189 "\n"
190 "For one-shot decompression, use the decompress() function instead.");
191
192 static PyObject *
193 _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
194 PyObject *memlimit, PyObject *filters);
195
196 static PyObject *
197 _lzma_LZMADecompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
198 {
199 PyObject *return_value = NULL;
200 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
201
202 #define NUM_KEYWORDS 3
203 static struct {
204 PyGC_Head _this_is_not_used;
205 PyObject_VAR_HEAD
206 Py_hash_t ob_hash;
207 PyObject *ob_item[NUM_KEYWORDS];
208 } _kwtuple = {
209 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
210 .ob_hash = -1,
211 .ob_item = { &_Py_ID(format), &_Py_ID(memlimit), &_Py_ID(filters), },
212 };
213 #undef NUM_KEYWORDS
214 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
215
216 #else // !Py_BUILD_CORE
217 # define KWTUPLE NULL
218 #endif // !Py_BUILD_CORE
219
220 static const char * const _keywords[] = {"format", "memlimit", "filters", NULL};
221 static _PyArg_Parser _parser = {
222 .keywords = _keywords,
223 .fname = "LZMADecompressor",
224 .kwtuple = KWTUPLE,
225 };
226 #undef KWTUPLE
227 PyObject *argsbuf[3];
228 PyObject * const *fastargs;
229 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
230 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
231 int format = FORMAT_AUTO;
232 PyObject *memlimit = Py_None;
233 PyObject *filters = Py_None;
234
235 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
236 /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 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 return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
328
329 exit:
330 /* Cleanup for encoded_props */
331 if (encoded_props.obj) {
332 PyBuffer_Release(&encoded_props);
333 }
334
335 return return_value;
336 }
337 /*[clinic end generated code: output=ffc6d673d858048c input=a9049054013a1b77]*/