1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__,
6 "compress($self, data, /)\n"
7 "--\n"
8 "\n"
9 "Provide data to the compressor object.\n"
10 "\n"
11 "Returns a chunk of compressed data if possible, or b\'\' otherwise.\n"
12 "\n"
13 "When you have finished providing data to the compressor, call the\n"
14 "flush() method to finish the compression process.");
15
16 #define _BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF \
17 {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__},
18
19 static PyObject *
20 _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
21
22 static PyObject *
_bz2_BZ2Compressor_compress(BZ2Compressor * self,PyObject * arg)23 _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
24 {
25 PyObject *return_value = NULL;
26 Py_buffer data = {NULL, NULL};
27
28 if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
29 goto exit;
30 }
31 if (!PyBuffer_IsContiguous(&data, 'C')) {
32 _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
33 goto exit;
34 }
35 return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
36
37 exit:
38 /* Cleanup for data */
39 if (data.obj) {
40 PyBuffer_Release(&data);
41 }
42
43 return return_value;
44 }
45
46 PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__,
47 "flush($self, /)\n"
48 "--\n"
49 "\n"
50 "Finish the compression process.\n"
51 "\n"
52 "Returns the compressed data left in internal buffers.\n"
53 "\n"
54 "The compressor object may not be used after this method is called.");
55
56 #define _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \
57 {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
58
59 static PyObject *
60 _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
61
62 static PyObject *
_bz2_BZ2Compressor_flush(BZ2Compressor * self,PyObject * Py_UNUSED (ignored))63 _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
64 {
65 return _bz2_BZ2Compressor_flush_impl(self);
66 }
67
68 PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__,
69 "BZ2Compressor(compresslevel=9, /)\n"
70 "--\n"
71 "\n"
72 "Create a compressor object for compressing data incrementally.\n"
73 "\n"
74 " compresslevel\n"
75 " Compression level, as a number between 1 and 9.\n"
76 "\n"
77 "For one-shot compression, use the compress() function instead.");
78
79 static int
80 _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel);
81
82 static int
_bz2_BZ2Compressor___init__(PyObject * self,PyObject * args,PyObject * kwargs)83 _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
84 {
85 int return_value = -1;
86 int compresslevel = 9;
87
88 if (Py_IS_TYPE(self, &BZ2Compressor_Type) &&
89 !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
90 goto exit;
91 }
92 if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) {
93 goto exit;
94 }
95 if (PyTuple_GET_SIZE(args) < 1) {
96 goto skip_optional;
97 }
98 if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) {
99 PyErr_SetString(PyExc_TypeError,
100 "integer argument expected, got float" );
101 goto exit;
102 }
103 compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
104 if (compresslevel == -1 && PyErr_Occurred()) {
105 goto exit;
106 }
107 skip_optional:
108 return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
109
110 exit:
111 return return_value;
112 }
113
114 PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
115 "decompress($self, /, data, max_length=-1)\n"
116 "--\n"
117 "\n"
118 "Decompress *data*, returning uncompressed data as bytes.\n"
119 "\n"
120 "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
121 "decompressed data. If this limit is reached and further output can be\n"
122 "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
123 "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
124 "\n"
125 "If all of the input data was decompressed and returned (either because this\n"
126 "was less than *max_length* bytes, or because *max_length* was negative),\n"
127 "*self.needs_input* will be set to True.\n"
128 "\n"
129 "Attempting to decompress data after the end of stream is reached raises an\n"
130 "EOFError. Any data found after the end of the stream is ignored and saved in\n"
131 "the unused_data attribute.");
132
133 #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
134 {"decompress", (PyCFunction)(void(*)(void))_bz2_BZ2Decompressor_decompress, METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
135
136 static PyObject *
137 _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
138 Py_ssize_t max_length);
139
140 static PyObject *
_bz2_BZ2Decompressor_decompress(BZ2Decompressor * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)141 _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
142 {
143 PyObject *return_value = NULL;
144 static const char * const _keywords[] = {"data", "max_length", NULL};
145 static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
146 PyObject *argsbuf[2];
147 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
148 Py_buffer data = {NULL, NULL};
149 Py_ssize_t max_length = -1;
150
151 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
152 if (!args) {
153 goto exit;
154 }
155 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
156 goto exit;
157 }
158 if (!PyBuffer_IsContiguous(&data, 'C')) {
159 _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
160 goto exit;
161 }
162 if (!noptargs) {
163 goto skip_optional_pos;
164 }
165 if (PyFloat_Check(args[1])) {
166 PyErr_SetString(PyExc_TypeError,
167 "integer argument expected, got float" );
168 goto exit;
169 }
170 {
171 Py_ssize_t ival = -1;
172 PyObject *iobj = PyNumber_Index(args[1]);
173 if (iobj != NULL) {
174 ival = PyLong_AsSsize_t(iobj);
175 Py_DECREF(iobj);
176 }
177 if (ival == -1 && PyErr_Occurred()) {
178 goto exit;
179 }
180 max_length = ival;
181 }
182 skip_optional_pos:
183 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
184
185 exit:
186 /* Cleanup for data */
187 if (data.obj) {
188 PyBuffer_Release(&data);
189 }
190
191 return return_value;
192 }
193
194 PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
195 "BZ2Decompressor()\n"
196 "--\n"
197 "\n"
198 "Create a decompressor object for decompressing data incrementally.\n"
199 "\n"
200 "For one-shot decompression, use the decompress() function instead.");
201
202 static int
203 _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
204
205 static int
_bz2_BZ2Decompressor___init__(PyObject * self,PyObject * args,PyObject * kwargs)206 _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
207 {
208 int return_value = -1;
209
210 if (Py_IS_TYPE(self, &BZ2Decompressor_Type) &&
211 !_PyArg_NoPositional("BZ2Decompressor", args)) {
212 goto exit;
213 }
214 if (Py_IS_TYPE(self, &BZ2Decompressor_Type) &&
215 !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
216 goto exit;
217 }
218 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
219
220 exit:
221 return return_value;
222 }
223 /*[clinic end generated code: output=3f3f1e788fe28ee1 input=a9049054013a1b77]*/
224