Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 6 | "compress($self, data, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 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 \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 17 | {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__}, |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
| 20 | _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data); |
| 21 | |
| 22 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 23 | _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg) |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 24 | { |
| 25 | PyObject *return_value = NULL; |
| 26 | Py_buffer data = {NULL, NULL}; |
| 27 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 28 | if (!PyArg_Parse(arg, "y*:compress", &data)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 29 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 30 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 31 | return_value = _bz2_BZ2Compressor_compress_impl(self, &data); |
| 32 | |
| 33 | exit: |
| 34 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 35 | if (data.obj) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 36 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 37 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 38 | |
| 39 | return return_value; |
| 40 | } |
| 41 | |
| 42 | PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 43 | "flush($self, /)\n" |
| 44 | "--\n" |
| 45 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 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 * |
| 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__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 65 | "BZ2Compressor(compresslevel=9, /)\n" |
| 66 | "--\n" |
| 67 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 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 |
| 79 | _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 80 | { |
| 81 | int return_value = -1; |
| 82 | int compresslevel = 9; |
| 83 | |
Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 84 | if ((Py_TYPE(self) == &BZ2Compressor_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 85 | !_PyArg_NoKeywords("BZ2Compressor", kwargs)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 86 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 87 | } |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 88 | if (!PyArg_ParseTuple(args, "|i:BZ2Compressor", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 89 | &compresslevel)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 90 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 91 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 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__, |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 99 | "decompress($self, /, data, max_length=-1)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 100 | "--\n" |
| 101 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 102 | "Decompress *data*, returning uncompressed data as bytes.\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 103 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 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" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 108 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 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."); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 116 | |
| 117 | #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 118 | {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_FASTCALL, _bz2_BZ2Decompressor_decompress__doc__}, |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 119 | |
| 120 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 121 | _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data, |
| 122 | Py_ssize_t max_length); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 123 | |
| 124 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 125 | _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 126 | { |
| 127 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 128 | static const char * const _keywords[] = {"data", "max_length", NULL}; |
| 129 | static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0}; |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 130 | Py_buffer data = {NULL, NULL}; |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 131 | Py_ssize_t max_length = -1; |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 132 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 133 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 134 | &data, &max_length)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 135 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 136 | } |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 137 | return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 138 | |
| 139 | exit: |
| 140 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 141 | if (data.obj) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 142 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 143 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 144 | |
| 145 | return return_value; |
| 146 | } |
| 147 | |
| 148 | PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 149 | "BZ2Decompressor()\n" |
| 150 | "--\n" |
| 151 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 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 |
| 160 | _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 161 | { |
| 162 | int return_value = -1; |
| 163 | |
Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 164 | if ((Py_TYPE(self) == &BZ2Decompressor_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 165 | !_PyArg_NoPositional("BZ2Decompressor", args)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 166 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 167 | } |
Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 168 | if ((Py_TYPE(self) == &BZ2Decompressor_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 169 | !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 170 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 171 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 172 | return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self); |
| 173 | |
| 174 | exit: |
| 175 | return return_value; |
| 176 | } |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 177 | /*[clinic end generated code: output=7e57af0b368d3e55 input=a9049054013a1b77]*/ |