blob: 8a201a08de02a37cfc29cce2c0105d3ff93612d5 [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 \
17 {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_VARARGS, _bz2_BZ2Compressor_compress__doc__},
18
19static PyObject *
20_bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
21
22static PyObject *
23_bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *args)
24{
25 PyObject *return_value = NULL;
26 Py_buffer data = {NULL, NULL};
27
28 if (!PyArg_ParseTuple(args,
29 "y*:compress",
30 &data))
31 goto exit;
32 return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
33
34exit:
35 /* Cleanup for data */
36 if (data.obj)
37 PyBuffer_Release(&data);
38
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) &&
85 !_PyArg_NoKeywords("BZ2Compressor", kwargs))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +020086 goto exit;
87 if (!PyArg_ParseTuple(args,
88 "|i:BZ2Compressor",
89 &compresslevel))
90 goto exit;
91 return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
92
93exit:
94 return return_value;
95}
96
97PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080098"decompress($self, data, /)\n"
99"--\n"
100"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200101"Provide data to the decompressor object.\n"
102"\n"
103"Returns a chunk of decompressed data if possible, or b\'\' otherwise.\n"
104"\n"
105"Attempting to decompress data after the end of stream is reached\n"
106"raises an EOFError. Any data found after the end of the stream\n"
107"is ignored and saved in the unused_data attribute.");
108
109#define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \
110 {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_VARARGS, _bz2_BZ2Decompressor_decompress__doc__},
111
112static PyObject *
113_bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data);
114
115static PyObject *
116_bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args)
117{
118 PyObject *return_value = NULL;
119 Py_buffer data = {NULL, NULL};
120
121 if (!PyArg_ParseTuple(args,
122 "y*:decompress",
123 &data))
124 goto exit;
125 return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data);
126
127exit:
128 /* Cleanup for data */
129 if (data.obj)
130 PyBuffer_Release(&data);
131
132 return return_value;
133}
134
135PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800136"BZ2Decompressor()\n"
137"--\n"
138"\n"
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200139"Create a decompressor object for decompressing data incrementally.\n"
140"\n"
141"For one-shot decompression, use the decompress() function instead.");
142
143static int
144_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self);
145
146static int
147_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
148{
149 int return_value = -1;
150
Larry Hastingsf0537e82014-01-25 22:01:12 -0800151 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
152 !_PyArg_NoPositional("BZ2Decompressor", args))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200153 goto exit;
Larry Hastingsf0537e82014-01-25 22:01:12 -0800154 if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
155 !_PyArg_NoKeywords("BZ2Decompressor", kwargs))
Serhiy Storchaka1bc4bb22014-01-25 12:07:57 +0200156 goto exit;
157 return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
158
159exit:
160 return return_value;
161}
Larry Hastings2623c8c2014-02-08 22:15:29 -0800162/*[clinic end generated code: output=21ca4405519a0931 input=a9049054013a1b77]*/