blob: 3ed8303e95f2e0ec60f8cc68b9b8f3bc7f5c6451 [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 Storchaka247789c2015-04-24 00:40:51 +030028 if (!PyArg_Parse(arg, "y*:compress", &data))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020029 goto exit;
30 return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
31
32exit:
33 /* Cleanup for data */
34 if (data.obj)
35 PyBuffer_Release(&data);
36
37 return return_value;
38}
39
40PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080041"flush($self, /)\n"
42"--\n"
43"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020044"Finish the compression process.\n"
45"\n"
46"Returns the compressed data left in internal buffers.\n"
47"\n"
48"The compressor object may not be used after this method is called.");
49
50#define _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \
51 {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
52
53static PyObject *
54_bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
55
56static PyObject *
57_bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
58{
59 return _bz2_BZ2Compressor_flush_impl(self);
60}
61
62PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080063"BZ2Compressor(compresslevel=9, /)\n"
64"--\n"
65"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020066"Create a compressor object for compressing data incrementally.\n"
67"\n"
68" compresslevel\n"
69" Compression level, as a number between 1 and 9.\n"
70"\n"
71"For one-shot compression, use the compress() function instead.");
72
73static int
74_bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel);
75
76static int
77_bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
78{
79 int return_value = -1;
80 int compresslevel = 9;
81
Larry Hastingsf0537e82014-01-25 22:01:12 -080082 if ((Py_TYPE(self) == &BZ2Compressor_Type) &&
83 !_PyArg_NoKeywords("BZ2Compressor", kwargs))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020084 goto exit;
Serhiy Storchaka247789c2015-04-24 00:40:51 +030085 if (!PyArg_ParseTuple(args, "|i:BZ2Compressor",
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020086 &compresslevel))
87 goto exit;
88 return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
89
90exit:
91 return return_value;
92}
93
94PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
Antoine Pitroue71258a2015-02-26 13:08:07 +010095"decompress($self, /, data, max_length=-1)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -080096"--\n"
97"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +010098"Decompress *data*, returning uncompressed data as bytes.\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020099"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +0100100"If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
101"decompressed data. If this limit is reached and further output can be\n"
102"produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
103"call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200104"\n"
Antoine Pitroue71258a2015-02-26 13:08:07 +0100105"If all of the input data was decompressed and returned (either because this\n"
106"was less than *max_length* bytes, or because *max_length* was negative),\n"
107"*self.needs_input* will be set to True.\n"
108"\n"
109"Attempting to decompress data after the end of stream is reached raises an\n"
110"EOFError. Any data found after the end of the stream is ignored and saved in\n"
111"the unused_data attribute.");
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200112
113#define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
Antoine Pitroue71258a2015-02-26 13:08:07 +0100114 {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_VARARGS|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200115
116static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400117_bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
118 Py_ssize_t max_length);
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200119
120static PyObject *
Antoine Pitroue71258a2015-02-26 13:08:07 +0100121_bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200122{
123 PyObject *return_value = NULL;
Antoine Pitroue71258a2015-02-26 13:08:07 +0100124 static char *_keywords[] = {"data", "max_length", NULL};
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200125 Py_buffer data = {NULL, NULL};
Antoine Pitroue71258a2015-02-26 13:08:07 +0100126 Py_ssize_t max_length = -1;
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200127
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300128 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|n:decompress", _keywords,
Antoine Pitroue71258a2015-02-26 13:08:07 +0100129 &data, &max_length))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200130 goto exit;
Antoine Pitroue71258a2015-02-26 13:08:07 +0100131 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200132
133exit:
134 /* Cleanup for data */
135 if (data.obj)
136 PyBuffer_Release(&data);
137
138 return return_value;
139}
140
141PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800142"BZ2Decompressor()\n"
143"--\n"
144"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200145"Create a decompressor object for decompressing data incrementally.\n"
146"\n"
147"For one-shot decompression, use the decompress() function instead.");
148
149static int
150_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
151
152static int
153_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
154{
155 int return_value = -1;
156
Larry Hastingsf0537e82014-01-25 22:01:12 -0800157 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
158 !_PyArg_NoPositional("BZ2Decompressor", args))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200159 goto exit;
Larry Hastingsf0537e82014-01-25 22:01:12 -0800160 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
161 !_PyArg_NoKeywords("BZ2Decompressor", kwargs))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200162 goto exit;
163 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
164
165exit:
166 return return_value;
167}
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300168/*[clinic end generated code: output=fef29b76b3314fc7 input=a9049054013a1b77]*/