1 | /*[clinic input] |
2 | preserve |
3 | [clinic start generated code]*/ |
4 | |
5 | PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__, |
6 | "compress($self, data, /)\n" |
7 | "--\n" |
8 | "\n" |
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 \ |
17 | {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__}, |
18 | |
19 | static PyObject * |
20 | _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data); |
21 | |
22 | static PyObject * |
23 | _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg) |
24 | { |
25 | PyObject *return_value = NULL; |
26 | Py_buffer data = {NULL, NULL}; |
27 | |
28 | if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) { |
29 | goto exit; |
30 | } |
31 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
32 | _PyArg_BadArgument("compress" , "argument" , "contiguous buffer" , arg); |
33 | goto exit; |
34 | } |
35 | return_value = _bz2_BZ2Compressor_compress_impl(self, &data); |
36 | |
37 | exit: |
38 | /* Cleanup for data */ |
39 | if (data.obj) { |
40 | PyBuffer_Release(&data); |
41 | } |
42 | |
43 | return return_value; |
44 | } |
45 | |
46 | PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__, |
47 | "flush($self, /)\n" |
48 | "--\n" |
49 | "\n" |
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_BZ2Decompressor_decompress__doc__, |
69 | "decompress($self, /, data, max_length=-1)\n" |
70 | "--\n" |
71 | "\n" |
72 | "Decompress *data*, returning uncompressed data as bytes.\n" |
73 | "\n" |
74 | "If *max_length* is nonnegative, returns at most *max_length* bytes of\n" |
75 | "decompressed data. If this limit is reached and further output can be\n" |
76 | "produced, *self.needs_input* will be set to ``False``. In this case, the next\n" |
77 | "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n" |
78 | "\n" |
79 | "If all of the input data was decompressed and returned (either because this\n" |
80 | "was less than *max_length* bytes, or because *max_length* was negative),\n" |
81 | "*self.needs_input* will be set to True.\n" |
82 | "\n" |
83 | "Attempting to decompress data after the end of stream is reached raises an\n" |
84 | "EOFError. Any data found after the end of the stream is ignored and saved in\n" |
85 | "the unused_data attribute." ); |
86 | |
87 | #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF \ |
88 | {"decompress", (PyCFunction)(void(*)(void))_bz2_BZ2Decompressor_decompress, METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__}, |
89 | |
90 | static PyObject * |
91 | _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data, |
92 | Py_ssize_t max_length); |
93 | |
94 | static PyObject * |
95 | _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
96 | { |
97 | PyObject *return_value = NULL; |
98 | static const char * const _keywords[] = {"data" , "max_length" , NULL}; |
99 | static _PyArg_Parser _parser = {NULL, _keywords, "decompress" , 0}; |
100 | PyObject *argsbuf[2]; |
101 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
102 | Py_buffer data = {NULL, NULL}; |
103 | Py_ssize_t max_length = -1; |
104 | |
105 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
106 | if (!args) { |
107 | goto exit; |
108 | } |
109 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
110 | goto exit; |
111 | } |
112 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
113 | _PyArg_BadArgument("decompress" , "argument 'data'" , "contiguous buffer" , args[0]); |
114 | goto exit; |
115 | } |
116 | if (!noptargs) { |
117 | goto skip_optional_pos; |
118 | } |
119 | { |
120 | Py_ssize_t ival = -1; |
121 | PyObject *iobj = _PyNumber_Index(args[1]); |
122 | if (iobj != NULL) { |
123 | ival = PyLong_AsSsize_t(iobj); |
124 | Py_DECREF(iobj); |
125 | } |
126 | if (ival == -1 && PyErr_Occurred()) { |
127 | goto exit; |
128 | } |
129 | max_length = ival; |
130 | } |
131 | skip_optional_pos: |
132 | return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length); |
133 | |
134 | exit: |
135 | /* Cleanup for data */ |
136 | if (data.obj) { |
137 | PyBuffer_Release(&data); |
138 | } |
139 | |
140 | return return_value; |
141 | } |
142 | /*[clinic end generated code: output=ed10705d7a9fd598 input=a9049054013a1b77]*/ |
143 | |