Debian Codegraph @

Modules/clinic/_bz2module.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(_bz2_BZ2Compressor_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 _BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF \
24 {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__},
25
26 static PyObject *
27 _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
28
29 static PyObject *
30 _bz2_BZ2Compressor_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 = _bz2_BZ2Compressor_compress_impl((BZ2Compressor *)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(_bz2_BZ2Compressor_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 _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \
60 {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
61
62 static PyObject *
63 _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
64
65 static PyObject *
66 _bz2_BZ2Compressor_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
67 {
68 return _bz2_BZ2Compressor_flush_impl((BZ2Compressor *)self);
69 }
70
71 PyDoc_STRVAR(_bz2_BZ2Compressor__doc__,
72 "BZ2Compressor(compresslevel=9, /)\n"
73 "--\n"
74 "\n"
75 "Create a compressor object for compressing data incrementally.\n"
76 "\n"
77 " compresslevel\n"
78 " Compression level, as a number between 1 and 9.\n"
79 "\n"
80 "For one-shot compression, use the compress() function instead.");
81
82 static PyObject *
83 _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel);
84
85 static PyObject *
86 _bz2_BZ2Compressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
87 {
88 PyObject *return_value = NULL;
89 PyTypeObject *base_tp = clinic_state()->bz2_compressor_type;
90 int compresslevel = 9;
91
92 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
93 !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
94 goto exit;
95 }
96 if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) {
97 goto exit;
98 }
99 if (PyTuple_GET_SIZE(args) < 1) {
100 goto skip_optional;
101 }
102 compresslevel = PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
103 if (compresslevel == -1 && PyErr_Occurred()) {
104 goto exit;
105 }
106 skip_optional:
107 return_value = _bz2_BZ2Compressor_impl(type, compresslevel);
108
109 exit:
110 return return_value;
111 }
112
113 PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
114 "decompress($self, /, data, max_length=-1)\n"
115 "--\n"
116 "\n"
117 "Decompress *data*, returning uncompressed data as bytes.\n"
118 "\n"
119 "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
120 "decompressed data. If this limit is reached and further output can be\n"
121 "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
122 "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
123 "\n"
124 "If all of the input data was decompressed and returned (either because this\n"
125 "was less than *max_length* bytes, or because *max_length* was negative),\n"
126 "*self.needs_input* will be set to True.\n"
127 "\n"
128 "Attempting to decompress data after the end of stream is reached raises an\n"
129 "EOFError. Any data found after the end of the stream is ignored and saved in\n"
130 "the unused_data attribute.");
131
132 #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
133 {"decompress", _PyCFunction_CAST(_bz2_BZ2Decompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
134
135 static PyObject *
136 _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
137 Py_ssize_t max_length);
138
139 static PyObject *
140 _bz2_BZ2Decompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
141 {
142 PyObject *return_value = NULL;
143 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
144
145 #define NUM_KEYWORDS 2
146 static struct {
147 PyGC_Head _this_is_not_used;
148 PyObject_VAR_HEAD
149 Py_hash_t ob_hash;
150 PyObject *ob_item[NUM_KEYWORDS];
151 } _kwtuple = {
152 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
153 .ob_hash = -1,
154 .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
155 };
156 #undef NUM_KEYWORDS
157 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
158
159 #else // !Py_BUILD_CORE
160 # define KWTUPLE NULL
161 #endif // !Py_BUILD_CORE
162
163 static const char * const _keywords[] = {"data", "max_length", NULL};
164 static _PyArg_Parser _parser = {
165 .keywords = _keywords,
166 .fname = "decompress",
167 .kwtuple = KWTUPLE,
168 };
169 #undef KWTUPLE
170 PyObject *argsbuf[2];
171 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
172 Py_buffer data = {NULL, NULL};
173 Py_ssize_t max_length = -1;
174
175 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
176 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
177 if (!args) {
178 goto exit;
179 }
180 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
181 goto exit;
182 }
183 if (!noptargs) {
184 goto skip_optional_pos;
185 }
186 {
187 Py_ssize_t ival = -1;
188 PyObject *iobj = _PyNumber_Index(args[1]);
189 if (iobj != NULL) {
190 ival = PyLong_AsSsize_t(iobj);
191 Py_DECREF(iobj);
192 }
193 if (ival == -1 && PyErr_Occurred()) {
194 goto exit;
195 }
196 max_length = ival;
197 }
198 skip_optional_pos:
199 return_value = _bz2_BZ2Decompressor_decompress_impl((BZ2Decompressor *)self, &data, max_length);
200
201 exit:
202 /* Cleanup for data */
203 if (data.obj) {
204 PyBuffer_Release(&data);
205 }
206
207 return return_value;
208 }
209
210 PyDoc_STRVAR(_bz2_BZ2Decompressor__doc__,
211 "BZ2Decompressor()\n"
212 "--\n"
213 "\n"
214 "Create a decompressor object for decompressing data incrementally.\n"
215 "\n"
216 "For one-shot decompression, use the decompress() function instead.");
217
218 static PyObject *
219 _bz2_BZ2Decompressor_impl(PyTypeObject *type);
220
221 static PyObject *
222 _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
223 {
224 PyObject *return_value = NULL;
225 PyTypeObject *base_tp = clinic_state()->bz2_decompressor_type;
226
227 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
228 !_PyArg_NoPositional("BZ2Decompressor", args)) {
229 goto exit;
230 }
231 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
232 !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
233 goto exit;
234 }
235 return_value = _bz2_BZ2Decompressor_impl(type);
236
237 exit:
238 return return_value;
239 }
240 /*[clinic end generated code: output=552ac6d4c5a101b7 input=a9049054013a1b77]*/