PyObject * Filter_SubFileDecode(PyObject * self, PyObject * args) { PyObject * target; PyObject * delim_object; SubFileDecodeState * state; int length; if (!PyArg_ParseTuple(args, "OS", &target, &delim_object)) return NULL; length = PyString_Size(delim_object); if (length < 1) return PyErr_Format(PyExc_ValueError, "empty delimiter"); state = PyMem_Malloc(sizeof (SubFileDecodeState) + length * sizeof(int)); if (!state) return PyErr_NoMemory(); state->delim_object = delim_object; Py_INCREF(state->delim_object); state->delim = PyString_AsString(delim_object); state->chars_matched = 0; state->length = length; init_shift(state); return Filter_NewDecoder(target, "SubFileDecode", 0, read_subfile, NULL, dealloc_subfile, state); }
PyObject * Filter_FlateDecode(PyObject * self, PyObject * args) { PyObject * target; FlateDecodeState * state; int result; if (!PyArg_ParseTuple(args, "O", &target)) return NULL; state = PyMem_Malloc(sizeof(FlateDecodeState)); if (!state) return PyErr_NoMemory(); state->buffer = PyMem_Malloc(INBUFSIZE); if (!state->buffer) { PyMem_Free(state); return PyErr_NoMemory(); } state->buffer_length = INBUFSIZE; state->zstr.zalloc = NULL; state->zstr.zfree = NULL; state->zstr.opaque = NULL; state->zstr.next_in = state->buffer; state->zstr.avail_in = 0; state->eod_reached = 0; result = inflateInit(&state->zstr); if (result != Z_OK) { if (result == Z_MEM_ERROR) { PyErr_SetString(PyExc_MemoryError, "FlateDecode: No memory for z_stream"); } else { if (state->zstr.msg == Z_NULL) PyErr_Format(PyExc_IOError, "FlateDecode: Zlib Error %i", result); else PyErr_Format(PyExc_IOError, "FlateDecode: Zlib Error %i: %.200s", result, state->zstr.msg); } PyMem_Free(state->buffer); PyMem_Free(state); return NULL; } return Filter_NewDecoder(target, "FlateDecode", 0, read_zlib, NULL, dealloc_zlib, state); }
PyObject * Filter_LineDecode(PyObject * self, PyObject * args) { PyObject * source; int * data; if (!PyArg_ParseTuple(args, "O", &source)) return NULL; data = malloc(sizeof(int)); if (!data) return PyErr_NoMemory(); *data = 0; return Filter_NewDecoder(source, "LineDecode", 0, read_nl, NULL, free, data); }
PyObject * Filter_StringDecode(PyObject * self, PyObject * args) { PyObject * source; PyObject * string; StringDecodeState * state; if (!PyArg_ParseTuple(args, "SO", &string, &source)) return NULL; state = malloc(sizeof (StringDecodeState)); if (!state) return PyErr_NoMemory(); state->string = string; Py_INCREF(state->string); state->pos = PyString_AsString(string); state->left = PyString_Size(string); return Filter_NewDecoder(source, "StringDecode", 0, read_string, NULL, string_state_dealloc, state); }