blob: 9451fd3b15ac4f027cf82be8896749e5fc0c1a0e [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 \
Antoine Pitroue71258a2015-02-26 13:08:07 +0100118 {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_VARARGS|METH_KEYWORDS, _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 *
Antoine Pitroue71258a2015-02-26 13:08:07 +0100125_bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200126{
127 PyObject *return_value = NULL;
Antoine Pitroue71258a2015-02-26 13:08:07 +0100128 static char *_keywords[] = {"data", "max_length", NULL};
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200129 Py_buffer data = {NULL, NULL};
Antoine Pitroue71258a2015-02-26 13:08:07 +0100130 Py_ssize_t max_length = -1;
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200131
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300132 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|n:decompress", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300133 &data, &max_length)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300135 }
Antoine Pitroue71258a2015-02-26 13:08:07 +0100136 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200137
138exit:
139 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300140 if (data.obj) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200141 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300142 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200143
144 return return_value;
145}
146
147PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800148"BZ2Decompressor()\n"
149"--\n"
150"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200151"Create a decompressor object for decompressing data incrementally.\n"
152"\n"
153"For one-shot decompression, use the decompress() function instead.");
154
155static int
156_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
157
158static int
159_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
160{
161 int return_value = -1;
162
Larry Hastingsf0537e82014-01-25 22:01:12 -0800163 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300164 !_PyArg_NoPositional("BZ2Decompressor", args)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200165 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300166 }
Larry Hastingsf0537e82014-01-25 22:01:12 -0800167 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300168 !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200169 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300170 }
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200171 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
172
173exit:
174 return return_value;
175}
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300176/*[clinic end generated code: output=71be22f38224fe84 input=a9049054013a1b77]*/