Esempio n. 1
0
/*
 * Create new CDBMaker object
 */
PyObject *
cdbx_maker_new(PyTypeObject *cdb_cls, PyObject *file_)
{
    cdbmaker_t *self;
    int fd, res;

    if (!(self = GENERIC_ALLOC(&CDBMakerType)))
        return NULL;

    self->maker32 = NULL;
    self->flags = FL_CLOSED | FL_DESTROY;
    self->cdb_cls = (PyObject *)cdb_cls;
    Py_INCREF(self->cdb_cls);

    if (-1 == cdbx_obj_as_fd(file_, "w+b", &self->filename, &self->fp,
                             &res, &fd))
        goto error;
    if (res)
        self->flags |= FL_FP_OPENED;
    self->flags &= ~FL_CLOSED;

    if (-1 == cdbx_cdb32_maker_create(fd, &self->maker32))
        goto error;

    return (PyObject *)self;

error:
    Py_DECREF(self);
    return NULL;
}
Esempio n. 2
0
static PyObject *
TDI_SoupParserType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"listener", "dtd", NULL};
    PyObject *listener, *dtd, *decoder;
    soup_parser *self;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
                                     &listener, &dtd))
        return NULL;

    if (!(self = GENERIC_ALLOC(type)))
        return NULL;

    Py_INCREF(listener);
    self->listener = listener;

    if (!(self->nestable = PyObject_GetAttrString(dtd, "nestable")))
        goto error;

    if (!(self->cdata = PyObject_GetAttrString(dtd, "cdata")))
        goto error;

    if (!(self->empty = PyObject_GetAttrString(dtd, "empty")))
        goto error;

    if (!(decoder = PyObject_GetAttrString(listener, "decoder")))
        goto error;

    self->normalize = PyObject_GetAttrString(decoder, "normalize");
    Py_DECREF(decoder);
    if (!self->normalize)
        goto error;

    self->parser = tdi_soup_parser_new(
        parser_callback, self,
        parser_nestable, self,
        parser_cdata, self,
        parser_empty, self,
        parser_normalize, self
    );
    if (!self->parser)
        goto error;

    return (PyObject *)self;

error:
    Py_DECREF(self);
    return NULL;
}
Esempio n. 3
0
static PyObject *
TDI_SoupEncoderType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"encoding", NULL};
    PyObject *encoding;
    tdi_soup_encoder_t *self;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "S", kwlist, &encoding))
        return NULL;

    if (!(encoding = PyObject_Str(encoding)))
        return NULL;

    if (!(self = GENERIC_ALLOC(type))) {
        Py_DECREF(encoding);
        return NULL;
    }
    self->encoding = encoding;

    return (PyObject *)self;
}