static PyObject * pyg_enum_repr(PyGEnum *self) { GEnumClass *enum_class; const char *value; guint index; static char tmp[256]; long l; enum_class = g_type_class_ref(self->gtype); g_assert(G_IS_ENUM_CLASS(enum_class)); l = PYGLIB_PyLong_AS_LONG(self); for (index = 0; index < enum_class->n_values; index++) if (l == enum_class->values[index].value) break; value = enum_class->values[index].value_name; if (value) sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype)); else sprintf(tmp, "<enum %ld of type %s>", PYGLIB_PyLong_AS_LONG(self), g_type_name(self->gtype)); g_type_class_unref(enum_class); return PYGLIB_PyUnicode_FromString(tmp); }
static PyObject * pyg_flags_repr(PyGFlags *self) { char *tmp, *retval; PyObject *pyretval; tmp = generate_repr(self->gtype, PYGLIB_PyLong_AS_LONG(self)); if (tmp) retval = g_strdup_printf("<flags %s of type %s>", tmp, g_type_name(self->gtype)); else retval = g_strdup_printf("<flags %ld of type %s>", PYGLIB_PyLong_AS_LONG(self), g_type_name(self->gtype)); g_free(tmp); pyretval = PYGLIB_PyUnicode_FromString(retval); g_free(retval); return pyretval; }