Example #1
0
static PyObject *
AMC_repr (AMC *motion)
{
	if (motion->name == NULL)
		return PyString_FromFormat ("[AMC]");
	return PyString_FromFormat ("[AMC \"%s\"]", motion->name);
}
Example #2
0
static PyObject *
pydatetime_str(pydatetimeObject *self)
{
    if (self->type <= PSYCO_DATETIME_TIMESTAMP) {
        PyObject *res = NULL;
        PyObject *iso = PyObject_CallMethod(self->wrapped, "isoformat", NULL);
        if (iso) {
            res = PyString_FromFormat("'%s'", PyString_AsString(iso));
            Py_DECREF(iso);
        }
        return res;
    }
    else {
        PyDateTime_Delta *obj = (PyDateTime_Delta*)self->wrapped;

        char buffer[8]; 
        int i;
        int a = obj->microseconds;

        for (i=0; i < 6 ; i++) {
            buffer[5-i] = '0' + (a % 10);
            a /= 10;
        }
        buffer[6] = '\0';

        return PyString_FromFormat("'%d days %d.%s seconds'",
                                   obj->days, obj->seconds, buffer);
    }
}
Example #3
0
static PyObject *
PyCField_repr(CFieldObject *self)
{
    PyObject *result;
    Py_ssize_t bits = self->size >> 16;
    Py_ssize_t size = self->size & 0xFFFF;
    const char *name;

    name = ((PyTypeObject *)self->proto)->tp_name;

    if (bits)
        result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
            "<Field type=%s, ofs=%d:%d, bits=%d>",
#else
            "<Field type=%s, ofs=%zd:%zd, bits=%zd>",
#endif
            name, self->offset, size, bits);
    else
        result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
            "<Field type=%s, ofs=%d, size=%d>",
#else
            "<Field type=%s, ofs=%zd, size=%zd>",
#endif
            name, self->offset, size);
    return result;
}
Example #4
0
    static PyObject* enum_repr(PyObject* self_)
    {
        // XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference
        // const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast<char*>("__module__")));
        PyObject *mod = PyObject_GetAttrString( self_, "__module__");
        enum_object* self = downcast<enum_object>(self_);
        if (!self->name)
        {
            return
#if PY_VERSION_HEX >= 0x03000000
                PyUnicode_FromFormat("%S.%s(%ld)", mod, self_->ob_type->tp_name, PyLong_AsLong(self_));
#else
                PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AS_LONG(self_));
#endif
        }
        else
        {
            PyObject* name = self->name;
            if (name == 0)
                return 0;

            return
#if PY_VERSION_HEX >= 0x03000000
                PyUnicode_FromFormat("%S.%s.%S", mod, self_->ob_type->tp_name, name);
#else
                PyString_FromFormat("%s.%s.%s", 
                        PyString_AsString(mod), self_->ob_type->tp_name, PyString_AsString(name));
#endif
        }
    }
