blob: 1ca810c9e7bd7f77f4745b29dddee4fc724f6b9f [file] [log] [blame]
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -08006"compress($self, data, /)\n"
7"--\n"
8"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +02009"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 \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030017 {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__},
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020018
19static PyObject *
20_bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
21
22static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030023_bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020024{
25 PyObject *return_value = NULL;
26 Py_buffer data = {NULL, NULL};
27
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030028 if (!PyArg_Parse(arg, "y*:compress", &data)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020029 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030030 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020031 return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
32
33exit:
34 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030035 if (data.obj) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020036 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030037 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020038
39 return return_value;
40}
41
42PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080043"flush($self, /)\n"
44"--\n"
45"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020046"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
55static PyObject *
56_bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
57
58static PyObject *
59_bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
60{
61 return _bz2_BZ2Compressor_flush_impl(self);
62}
63
64PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080065"BZ2Compressor(compresslevel=9, /)\n"
66"--\n"
67"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020068"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
75static int
76_bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel);
77
78static int
79_bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
80{
81 int return_value = -1;
82 int compresslevel = 9;
83
Larry Hastingsf0537e82014-01-25 22:01:12 -080084 if ((Py_TYPE(self) == &BZ2Compressor_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030085 !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020086 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030087 }
Serhiy Storchaka247789c2015-04-24 00:40:51 +030088 if (!PyArg_ParseTuple(args, "|i:BZ2Compressor",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030089 &compresslevel)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020090 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030091 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020092 return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
93
94exit:
95 return return_value;
96}
97
98PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
Antoine Pitroue71258a2015-02-26 13:08:07 +010099"decompress($self, /, data, max_length=-1)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800100"--\n"
101"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +0100102"Decompress *data*, returning uncompressed data as bytes.\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200103"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +0100104"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"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200108"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +0100109"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.");
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200116
117#define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700118 {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_FASTCALL, _bz2_BZ2Decompressor_decompress__doc__},
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200119
120static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400121_bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
122 Py_ssize_t max_length);
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200123
124static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700125_bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200126{
127 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300128 static const char * const _keywords[] = {"data", "max_length", NULL};
129 static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0};
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200130 Py_buffer data = {NULL, NULL};
Antoine Pitroue71258a2015-02-26 13:08:07 +0100131 Py_ssize_t max_length = -1;
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200132
Victor Stinner37e4ef72016-09-09 20:00:13 -0700133 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300134 &data, &max_length)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200135 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300136 }
Antoine Pitroue71258a2015-02-26 13:08:07 +0100137 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200138
139exit:
140 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300141 if (data.obj) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200142 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300143 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200144
145 return return_value;
146}
147
148PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800149"BZ2Decompressor()\n"
150"--\n"
151"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200152"Create a decompressor object for decompressing data incrementally.\n"
153"\n"
154"For one-shot decompression, use the decompress() function instead.");
155
156static int
157_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
158
159static int
160_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
161{
162 int return_value = -1;
163
Larry Hastingsf0537e82014-01-25 22:01:12 -0800164 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300165 !_PyArg_NoPositional("BZ2Decompressor", args)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300167 }
Larry Hastingsf0537e82014-01-25 22:01:12 -0800168 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300169 !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200170 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300171 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200172 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
173
174exit:
175 return return_value;
176}
Victor Stinner37e4ef72016-09-09 20:00:13 -0700177/*[clinic end generated code: output=7e57af0b368d3e55 input=a9049054013a1b77]*/