本文整理汇总了C++中PyObject_TypeCheck函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_TypeCheck函数的具体用法?C++ PyObject_TypeCheck怎么用?C++ PyObject_TypeCheck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_TypeCheck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pyg_value_from_pyobject
/**
* pyg_value_from_pyobject:
* @value: the GValue object to store the converted value in.
* @obj: the Python object to convert.
*
* This function converts a Python object and stores the result in a
* GValue. The GValue must be initialised in advance with
* g_value_init(). If the Python object can't be converted to the
* type of the GValue, then an error is returned.
*
* Returns: 0 on success, -1 on error.
*/
int
pyg_value_from_pyobject(GValue *value, PyObject *obj)
{
PyObject *tmp;
switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
case G_TYPE_INTERFACE:
/* we only handle interface types that have a GObject prereq */
if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT)) {
if (obj == Py_None)
g_value_set_object(value, NULL);
else {
if (!PyObject_TypeCheck(obj, &PyGObject_Type)) {
return -1;
}
if (!G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
G_VALUE_TYPE(value))) {
return -1;
}
g_value_set_object(value, pygobject_get(obj));
}
} else {
return -1;
}
break;
case G_TYPE_CHAR:
#if PY_VERSION_HEX < 0x03000000
if (PyString_Check(obj)) {
g_value_set_char(value, PyString_AsString(obj)[0]);
} else
#endif
if (PyUnicode_Check(obj)) {
tmp = PyUnicode_AsUTF8String(obj);
g_value_set_char(value, PYGLIB_PyBytes_AsString(tmp)[0]);
Py_DECREF(tmp);
} else {
PyErr_Clear();
return -1;
}
break;
case G_TYPE_UCHAR:
if (PYGLIB_PyLong_Check(obj)) {
glong val;
val = PYGLIB_PyLong_AsLong(obj);
if (val >= 0 && val <= 255)
g_value_set_uchar(value, (guchar)PYGLIB_PyLong_AsLong (obj));
else
return -1;
#if PY_VERSION_HEX < 0x03000000
} else if (PyString_Check(obj)) {
g_value_set_uchar(value, PyString_AsString(obj)[0]);
#endif
} else if (PyUnicode_Check(obj)) {
tmp = PyUnicode_AsUTF8String(obj);
g_value_set_uchar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
Py_DECREF(tmp);
} else {
PyErr_Clear();
return -1;
}
break;
case G_TYPE_BOOLEAN:
g_value_set_boolean(value, PyObject_IsTrue(obj));
break;
case G_TYPE_INT:
g_value_set_int(value, PYGLIB_PyLong_AsLong(obj));
break;
case G_TYPE_UINT:
{
if (PYGLIB_PyLong_Check(obj)) {
glong val;
val = PYGLIB_PyLong_AsLong(obj);
if (val >= 0 && val <= G_MAXUINT)
g_value_set_uint(value, (guint)val);
else
return -1;
} else {
g_value_set_uint(value, PyLong_AsUnsignedLong(obj));
}
}
break;
case G_TYPE_LONG:
g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
break;
case G_TYPE_ULONG:
#if PY_VERSION_HEX < 0x03000000
//.........这里部分代码省略.........
示例2: PyDict_GetItemString
PyObject* ItemSupplier::create(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
{
try
{
// Pick up the supplier
PyObject* sup = PyDict_GetItemString(kwds,"supplier");
if (!sup)
throw DataException("missing supplier on ItemSupplier");
if (!PyObject_TypeCheck(sup, Supplier::metadata->pythonClass))
throw DataException("ItemSupplier supplier must be of type supplier");
// Pick up the item
PyObject* it = PyDict_GetItemString(kwds,"item");
if (!it)
throw DataException("missing item on ItemSupplier");
if (!PyObject_TypeCheck(it, Item::metadata->pythonClass))
throw DataException("ItemSupplier item must be of type item");
// Pick up the priority
PyObject* q1 = PyDict_GetItemString(kwds,"priority");
int q2 = q1 ? PythonData(q1).getInt() : 1;
// Pick up the effective dates
DateRange eff;
PyObject* eff_start = PyDict_GetItemString(kwds,"effective_start");
if (eff_start)
{
PythonData d(eff_start);
eff.setStart(d.getDate());
}
PyObject* eff_end = PyDict_GetItemString(kwds,"effective_end");
if (eff_end)
{
PythonData d(eff_end);
eff.setEnd(d.getDate());
}
// Create the ItemSupplier
ItemSupplier *l = new ItemSupplier(
static_cast<Supplier*>(sup),
static_cast<Item*>(it),
q2, eff
);
// Iterate over extra keywords, and set attributes. @todo move this responsibility to the readers...
if (l)
{
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(kwds, &pos, &key, &value))
{
PythonData field(value);
PyObject* key_utf8 = PyUnicode_AsUTF8String(key);
DataKeyword attr(PyBytes_AsString(key_utf8));
Py_DECREF(key_utf8);
if (!attr.isA(Tags::effective_end) && !attr.isA(Tags::effective_start)
&& !attr.isA(Tags::supplier) && !attr.isA(Tags::item)
&& !attr.isA(Tags::type) && !attr.isA(Tags::action))
{
const MetaFieldBase* fmeta = l->getType().findField(attr.getHash());
if (!fmeta && l->getType().category)
fmeta = l->getType().category->findField(attr.getHash());
if (fmeta)
// Update the attribute
fmeta->setField(l, field);
else
l->setProperty(attr.getName(), value);
}
};
}
// Return the object
Py_INCREF(l);
return static_cast<PyObject*>(l);
}
catch (...)
{
PythonType::evalException();
return NULL;
}
}
示例3: qpyqml_convertTo_QJSValue
// Convert a Python object to a QJSValue.
int qpyqml_convertTo_QJSValue(PyObject *py, PyObject *transferObj,
QJSValue **cpp, int *isErr)
{
if (PyObject_TypeCheck(py, sipTypeAsPyTypeObject(sipType_QJSValue_SpecialValue)))
{
*cpp = new QJSValue((QJSValue::SpecialValue)SIPLong_AsLong(py));
return sipGetState(transferObj);
}
if (PyBool_Check(py))
{
*cpp = new QJSValue(py == Py_True);
return sipGetState(transferObj);
}
#if PY_MAJOR_VERSION >= 3
if (PyLong_Check(py))
{
*cpp = new QJSValue((int)PyLong_AS_LONG(py));
return sipGetState(transferObj);
}
#else
if (PyInt_Check(py))
{
*cpp = new QJSValue((int)PyInt_AS_LONG(py));
return sipGetState(transferObj);
}
#endif
if (PyFloat_Check(py))
{
*cpp = new QJSValue((double)PyFloat_AS_DOUBLE(py));
return sipGetState(transferObj);
}
if (sipCanConvertToType(py, sipType_QString, 0))
{
int state;
QString *qs = reinterpret_cast<QString *>(sipConvertToType(py,
sipType_QString, 0, 0, &state, isErr));
if (*isErr)
{
sipReleaseType(qs, sipType_QString, state);
return 0;
}
*cpp = new QJSValue(*qs);
sipReleaseType(qs, sipType_QString, state);
return sipGetState(transferObj);
}
*cpp = reinterpret_cast<QJSValue *>(sipConvertToType(py, sipType_QJSValue,
transferObj, SIP_NO_CONVERTORS, 0, isErr));
return 0;
}
示例4: Wcs_init
static int
Wcs_init(
Wcs* self,
PyObject* args,
/*@un[email protected]*/ PyObject* kwds) {
size_t i;
PyObject* py_sip;
PyObject* py_wcsprm;
PyObject* py_distortion_lookup[2];
PyObject* py_det2im[2];
if (!PyArg_ParseTuple
(args, "O(OO)O(OO):Wcs.__init__",
&py_sip,
&py_distortion_lookup[0],
&py_distortion_lookup[1],
&py_wcsprm,
&py_det2im[0],
&py_det2im[1])) {
return -1;
}
/* Check and set Distortion lookup tables */
for (i = 0; i < 2; ++i) {
if (py_det2im[i] != NULL && py_det2im[i] != Py_None) {
if (!PyObject_TypeCheck(py_det2im[i], &PyDistLookupType)) {
PyErr_SetString(PyExc_TypeError,
"Arg 4 must be a pair of DistortionLookupTable or None objects");
return -1;
}
self->py_det2im[i] = py_det2im[i];
self->x.det2im[i] = &(((PyDistLookup*)py_det2im[i])->x);
}
}
/* Check and set SIP */
if (py_sip != NULL && py_sip != Py_None) {
if (!PyObject_TypeCheck(py_sip, &PySipType)) {
PyErr_SetString(PyExc_TypeError,
"Arg 1 must be Sip object");
return -1;
}
self->py_sip = py_sip;
self->x.sip = &(((PySip*)py_sip)->x);
}
/* Check and set Distortion lookup tables */
for (i = 0; i < 2; ++i) {
if (py_distortion_lookup[i] != NULL && py_distortion_lookup[i] != Py_None) {
if (!PyObject_TypeCheck(py_distortion_lookup[i], &PyDistLookupType)) {
PyErr_SetString(PyExc_TypeError,
"Arg 2 must be a pair of DistortionLookupTable or None objects");
return -1;
}
self->py_distortion_lookup[i] = py_distortion_lookup[i];
self->x.cpdis[i] = &(((PyDistLookup*)py_distortion_lookup[i])->x);
}
}
/* Set and lookup Wcsprm object */
if (py_wcsprm != NULL && py_wcsprm != Py_None) {
if (!PyObject_TypeCheck(py_wcsprm, &PyWcsprmType)) {
PyErr_SetString(PyExc_TypeError,
"Arg 3 must be Wcsprm object");
return -1;
}
self->py_wcsprm = py_wcsprm;
self->x.wcs = &(((PyWcsprm*)py_wcsprm)->x);
}
Py_XINCREF(self->py_sip);
Py_XINCREF(self->py_distortion_lookup[0]);
Py_XINCREF(self->py_distortion_lookup[1]);
Py_XINCREF(self->py_wcsprm);
Py_XINCREF(self->py_det2im[0]);
Py_XINCREF(self->py_det2im[1]);
return 0;
}
示例5: pytalloc_BaseObject_check
_PUBLIC_ int pytalloc_BaseObject_check(PyObject *obj)
{
PyTypeObject *tp = pytalloc_GetBaseObjectType();
return PyObject_TypeCheck(obj, tp);
}
示例6: dialect_init
static int
dialect_init(DialectObj * self, PyObject * args, PyObject * kwargs)
{
PyObject *dialect = NULL, *name_obj, *value_obj;
self->quotechar = '"';
self->delimiter = ',';
self->escapechar = '\0';
self->skipinitialspace = 0;
Py_XDECREF(self->lineterminator);
self->lineterminator = PyString_FromString("\r\n");
if (self->lineterminator == NULL)
return -1;
self->quoting = QUOTE_MINIMAL;
self->doublequote = 1;
self->strict = 0;
if (!PyArg_UnpackTuple(args, "", 0, 1, &dialect))
return -1;
Py_XINCREF(dialect);
if (kwargs != NULL) {
PyObject * key = PyString_FromString("dialect");
PyObject * d;
d = PyDict_GetItem(kwargs, key);
if (d) {
Py_INCREF(d);
Py_XDECREF(dialect);
PyDict_DelItem(kwargs, key);
dialect = d;
}
Py_DECREF(key);
}
if (dialect != NULL) {
int i;
PyObject * dir_list;
/* If dialect is a string, look it up in our registry */
if (PyString_Check(dialect)
#ifdef Py_USING_UNICODE
|| PyUnicode_Check(dialect)
#endif
) {
PyObject * new_dia;
new_dia = get_dialect_from_registry(dialect);
Py_DECREF(dialect);
if (new_dia == NULL)
return -1;
dialect = new_dia;
}
/* A class rather than an instance? Instantiate */
if (PyObject_TypeCheck(dialect, &PyClass_Type)) {
PyObject * new_dia;
new_dia = PyObject_CallFunction(dialect, "");
Py_DECREF(dialect);
if (new_dia == NULL)
return -1;
dialect = new_dia;
}
/* Make sure we finally have an instance */
if (!PyInstance_Check(dialect) ||
(dir_list = PyObject_Dir(dialect)) == NULL) {
PyErr_SetString(PyExc_TypeError,
"dialect must be an instance");
Py_DECREF(dialect);
return -1;
}
/* And extract the attributes */
for (i = 0; i < PyList_GET_SIZE(dir_list); ++i) {
char *s;
name_obj = PyList_GET_ITEM(dir_list, i);
s = PyString_AsString(name_obj);
if (s == NULL)
return -1;
if (s[0] == '_')
continue;
value_obj = PyObject_GetAttr(dialect, name_obj);
if (value_obj) {
if (PyObject_SetAttr((PyObject *)self,
name_obj, value_obj)) {
Py_DECREF(value_obj);
Py_DECREF(dir_list);
Py_DECREF(dialect);
return -1;
}
Py_DECREF(value_obj);
}
}
Py_DECREF(dir_list);
Py_DECREF(dialect);
}
if (kwargs != NULL) {
int pos = 0;
while (PyDict_Next(kwargs, &pos, &name_obj, &value_obj)) {
if (PyObject_SetAttr((PyObject *)self,
name_obj, value_obj))
return -1;
}
}
//.........这里部分代码省略.........
示例7: PyStorageList_Check
//
// checks to see if the python object is a storage list
int PyStorageList_Check(PyObject *value) {
return PyObject_TypeCheck(value, &PyStorageList_Type);
}
示例8: DyND_PyWrapper_Check
int DyND_PyWrapper_Check(PyObject *obj)
{
return PyObject_TypeCheck(obj, DyND_PyWrapper_Type<T>());
}
示例9: pyjiterator_check
/*
* Checks if the object is a pyjiterator.
*/
int pyjiterator_check(PyObject *obj) {
if(PyObject_TypeCheck(obj, &PyJiterator_Type))
return 1;
return 0;
}
示例10: switch
//-------------------------------------------------------------------------------------
PyObject* VectorDescription::onSetValue(PyObject* parentObj, PyObject* value)
{
switch(elemCount_)
{
case 2:
{
if(PyObject_TypeCheck(value, script::ScriptVector2::getScriptType()))
{
return PropertyDescription::onSetValue(parentObj, value);
}
else
{
PyObject* pyobj = PyObject_GetAttrString(parentObj, const_cast<char*>(getName()));
if(pyobj == NULL)
return NULL;
script::ScriptVector2* v = static_cast<script::ScriptVector2*>(pyobj);
v->__py_pySet(v, value);
Py_XDECREF(pyobj);
return v;
}
}
break;
case 3:
{
if(PyObject_TypeCheck(value, script::ScriptVector3::getScriptType()))
{
return PropertyDescription::onSetValue(parentObj, value);
}
else
{
PyObject* pyobj = PyObject_GetAttrString(parentObj, const_cast<char*>(getName()));
if(pyobj == NULL)
return NULL;
script::ScriptVector3* v = static_cast<script::ScriptVector3*>(pyobj);
v->__py_pySet(v, value);
Py_XDECREF(pyobj);
return v;
}
}
break;
case 4:
{
if(PyObject_TypeCheck(value, script::ScriptVector4::getScriptType()))
{
return PropertyDescription::onSetValue(parentObj, value);
}
else
{
PyObject* pyobj = PyObject_GetAttrString(parentObj, const_cast<char*>(getName()));
if(pyobj == NULL)
return NULL;
script::ScriptVector4* v = static_cast<script::ScriptVector4*>(pyobj);
v->__py_pySet(v, value);
Py_XDECREF(pyobj);
return v;
}
}
break;
};
return NULL;
}
示例11: pyg_enum_new
static PyObject *
pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "value", NULL };
long value;
PyObject *pytc, *values, *ret, *intvalue;
GType gtype;
GEnumClass *eclass;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "l", kwlist, &value))
return NULL;
pytc = PyObject_GetAttrString((PyObject *)type, "__gtype__");
if (!pytc)
return NULL;
if (!PyObject_TypeCheck(pytc, &PyGTypeWrapper_Type)) {
Py_DECREF(pytc);
PyErr_SetString(PyExc_TypeError,
"__gtype__ attribute not a typecode");
return NULL;
}
gtype = pyg_type_from_object(pytc);
Py_DECREF(pytc);
eclass = G_ENUM_CLASS(g_type_class_ref(gtype));
/* A check that 0 < value < eclass->n_values was here but got
* removed: enumeration values do not need to be consequitive,
* e.g. GtkPathPriorityType values are not.
*/
values = PyObject_GetAttrString((PyObject *)type, "__enum_values__");
if (!values) {
g_type_class_unref(eclass);
return NULL;
}
/* Note that size of __enum_values__ dictionary can easily be less
* than 'n_values'. This happens if some values of the enum are
* numerically equal, e.g. gtk.ANCHOR_N == gtk.ANCHOR_NORTH.
* Johan said that "In retrospect, using a dictionary to store the
* values might not have been that good", but we need to keep
* backward compatibility.
*/
if (!PyDict_Check(values) || PyDict_Size(values) > eclass->n_values) {
PyErr_SetString(PyExc_TypeError, "__enum_values__ badly formed");
Py_DECREF(values);
g_type_class_unref(eclass);
return NULL;
}
g_type_class_unref(eclass);
intvalue = PYGLIB_PyLong_FromLong(value);
ret = PyDict_GetItem(values, intvalue);
Py_DECREF(intvalue);
Py_DECREF(values);
if (ret)
Py_INCREF(ret);
else
PyErr_Format(PyExc_ValueError, "invalid enum value: %ld", value);
return ret;
}
示例12: PyObject_TypeCheck
bool PythonQtDebugAPI::isPythonQtClassWrapper( PyObject* object )
{
return PyObject_TypeCheck(object, &PythonQtClassWrapper_Type) != 0;
}
示例13: pyjobject_check
int pyjobject_check(PyObject *obj) {
if(PyObject_TypeCheck(obj, &PyJobject_Type))
return 1;
return 0;
}
示例14: PyUnicode_New
PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
{
PyObject *object;
Py_ssize_t i;
Py_ssize_t start;
Py_ssize_t end;
PyObject *res;
unsigned char *outp;
int ressize;
Py_UCS4 c;
if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) {
const unsigned char *p;
if (PyUnicodeDecodeError_GetStart(exc, &start))
return NULL;
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
return NULL;
p = (const unsigned char*)PyBytes_AS_STRING(object);
res = PyUnicode_New(4 * (end - start), 127);
if (res == NULL) {
Py_DECREF(object);
return NULL;
}
outp = PyUnicode_1BYTE_DATA(res);
for (i = start; i < end; i++, outp += 4) {
unsigned char c = p[i];
outp[0] = '\\';
outp[1] = 'x';
outp[2] = Py_hexdigits[(c>>4)&0xf];
outp[3] = Py_hexdigits[c&0xf];
}
assert(_PyUnicode_CheckConsistency(res, 1));
Py_DECREF(object);
return Py_BuildValue("(Nn)", res, end);
}
if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeEncodeError)) {
if (PyUnicodeEncodeError_GetStart(exc, &start))
return NULL;
if (PyUnicodeEncodeError_GetEnd(exc, &end))
return NULL;
if (!(object = PyUnicodeEncodeError_GetObject(exc)))
return NULL;
}
else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeTranslateError)) {
if (PyUnicodeTranslateError_GetStart(exc, &start))
return NULL;
if (PyUnicodeTranslateError_GetEnd(exc, &end))
return NULL;
if (!(object = PyUnicodeTranslateError_GetObject(exc)))
return NULL;
}
else {
wrong_exception_type(exc);
return NULL;
}
if (end - start > PY_SSIZE_T_MAX / (1+1+8))
end = start + PY_SSIZE_T_MAX / (1+1+8);
for (i = start, ressize = 0; i < end; ++i) {
/* object is guaranteed to be "ready" */
c = PyUnicode_READ_CHAR(object, i);
if (c >= 0x10000) {
ressize += 1+1+8;
}
else if (c >= 0x100) {
ressize += 1+1+4;
}
else
ressize += 1+1+2;
}
res = PyUnicode_New(ressize, 127);
if (res == NULL) {
Py_DECREF(object);
return NULL;
}
outp = PyUnicode_1BYTE_DATA(res);
for (i = start; i < end; ++i) {
c = PyUnicode_READ_CHAR(object, i);
*outp++ = '\\';
if (c >= 0x00010000) {
*outp++ = 'U';
*outp++ = Py_hexdigits[(c>>28)&0xf];
*outp++ = Py_hexdigits[(c>>24)&0xf];
*outp++ = Py_hexdigits[(c>>20)&0xf];
*outp++ = Py_hexdigits[(c>>16)&0xf];
*outp++ = Py_hexdigits[(c>>12)&0xf];
*outp++ = Py_hexdigits[(c>>8)&0xf];
}
else if (c >= 0x100) {
示例15: providedBy
static PyObject *
providedBy(PyObject *ignored, PyObject *ob)
{
PyObject *result, *cls, *cp;
result = PyObject_GetAttr(ob, str__providedBy__);
if (result == NULL)
{
PyErr_Clear();
return getObjectSpecification(NULL, ob);
}
/* We want to make sure we have a spec. We can't do a type check
because we may have a proxy, so we'll just try to get the
only attribute.
*/
if (PyObject_TypeCheck(result, &SpecType)
||
PyObject_HasAttr(result, strextends)
)
return result;
/*
The object's class doesn't understand descriptors.
Sigh. We need to get an object descriptor, but we have to be
careful. We want to use the instance's __provides__,l if
there is one, but only if it didn't come from the class.
*/
Py_DECREF(result);
cls = PyObject_GetAttr(ob, str__class__);
if (cls == NULL)
return NULL;
result = PyObject_GetAttr(ob, str__provides__);
if (result == NULL)
{
/* No __provides__, so just fall back to implementedBy */
PyErr_Clear();
result = implementedBy(NULL, cls);
Py_DECREF(cls);
return result;
}
cp = PyObject_GetAttr(cls, str__provides__);
if (cp == NULL)
{
/* The the class has no provides, assume we're done: */
PyErr_Clear();
Py_DECREF(cls);
return result;
}
if (cp == result)
{
/*
Oops, we got the provides from the class. This means
the object doesn't have it's own. We should use implementedBy
*/
Py_DECREF(result);
result = implementedBy(NULL, cls);
}
Py_DECREF(cls);
Py_DECREF(cp);
return result;
}