Example #5
0
static PyObject *
DBusPythonLong_tp_repr(PyObject *self)
{
    PyObject *parent_repr = (PyLong_Type.tp_repr)(self);
    PyObject *vl_obj;
    PyObject *my_repr;
    long variant_level;

    if (!parent_repr) return NULL;
    vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const);
    if (!vl_obj) {
        Py_DECREF(parent_repr);
        return NULL;
    }
    variant_level = PyInt_AsLong(vl_obj);
    Py_DECREF(vl_obj);
    if (variant_level) {
        my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)",
                                      self->ob_type->tp_name,
                                      PyString_AS_STRING(parent_repr),
                                      variant_level);
    }
    else {
        my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name,
                                      PyString_AS_STRING(parent_repr));
    }
    /* whether my_repr is NULL or not: */
    Py_DECREF(parent_repr);
    return my_repr;
}
Example #6
0
static PyObject *
normalizeUserObj(PyObject *obj)
{
	PyCFunctionObject *fn;
	if (!PyCFunction_Check(obj)) {
		Py_INCREF(obj);
		return obj;
	}
	/* Replace built-in function objects with a descriptive string
	   because of built-in methods -- keeping a reference to
	   __self__ is probably not a good idea. */
	fn = (PyCFunctionObject *)obj;

	if (fn->m_self == NULL) {
		/* built-in function: look up the module name */
		PyObject *mod = fn->m_module;
		char *modname;
		if (mod && PyString_Check(mod)) {
			modname = PyString_AS_STRING(mod);
		}
		else if (mod && PyModule_Check(mod)) {
			modname = PyModule_GetName(mod);
			if (modname == NULL) {
				PyErr_Clear();
				modname = "__builtin__";
			}
		}
		else {
			modname = "__builtin__";
		}
		if (strcmp(modname, "__builtin__") != 0)
			return PyString_FromFormat("<%s.%s>",
						   modname,
						   fn->m_ml->ml_name);
		else
			return PyString_FromFormat("<%s>",
						   fn->m_ml->ml_name);
	}
	else {
		/* built-in method: try to return
			repr(getattr(type(__self__), __name__))
		*/
		PyObject *self = fn->m_self;
		PyObject *name = PyString_FromString(fn->m_ml->ml_name);
		if (name != NULL) {
			PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
			Py_XINCREF(mo);
			Py_DECREF(name);
			if (mo != NULL) {
				PyObject *res = PyObject_Repr(mo);
				Py_DECREF(mo);
				if (res != NULL)
					return res;
			}
		}
		PyErr_Clear();
		return PyString_FromFormat("<built-in method %s>",
					   fn->m_ml->ml_name);
	}
}
Example #7
0
File: type.c Project: zillow/ctds
static PyObject* SqlType_repr(PyObject* self)
{
    const struct SqlType* type = (const struct SqlType*)self;
    PyObject* repr = NULL;

    bool include_size = (-1 != type->size);

#if PY_MAJOR_VERSION < 3
    /*
        Python2.6's implementation of `PyUnicode_FromFormat` is buggy and
        will crash when the '%R' format specifier is used. Additionally
        a conversion to the `str` type is required. Avoid all this in Python2.
    */
    PyObject* value = PyObject_Repr(type->value);
    if (value)
    {
        if (include_size)
        {
            repr = PyString_FromFormat(
                "%s(%s, size=%d)",
                Py_TYPE(self)->tp_name,
                PyString_AS_STRING(value),
                type->size
            );
        }
        else
        {
            repr = PyString_FromFormat(
                "%s(%s)",
                Py_TYPE(self)->tp_name,
                PyString_AS_STRING(value)
            );
        }
        Py_DECREF(value);
    }
#else /* if PY_MAJOR_VERSION < 3 */
    if (include_size)
    {
        repr = PyUnicode_FromFormat(
            "%s(%R, size=%d)",
            Py_TYPE(self)->tp_name,
            type->value,
            type->size
        );
    }
    else
    {
        repr = PyUnicode_FromFormat(
            "%s(%R)",
            Py_TYPE(self)->tp_name,
            type->value
        );
    }
#endif /* else if PY_MAJOR_VERSION < 3 */
    return repr;
}
Example #8
0
static PyObject *
cell_repr(PyCellObject *op)
{
	if (op->ob_ref == NULL)
		return PyString_FromFormat("<cell at %p: empty>", op);

	return PyString_FromFormat("<cell at %p: %.80s object at %p>",
				   op, op->ob_ref->ob_type->tp_name,
				   op->ob_ref);
}
SWIGRUNTIME PyObject *
PySwigPacked_str(PySwigPacked *v)
{
  char result[SWIG_BUFFER_SIZE];
  if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
    return PyString_FromFormat("%s%s", result, v->desc);
  } else {
    return PyString_FromFormat("%s", v->desc);
  }  
}
Example #10
0
static PyObject *
meth_repr(PyCFunctionObject *m)
{
    if (m->m_self == NULL)
        return PyString_FromFormat("<built-in function %s>",
                                   m->m_ml->ml_name);
    return PyString_FromFormat("<built-in method %s of %s object at %p>",
                               m->m_ml->ml_name,
                               m->m_self->ob_type->tp_name,
                               m->m_self);
}
Example #11
0
static PyObject *
range_repr(range *self)
{
	if (self->step == 1)
	{
		return PyString_FromFormat("range(%i, %i)", self->start, self->stop);
	}
	else
	{
		return PyString_FromFormat("range(%i, %i, %i)", self->start, self->stop, self->step);
	}
}
Example #12
0
/* Representation */
static PyObject* PyBlitzArray_repr(PyBlitzArrayObject* o) {
  switch (o->ndim) {
    case 1:
      return
        PyString_FromFormat
          ("%s(%" PY_FORMAT_SIZE_T "d,'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 2:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 3:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          o->shape[2],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 4:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          o->shape[2],
          o->shape[3],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    default:
      return
        PyString_FromFormat
          ("[unsupported] %s(@%" PY_FORMAT_SIZE_T "d,'%s') %" PY_FORMAT_SIZE_T "d elements>",
          Py_TYPE(o)->tp_name,
          o->ndim,
          PyBlitzArray_TypenumAsString(o->type_num),
          PyBlitzArray_len(o)
          );
  }
}
Example #13
0
static PyObject *
preparePreLink(const char *prelink) {
	int len;
	len = strlen(prelink);
	if (strstr(prelink, "?") != NULL) {
		if (prelink[len-1] != '?' && prelink[len-1] != '&') {
			return PyString_FromFormat("%s&", prelink);
		} else {
			return PyString_FromString(prelink);
		}
	} else {
		return PyString_FromFormat("%s?", prelink);
	}
}
Example #14
0
static PyObject *
package_repr(_PackageObject *self)
{
    cr_Package *pkg = self->package;
    PyObject *repr;
    if (pkg) {
        repr = PyString_FromFormat("<createrepo_c.Package object id %s, %s>",
                                   (pkg->pkgId ? pkg->pkgId : "-"),
                                   (pkg->name  ? pkg->name  : "-"));
    } else {
       repr = PyString_FromFormat("<createrepo_c.Package object id -, ->");
    }
    return repr;
}
static PyObject *
meth_repr(PythonQtSignalFunctionObject *f)
{
  if (f->m_self->ob_type == &PythonQtClassWrapper_Type) {
    PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self;
    return PyString_FromFormat("<unbound qt signal %s of %s type>",
      f->m_ml->slotName().data(),
      self->classInfo()->className());
  } else {
    return PyString_FromFormat("<qt signal %s of %s instance at %p>",
      f->m_ml->slotName().data(),
      f->m_self->ob_type->tp_name,
      f->m_self);
  }
}
Example #16
0
static PyObject *
DiscoDBIter_str(DiscoDBIter *self)
{
    PyObject
        *string = PyString_FromFormat("%s(", Py_TYPE(self)->tp_name),
        *format = NULL;

    if (string == NULL)
        goto Done;

    if (Py_TYPE(self) == &DiscoDBIterItemType)
        format = PyString_FromString("('%s', %s)");
    else
        format = PyString_FromString("'%s'");

    if (format == NULL)
        goto Done;

    PyString_ConcatAndDel(&string, DiscoDBIter_format(self, format, 3));
    PyString_ConcatAndDel(&string, PyString_FromString(")"));

 Done:
    Py_CLEAR(format);

    if (PyErr_Occurred()) {
        Py_CLEAR(string);
        return NULL;
    }

    return string;
}
Example #17
0
/*
 *	This is the core Python function that the others wrap around.
 *	Pass the value-pair print strings in a tuple.
 *
 *	FIXME: We're not checking the errors. If we have errors, what
 *	do we do?
 */
static int mod_populate_vptuple(PyObject *pPair, VALUE_PAIR *vp)
{
	PyObject *pStr = NULL;
	char buf[1024];
	
	/* Look at the vp_print_name? */
	
	if (vp->da->flags.has_tag)
		pStr = PyString_FromFormat("%s:%d", vp->da->name, vp->tag);
	else
		pStr = PyString_FromString(vp->da->name);
	
	if (!pStr)
		goto failed;
	
	PyTuple_SET_ITEM(pPair, 0, pStr);
	
	vp_prints_value(buf, sizeof(buf), vp, 1);
	
	if ((pStr = PyString_FromString(buf)) == NULL)
		goto failed;
	PyTuple_SET_ITEM(pPair, 1, pStr);
	
	return 0;
	
failed:
	return -1;
}
Example #18
0
/** \ingroup python_interface_arpack
 * \brief Formats an \c igraph.ARPACKOptions object in a
 * human-consumable format.
 * 
 * \return the formatted textual representation as a \c PyObject
 */
PyObject* igraphmodule_ARPACKOptions_str(
  igraphmodule_ARPACKOptionsObject *self) {
  PyObject *s;
  
  s=PyString_FromFormat("ARPACK parameters");
  return s;
}
static PyObject *SymbolicExpression_getComment(PyObject *self, PyObject *noarg) {
  SymbolicExpression *expression = PySymbolicExpression_AsSymbolicExpression(self);
  if (expression->getComment().empty() == false)
    return PyString_FromFormat("%s", expression->getComment().c_str());
  Py_INCREF(Py_None);
  return Py_None;
}
Example #20
0
static PyObject *
connection_repr(connectionObject *self)
{
    return PyString_FromFormat(
        "<connection object at %p; dsn: '%s', closed: %ld>",
        self, (self->dsn ? self->dsn : "<unintialized>"), self->closed);
}
Example #21
0
void
handle_core_message(DBusMessage *bus_msg, const char *path, const char *iface, const char *method, const char *sender, PyObject *py_args)
{
    if (strcmp(method, "setLocale") == 0) {
        PyDict_SetItemString(PyDict_GetItemString(py_core, "locales"), sender, PyTuple_GetItem(py_args, 0));
        bus_reply_object(bus_msg, Py_True, "b");
    }
    else if (strcmp(method, "cancel") == 0) {
        log_debug("Cancel requested.\n");
        int i;
        int total = 0;
        // Iterate over all child processes
        for (i = 0; i < my_proc.nr_children; i++) {
            struct ProcChild *child = &my_proc.children[i];
            if (dbus_message_has_sender(child->bus_msg, sender)) {
                kill(child->pid, SIGINT);
                total++;
            }
        }
        log_debug("Killed %d processes.\n", total);
        bus_reply_object(bus_msg, PyInt_FromLong((long) total), "i");
    }
    else if (strcmp(method, "listRunning") == 0) {
        int i;
        PyObject *py_list = PyList_New(0);
        // Iterate over all child processes
        for (i = 0; i < my_proc.nr_children; i++) {
            struct ProcChild *child = &my_proc.children[i];
            if (PyTuple_GetItem(py_args, 0) == Py_True || dbus_message_has_sender(child->bus_msg, sender)) {
                PyList_Append(py_list, PyString_FromFormat("%s.%s", dbus_message_get_interface(child->bus_msg), dbus_message_get_member(child->bus_msg)));
            }
        }
        bus_reply_object(bus_msg, py_list, "as");
    }
}
Example #22
0
static PyObject *
replicationConnection_repr(replicationConnectionObject *self)
{
    return PyString_FromFormat(
        "<ReplicationConnection object at %p; dsn: '%s', closed: %ld>",
        self, self->conn.dsn, self->conn.closed);
}
SWIGRUNTIME PyObject *
PySwigObject_repr(PySwigObject *v)
{
  char result[SWIG_BUFFER_SIZE];
  return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
    PyString_FromFormat("<Swig Object at %s>", result) : 0;
}
Example #24
0
static PyObject *
Wmii_write(Wmii *self, PyObject *args)
{
    const char *file;
    const char *data;

    IxpCFid *fid;

    if (!PyArg_ParseTuple(args, "ss", &file,  &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.write() takes exactly 2 arguments");
        return NULL;
    }

    fid = ixp_open(self->client, file, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't open file '%s'\n", file));
        return NULL;
    }

    ixp_write(fid, data, strlen(data));

    ixp_close(fid);

    Py_RETURN_NONE;
}
		// ------------------------------------------
		PyObject* ConfigServiceBinder::repr(PyObject* self) {
#ifdef IS_PY3K
			return PyBytes_FromFormat("<ConfigService at %p>", self);
#else
			return PyString_FromFormat("<ConfigService at %p>", self);
#endif
		}
Example #26
0
init_imagingcms(void)
{
    PyObject *m;
    PyObject *d;
    PyObject *v;

    /* Patch up object types */
    CmsProfile_Type.ob_type = &PyType_Type;
    CmsTransform_Type.ob_type = &PyType_Type;

    m = Py_InitModule("_imagingcms", pyCMSdll_methods);

    d = PyModule_GetDict(m);

#if PY_VERSION_HEX >= 0x02020000
    v = PyString_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
#else
    {
        char buffer[100];
        sprintf(buffer, "%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
        v = PyString_FromString(buffer);
    }
#endif
    PyDict_SetItemString(d, "littlecms_version", v);
}
Example #27
0
static PyObject *
DiscoDB_str(DiscoDB *self)
{
    PyObject
        *string = PyString_FromFormat("%s({", Py_TYPE(self)->tp_name),
        *format = PyString_FromString("'%s': %s"),
        *items = NULL;

    if (string == NULL)
        goto Done;

    if (format == NULL)
        goto Done;

    items = DiscoDB_items(self);
    if (items == NULL)
        goto Done;

    PyString_ConcatAndDel(&string, DiscoDBIter_format((DiscoDBIter *)items, format, 3));
    PyString_ConcatAndDel(&string, PyString_FromString("})"));

 Done:
    Py_CLEAR(format);
    Py_CLEAR(items);

    if (PyErr_Occurred()) {
        Py_CLEAR(string);
        return NULL;
    }

    return string;
}
Example #28
0
static PyObject *
Wmii_create(Wmii *self, PyObject *args)
{
    IxpCFid *fid;
    const char *file;
    const char *data;

    if (!PyArg_ParseTuple(args, "s|s", &file, &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.create() requires 1 argument");
        return NULL;
    }

    fid = ixp_create(self->client, file, 0777, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't create file '%s'\n", file));
    }

    if((fid->qid.type&P9_DMDIR) == 0)
    {
        if(strlen(data)) {
            ixp_write(fid, data, strlen(data));
        }
    }
    ixp_close(fid);
    Py_RETURN_NONE;
}
Example #29
0
static PyObject* Bar_Str(BarObject *self) {
  // Returns a string representation of this object.
  return PyString_FromFormat
    ("<%s, %s %d of %s %p>", Py_TYPE(self)->tp_name,
     Bar_Row(self)?"row":"col", Bar_Index(self),
     LPXType.tp_name, self->py_bc->py_lp);
}
		// ------------------------------------------
		PyObject* DataFieldDescIteratorBinder::repr(PyObject *self) {
#ifdef IS_PY3K
			return PyBytes_FromFormat("<DataFieldDescIterator at %p>", self);
#else
			return PyString_FromFormat("<DataFieldDescIterator at %p>", self);
#endif
		}