static PyObject *
Noddy_name(Noddy* self)
{
    static PyObject *format = NULL;
    PyObject *args, *result;

    if (format == NULL) {
        format = PyUnicode_FromString("%s %s");
        if (format == NULL)
            return NULL;
    }

    if (self->first == NULL) {
        PyErr_SetString(PyExc_AttributeError, "first");
        return NULL;
    }

    if (self->last == NULL) {
        PyErr_SetString(PyExc_AttributeError, "last");
        return NULL;
    }

    args = Py_BuildValue("OO", self->first, self->last);
    if (args == NULL)
        return NULL;

    result = PyUnicode_Format(format, args);
    Py_DECREF(args);
    
    return result;
}
Beispiel #2
0
static PyObject *
Py_cvec_repr (Py_cvec * self, PyObject * unused)
{
    PyObject *format = NULL;
    PyObject *args = NULL;
    PyObject *result = NULL;

    format = PyUnicode_FromString ("aubio cvec of %d elements");
    if (format == NULL) {
        goto fail;
    }

    args = Py_BuildValue ("I", self->length);
    if (args == NULL) {
        goto fail;
    }
    // hide actual norm / phas content

    result = PyUnicode_Format (format, args);

fail:
    Py_XDECREF (format);
    Py_XDECREF (args);

    return result;
}
Beispiel #3
0
static PyObject *
DecimalResultProcessor_process(DecimalResultProcessor *self, PyObject *value)
{
    PyObject *str, *result, *args;

    if (value == Py_None)
        Py_RETURN_NONE;

    /* Decimal does not accept float values directly */
    /* SQLite can also give us an integer here (see [ticket:2432]) */
    /* XXX: starting with Python 3.1, we could use Decimal.from_float(f),
                 but the result wouldn't be the same */

    args = PyTuple_Pack(1, value);
    if (args == NULL)
        return NULL;

#if PY_MAJOR_VERSION >= 3
    str = PyUnicode_Format(self->format, args);
#else
    str = PyString_Format(self->format, args);
#endif

    Py_DECREF(args);
    if (str == NULL)
        return NULL;

    result = PyObject_CallFunctionObjArgs(self->type, str, NULL);
    Py_DECREF(str);
    return result;
}
Beispiel #4
0
static PyObject *
range_index(rangeobject *r, PyObject *ob)
{
    PyObject *idx, *tmp;
    int contains;
    PyObject *format_tuple, *err_string;
    static PyObject *err_format = NULL;

    if (!PyLong_CheckExact(ob) && !PyBool_Check(ob)) {
        Py_ssize_t index;
        index = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_INDEX);
        if (index == -1)
            return NULL;
        return PyLong_FromSsize_t(index);
    }

    contains = range_contains_long(r, ob);
    if (contains == -1)
        return NULL;

    if (!contains)
        goto value_error;

    tmp = PyNumber_Subtract(ob, r->start);
    if (tmp == NULL)
        return NULL;

    /* idx = (ob - r.start) // r.step */
    idx = PyNumber_FloorDivide(tmp, r->step);
    Py_DECREF(tmp);
    return idx;

value_error:

    /* object is not in the range */
    if (err_format == NULL) {
        err_format = PyUnicode_FromString("%r is not in range");
        if (err_format == NULL)
            return NULL;
    }
    format_tuple = PyTuple_Pack(1, ob);
    if (format_tuple == NULL)
        return NULL;
    err_string = PyUnicode_Format(err_format, format_tuple);
    Py_DECREF(format_tuple);
    if (err_string == NULL)
        return NULL;
    PyErr_SetObject(PyExc_ValueError, err_string);
    Py_DECREF(err_string);
    return NULL;
}
Beispiel #5
0
PyObject *
PyNumber_Remainder(PyObject *v, PyObject *w)
{
	if (PyString_Check(v))
		return PyString_Format(v, w);
	else if (PyUnicode_Check(v))
		return PyUnicode_Format(v, w);
	BINOP(v, w, "__mod__", "__rmod__", PyNumber_Remainder);
	if (v->ob_type->tp_as_number != NULL) {
		PyObject *x = NULL;
		PyObject * (*f)(PyObject *, PyObject *);
		if (PyNumber_Coerce(&v, &w) != 0)
			return NULL;
		if ((f = v->ob_type->tp_as_number->nb_remainder) != NULL)
			x = (*f)(v, w);
		Py_DECREF(v);
		Py_DECREF(w);
		if (f != NULL)
			return x;
	}
	return type_error("bad operand type(s) for %");
}