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 | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 28 | if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) { |
| 29 | goto exit; |
| 30 | } |
| 31 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
| 32 | _PyArg_BadArgument("compress", "contiguous buffer", arg); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 33 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 34 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 35 | return_value = _bz2_BZ2Compressor_compress_impl(self, &data); |
| 36 | |
| 37 | exit: |
| 38 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 39 | if (data.obj) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 40 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 41 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 42 | |
| 43 | return return_value; |
| 44 | } |
| 45 | |
| 46 | PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 47 | "flush($self, /)\n" |
| 48 | "--\n" |
| 49 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 50 | "Finish the compression process.\n" |
| 51 | "\n" |
| 52 | "Returns the compressed data left in internal buffers.\n" |
| 53 | "\n" |
| 54 | "The compressor object may not be used after this method is called."); |
| 55 | |
| 56 | #define _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF \ |
| 57 | {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__}, |
| 58 | |
| 59 | static PyObject * |
| 60 | _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self); |
| 61 | |
| 62 | static PyObject * |
| 63 | _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored)) |
| 64 | { |
| 65 | return _bz2_BZ2Compressor_flush_impl(self); |
| 66 | } |
| 67 | |
| 68 | PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 69 | "BZ2Compressor(compresslevel=9, /)\n" |
| 70 | "--\n" |
| 71 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 72 | "Create a compressor object for compressing data incrementally.\n" |
| 73 | "\n" |
| 74 | " compresslevel\n" |
| 75 | " Compression level, as a number between 1 and 9.\n" |
| 76 | "\n" |
| 77 | "For one-shot compression, use the compress() function instead."); |
| 78 | |
| 79 | static int |
| 80 | _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel); |
| 81 | |
| 82 | static int |
| 83 | _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 84 | { |
| 85 | int return_value = -1; |
| 86 | int compresslevel = 9; |
| 87 | |
Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 88 | if ((Py_TYPE(self) == &BZ2Compressor_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 89 | !_PyArg_NoKeywords("BZ2Compressor", kwargs)) { |
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 | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 92 | if (!PyArg_ParseTuple(args, "|i:BZ2Compressor", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 93 | &compresslevel)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 94 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 95 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 96 | return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel); |
| 97 | |
| 98 | exit: |
| 99 | return return_value; |
| 100 | } |
| 101 | |
| 102 | PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__, |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 103 | "decompress($self, /, data, max_length=-1)\n" |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 104 | "--\n" |
| 105 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 106 | "Decompress *data*, returning uncompressed data as bytes.\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 107 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 108 | "If *max_length* is nonnegative, returns at most *max_length* bytes of\n" |
| 109 | "decompressed data. If this limit is reached and further output can be\n" |
| 110 | "produced, *self.needs_input* will be set to ``False``. In this case, the next\n" |
| 111 | "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] | 112 | "\n" |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 113 | "If all of the input data was decompressed and returned (either because this\n" |
| 114 | "was less than *max_length* bytes, or because *max_length* was negative),\n" |
| 115 | "*self.needs_input* will be set to True.\n" |
| 116 | "\n" |
| 117 | "Attempting to decompress data after the end of stream is reached raises an\n" |
| 118 | "EOFError. Any data found after the end of the stream is ignored and saved in\n" |
| 119 | "the unused_data attribute."); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 120 | |
| 121 | #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 122 | {"decompress", (PyCFunction)(void(*)(void))_bz2_BZ2Decompressor_decompress, METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__}, |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 123 | |
| 124 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 125 | _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data, |
| 126 | Py_ssize_t max_length); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 127 | |
| 128 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 129 | _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 130 | { |
| 131 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 132 | static const char * const _keywords[] = {"data", "max_length", NULL}; |
| 133 | static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0}; |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 134 | Py_buffer data = {NULL, NULL}; |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 135 | Py_ssize_t max_length = -1; |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 136 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 137 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 138 | &data, &max_length)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 139 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 140 | } |
Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 141 | return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length); |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 142 | |
| 143 | exit: |
| 144 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 145 | if (data.obj) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 146 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 147 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 148 | |
| 149 | return return_value; |
| 150 | } |
| 151 | |
| 152 | PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 153 | "BZ2Decompressor()\n" |
| 154 | "--\n" |
| 155 | "\n" |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 156 | "Create a decompressor object for decompressing data incrementally.\n" |
| 157 | "\n" |
| 158 | "For one-shot decompression, use the decompress() function instead."); |
| 159 | |
| 160 | static int |
| 161 | _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self); |
| 162 | |
| 163 | static int |
| 164 | _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 165 | { |
| 166 | int return_value = -1; |
| 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_NoPositional("BZ2Decompressor", args)) { |
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 | } |
Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 172 | if ((Py_TYPE(self) == &BZ2Decompressor_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 173 | !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 174 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 175 | } |
Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 176 | return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self); |
| 177 | |
| 178 | exit: |
| 179 | return return_value; |
| 180 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 181 | /*[clinic end generated code: output=8549cccdb82f57d9 input=a9049054013a1b77]*/ |