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 (!PyArg_Parse(arg, "y*:compress", &data)) {
29 goto exit;
30 }
31 return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
32
33 exit:
34 /* Cleanup for data */
35 if (data.obj) {
36 PyBuffer_Release(&data);
37 }
38
39 return return_value;
40 }
41
42 PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__,
43 "flush($self, /)\n"
44 "--\n"
45 "\n"
46 "Finish the compression process.\n"
47 "\n"
48 "Returns the compressed data left in internal buffers.\n"
49 "\n"
50 "The compressor object may not be used after this method is called.");
51
52 #define _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \
53 {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
54
55 static PyObject *
56 _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
57
58 static PyObject *
_bz2_BZ2Compressor_flush(BZ2Compressor * self,PyObject * Py_UNUSED (ignored))59 _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
60 {
61 return _bz2_BZ2Compressor_flush_impl(self);
62 }
63
64 PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__,
65 "BZ2Compressor(compresslevel=9, /)\n"
66 "--\n"
67 "\n"
68 "Create a compressor object for compressing data incrementally.\n"
69 "\n"
70 " compresslevel\n"
71 " Compression level, as a number between 1 and 9.\n"
72 "\n"
73 "For one-shot compression, use the compress() function instead.");
74
75 static int
76 _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel);
77
78 static int
_bz2_BZ2Compressor___init__(PyObject * self,PyObject * args,PyObject * kwargs)79 _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
80 {
81 int return_value = -1;
82 int compresslevel = 9;
83
84 if ((Py_TYPE(self) == &BZ2Compressor_Type) &&
85 !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
86 goto exit;
87 }
88 if (!PyArg_ParseTuple(args, "|i:BZ2Compressor",
89 &compresslevel)) {
90 goto exit;
91 }
92 return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
93
94 exit:
95 return return_value;
96 }
97
98 PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
99 "decompress($self, /, data, max_length=-1)\n"
100 "--\n"
101 "\n"
102 "Decompress *data*, returning uncompressed data as bytes.\n"
103 "\n"
104 "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
105 "decompressed data. If this limit is reached and further output can be\n"
106 "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
107 "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
108 "\n"
109 "If all of the input data was decompressed and returned (either because this\n"
110 "was less than *max_length* bytes, or because *max_length* was negative),\n"
111 "*self.needs_input* will be set to True.\n"
112 "\n"
113 "Attempting to decompress data after the end of stream is reached raises an\n"
114 "EOFError. Any data found after the end of the stream is ignored and saved in\n"
115 "the unused_data attribute.");
116
117 #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
118 {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
119
120 static PyObject *
121 _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
122 Py_ssize_t max_length);
123
124 static PyObject *
_bz2_BZ2Decompressor_decompress(BZ2Decompressor * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)125 _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
126 {
127 PyObject *return_value = NULL;
128 static const char * const _keywords[] = {"data", "max_length", NULL};
129 static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0};
130 Py_buffer data = {NULL, NULL};
131 Py_ssize_t max_length = -1;
132
133 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
134 &data, &max_length)) {
135 goto exit;
136 }
137 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
138
139 exit:
140 /* Cleanup for data */
141 if (data.obj) {
142 PyBuffer_Release(&data);
143 }
144
145 return return_value;
146 }
147
148 PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
149 "BZ2Decompressor()\n"
150 "--\n"
151 "\n"
152 "Create a decompressor object for decompressing data incrementally.\n"
153 "\n"
154 "For one-shot decompression, use the decompress() function instead.");
155
156 static int
157 _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
158
159 static int
_bz2_BZ2Decompressor___init__(PyObject * self,PyObject * args,PyObject * kwargs)160 _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
161 {
162 int return_value = -1;
163
164 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
165 !_PyArg_NoPositional("BZ2Decompressor", args)) {
166 goto exit;
167 }
168 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
169 !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
170 goto exit;
171 }
172 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
173
174 exit:
175 return return_value;
176 }
177 /*[clinic end generated code: output=564a0313177fff63 input=a9049054013a1b77]*/
178