Пример #1
0
static PyObject *_internal_stream_dump(PyObject *args, unsigned int blocking)
{
    PyObject *encoder = NULL;
    PyObject *stream = NULL;
    PyObject *buffer = NULL;
    PyObject *object = NULL;

    if (!PyArg_ParseTuple(args, "OO", &object, &stream)) {
        goto bad_type;
    }

    if (__write == NULL) {
        __write = PyString_FromString("write");
    }

    if (!PyObject_HasAttr(stream, __write)) {
        goto bad_type;
    }

    encoder = PyObject_Call((PyObject *)(&YajlEncoderType), NULL, NULL);
    if (encoder == NULL) {
        return NULL;
    }

    buffer = _internal_encode((_YajlEncoder *)encoder, object);
    PyObject_CallMethodObjArgs(stream, __write, buffer, NULL);
    Py_XDECREF(encoder);
    return Py_True;

bad_type:
    PyErr_SetObject(PyExc_TypeError, PyString_FromString("Must pass a stream object"));
    return NULL;
}
Пример #2
0
static PyObject *py_dumps(PYARGS)
{
    PyObject *encoder = NULL;
    PyObject *obj = NULL;
    PyObject *result = NULL;
    PyObject *indent = NULL;
    yajl_gen_config config = { 0, NULL };
    static char *kwlist[] = {"object", "indent", NULL};
    char *spaces = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &obj, &indent)) {
        return NULL;
    }

    spaces = __config_gen_config(indent, &config);
    if (PyErr_Occurred()) {
        return NULL;
    }

    encoder = PyObject_Call((PyObject *)(&YajlEncoderType), NULL, NULL);
    if (encoder == NULL) {
        return NULL;
    }

    result = _internal_encode((_YajlEncoder *)encoder, obj, config);
    Py_XDECREF(encoder);
    if (spaces) {
        free(spaces);
    }
    return result;
}
Пример #3
0
PyObject *py_yajlencoder_encode(PYARGS)
{
    _YajlEncoder *encoder = (_YajlEncoder *)(self);
    PyObject *value;

    if (!PyArg_ParseTuple(args, "O", &value))
        return NULL;

    return _internal_encode(encoder, value);
}
Пример #4
0
static PyObject *py_dumps(PYARGS)
{
    PyObject *encoder = NULL;
    PyObject *obj = NULL;
    PyObject *result = NULL;

    if (!PyArg_ParseTuple(args, "O", &obj)) {
        return NULL;
    }

    encoder = PyObject_Call((PyObject *)(&YajlEncoderType), NULL, NULL);
    if (encoder == NULL) {
        return NULL;
    }

    result = _internal_encode((_YajlEncoder *)encoder, obj);
    Py_XDECREF(encoder);
    return result;
}