| 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 | 247789c | 2015-04-24 00:40:51 +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; | 
 | 30 |     return_value = _bz2_BZ2Compressor_compress_impl(self, &data); | 
 | 31 |  | 
 | 32 | exit: | 
 | 33 |     /* Cleanup for data */ | 
 | 34 |     if (data.obj) | 
 | 35 |        PyBuffer_Release(&data); | 
 | 36 |  | 
 | 37 |     return return_value; | 
 | 38 | } | 
 | 39 |  | 
 | 40 | PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 41 | "flush($self, /)\n" | 
 | 42 | "--\n" | 
 | 43 | "\n" | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 44 | "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 |  | 
 | 53 | static PyObject * | 
 | 54 | _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self); | 
 | 55 |  | 
 | 56 | static PyObject * | 
 | 57 | _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored)) | 
 | 58 | { | 
 | 59 |     return _bz2_BZ2Compressor_flush_impl(self); | 
 | 60 | } | 
 | 61 |  | 
 | 62 | PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 63 | "BZ2Compressor(compresslevel=9, /)\n" | 
 | 64 | "--\n" | 
 | 65 | "\n" | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 66 | "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 |  | 
 | 73 | static int | 
 | 74 | _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel); | 
 | 75 |  | 
 | 76 | static int | 
 | 77 | _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) | 
 | 78 | { | 
 | 79 |     int return_value = -1; | 
 | 80 |     int compresslevel = 9; | 
 | 81 |  | 
| Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 82 |     if ((Py_TYPE(self) == &BZ2Compressor_Type) && | 
 | 83 |         !_PyArg_NoKeywords("BZ2Compressor", kwargs)) | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 84 |         goto exit; | 
| Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 85 |     if (!PyArg_ParseTuple(args, "|i:BZ2Compressor", | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 86 |         &compresslevel)) | 
 | 87 |         goto exit; | 
 | 88 |     return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel); | 
 | 89 |  | 
 | 90 | exit: | 
 | 91 |     return return_value; | 
 | 92 | } | 
 | 93 |  | 
 | 94 | PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__, | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 95 | "decompress($self, /, data, max_length=-1)\n" | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 96 | "--\n" | 
 | 97 | "\n" | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 98 | "Decompress *data*, returning uncompressed data as bytes.\n" | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 99 | "\n" | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 100 | "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 Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 104 | "\n" | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 105 | "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 Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 112 |  | 
 | 113 | #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF    \ | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 114 |     {"decompress", (PyCFunction)_bz2_BZ2Decompressor_decompress, METH_VARARGS|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__}, | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 115 |  | 
 | 116 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 117 | _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data, | 
 | 118 |                                      Py_ssize_t max_length); | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 119 |  | 
 | 120 | static PyObject * | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 121 | _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *args, PyObject *kwargs) | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 122 | { | 
 | 123 |     PyObject *return_value = NULL; | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 124 |     static char *_keywords[] = {"data", "max_length", NULL}; | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 125 |     Py_buffer data = {NULL, NULL}; | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 126 |     Py_ssize_t max_length = -1; | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 127 |  | 
| Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 128 |     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|n:decompress", _keywords, | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 129 |         &data, &max_length)) | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 130 |         goto exit; | 
| Antoine Pitrou | e71258a | 2015-02-26 13:08:07 +0100 | [diff] [blame] | 131 |     return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length); | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 132 |  | 
 | 133 | exit: | 
 | 134 |     /* Cleanup for data */ | 
 | 135 |     if (data.obj) | 
 | 136 |        PyBuffer_Release(&data); | 
 | 137 |  | 
 | 138 |     return return_value; | 
 | 139 | } | 
 | 140 |  | 
 | 141 | PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 142 | "BZ2Decompressor()\n" | 
 | 143 | "--\n" | 
 | 144 | "\n" | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 145 | "Create a decompressor object for decompressing data incrementally.\n" | 
 | 146 | "\n" | 
 | 147 | "For one-shot decompression, use the decompress() function instead."); | 
 | 148 |  | 
 | 149 | static int | 
 | 150 | _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self); | 
 | 151 |  | 
 | 152 | static int | 
 | 153 | _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) | 
 | 154 | { | 
 | 155 |     int return_value = -1; | 
 | 156 |  | 
| Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 157 |     if ((Py_TYPE(self) == &BZ2Decompressor_Type) && | 
 | 158 |         !_PyArg_NoPositional("BZ2Decompressor", args)) | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 159 |         goto exit; | 
| Larry Hastings | f0537e8 | 2014-01-25 22:01:12 -0800 | [diff] [blame] | 160 |     if ((Py_TYPE(self) == &BZ2Decompressor_Type) && | 
 | 161 |         !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) | 
| Serhiy Storchaka | 1bc4bb2 | 2014-01-25 12:07:57 +0200 | [diff] [blame] | 162 |         goto exit; | 
 | 163 |     return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self); | 
 | 164 |  | 
 | 165 | exit: | 
 | 166 |     return return_value; | 
 | 167 | } | 
| Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 168 | /*[clinic end generated code: output=fef29b76b3314fc7 input=a9049054013a1b77]*/ |