Branch data Line data Source code
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 : 0 : _lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
30 : : {
31 : 0 : PyObject *return_value = NULL;
32 : 0 : Py_buffer data = {NULL, NULL};
33 : :
34 [ # # ]: 0 : if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
35 : 0 : goto exit;
36 : : }
37 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&data, 'C')) {
38 : 0 : _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
39 : 0 : goto exit;
40 : : }
41 : 0 : return_value = _lzma_LZMACompressor_compress_impl(self, &data);
42 : :
43 : 0 : exit:
44 : : /* Cleanup for data */
45 [ # # ]: 0 : if (data.obj) {
46 : 0 : PyBuffer_Release(&data);
47 : : }
48 : :
49 : 0 : 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 : 0 : _lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored))
70 : : {
71 : 0 : 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 : 0 : _lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
102 : : {
103 : 0 : 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 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
131 : 0 : Py_buffer data = {NULL, NULL};
132 : 0 : Py_ssize_t max_length = -1;
133 : :
134 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
135 [ # # ]: 0 : if (!args) {
136 : 0 : goto exit;
137 : : }
138 [ # # ]: 0 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
139 : 0 : goto exit;
140 : : }
141 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&data, 'C')) {
142 : 0 : _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
143 : 0 : goto exit;
144 : : }
145 [ # # ]: 0 : if (!noptargs) {
146 : 0 : goto skip_optional_pos;
147 : : }
148 : : {
149 : 0 : Py_ssize_t ival = -1;
150 : 0 : PyObject *iobj = _PyNumber_Index(args[1]);
151 [ # # ]: 0 : if (iobj != NULL) {
152 : 0 : ival = PyLong_AsSsize_t(iobj);
153 : 0 : Py_DECREF(iobj);
154 : : }
155 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
156 : 0 : goto exit;
157 : : }
158 : 0 : max_length = ival;
159 : : }
160 : 0 : skip_optional_pos:
161 : 0 : return_value = _lzma_LZMADecompressor_decompress_impl(self, &data, max_length);
162 : :
163 : 0 : exit:
164 : : /* Cleanup for data */
165 [ # # ]: 0 : if (data.obj) {
166 : 0 : PyBuffer_Release(&data);
167 : : }
168 : :
169 : 0 : 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 : 0 : _lzma_LZMADecompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
201 : : {
202 : 0 : 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 : 0 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
231 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
232 : 0 : int format = FORMAT_AUTO;
233 : 0 : PyObject *memlimit = Py_None;
234 : 0 : PyObject *filters = Py_None;
235 : :
236 [ # # # # : 0 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
# # # # ]
237 [ # # ]: 0 : if (!fastargs) {
238 : 0 : goto exit;
239 : : }
240 [ # # ]: 0 : if (!noptargs) {
241 : 0 : goto skip_optional_pos;
242 : : }
243 [ # # ]: 0 : if (fastargs[0]) {
244 : 0 : format = _PyLong_AsInt(fastargs[0]);
245 [ # # # # ]: 0 : if (format == -1 && PyErr_Occurred()) {
246 : 0 : goto exit;
247 : : }
248 [ # # ]: 0 : if (!--noptargs) {
249 : 0 : goto skip_optional_pos;
250 : : }
251 : : }
252 [ # # ]: 0 : if (fastargs[1]) {
253 : 0 : memlimit = fastargs[1];
254 [ # # ]: 0 : if (!--noptargs) {
255 : 0 : goto skip_optional_pos;
256 : : }
257 : : }
258 : 0 : filters = fastargs[2];
259 : 0 : skip_optional_pos:
260 : 0 : return_value = _lzma_LZMADecompressor_impl(type, format, memlimit, filters);
261 : :
262 : 0 : exit:
263 : 0 : 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 : 0 : _lzma_is_check_supported(PyObject *module, PyObject *arg)
282 : : {
283 : 0 : PyObject *return_value = NULL;
284 : : int check_id;
285 : :
286 : 0 : check_id = _PyLong_AsInt(arg);
287 [ # # # # ]: 0 : if (check_id == -1 && PyErr_Occurred()) {
288 : 0 : goto exit;
289 : : }
290 : 0 : return_value = _lzma_is_check_supported_impl(module, check_id);
291 : :
292 : 0 : exit:
293 : 0 : 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 : 0 : _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
313 : : {
314 : 0 : PyObject *return_value = NULL;
315 : : lzma_vli filter_id;
316 : 0 : Py_buffer encoded_props = {NULL, NULL};
317 : :
318 [ # # # # : 0 : if (!_PyArg_CheckPositional("_decode_filter_properties", nargs, 2, 2)) {
# # ]
319 : 0 : goto exit;
320 : : }
321 [ # # ]: 0 : if (!lzma_vli_converter(args[0], &filter_id)) {
322 : 0 : goto exit;
323 : : }
324 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &encoded_props, PyBUF_SIMPLE) != 0) {
325 : 0 : goto exit;
326 : : }
327 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&encoded_props, 'C')) {
328 : 0 : _PyArg_BadArgument("_decode_filter_properties", "argument 2", "contiguous buffer", args[1]);
329 : 0 : goto exit;
330 : : }
331 : 0 : return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
332 : :
333 : 0 : exit:
334 : : /* Cleanup for encoded_props */
335 [ # # ]: 0 : if (encoded_props.obj) {
336 : 0 : PyBuffer_Release(&encoded_props);
337 : : }
338 : :
339 : 0 : return return_value;
340 : : }
341 : : /*[clinic end generated code: output=96c1fbdada1ef232 input=a9049054013a1b77]*/
|