Esempio n. 1
0
static PyObject *
O_writelines(Oobject *self, PyObject *args) {
    PyObject *it, *s;

    it = PyObject_GetIter(args);
    if (it == NULL)
        return NULL;
    while ((s = PyIter_Next(it)) != NULL) {
        Py_ssize_t n;
        char *c;
        if (PyString_AsStringAndSize(s, &c, &n) == -1) {
            Py_DECREF(it);
            Py_DECREF(s);
            return NULL;
        }
        if (O_cwrite((PyObject *)self, c, n) == -1) {
            Py_DECREF(it);
            Py_DECREF(s);
            return NULL;
           }
           Py_DECREF(s);
       }

       Py_DECREF(it);

       /* See if PyIter_Next failed */
       if (PyErr_Occurred())
           return NULL;

       Py_RETURN_NONE;
}
Esempio n. 2
0
static PyObject *
O_write(Oobject *self, PyObject *args) {
        char *c;
        int l;

        if (!PyArg_ParseTuple(args, "t#:write", &c, &l)) return NULL;

        if (O_cwrite((PyObject*)self,c,l) < 0) return NULL;

        Py_INCREF(Py_None);
        return Py_None;
}
Esempio n. 3
0
static PyObject *
O_write(Oobject *self, PyObject *args) {
    Py_buffer buf;
    int result;

    if (!PyArg_ParseTuple(args, "s*:write", &buf)) return NULL;

    result = O_cwrite((PyObject*)self, buf.buf, buf.len);
    PyBuffer_Release(&buf);
    if (result < 0) return NULL;

    Py_INCREF(Py_None);
    return Py_None;
}