本文整理汇总了C++中PyObject_RichCompare函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_RichCompare函数的具体用法?C++ PyObject_RichCompare怎么用?C++ PyObject_RichCompare使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_RichCompare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyObject_Str
static PyObject *t_tzinfo_richcmp(t_tzinfo *self, PyObject *other, int op)
{
if (PyObject_TypeCheck(other, &TZInfoType))
{
PyObject *s1 = PyObject_Str((PyObject *) self->tz);
PyObject *s2 = PyObject_Str((PyObject *) ((t_tzinfo *) other)->tz);
PyObject *result = PyObject_RichCompare(s1, s2, op);
Py_DECREF(s1);
Py_DECREF(s2);
return result;
}
if (PyObject_TypeCheck(other, &FloatingTZType))
{
PyObject *s1 = PyObject_Str((PyObject *) self->tz);
PyObject *result = PyObject_RichCompare(s1, FLOATING_TZNAME, op);
Py_DECREF(s1);
return result;
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
示例2: notify_richcompare
/* note on Notify-tuple comparison.
*
* Such a comparison is required otherwise a check n == (pid, channel)
* would fail. We also want to compare two notifies, and the obvious meaning is
* "check that all the attributes are equal". Unfortunately this leads to an
* inconsistent situation:
* Notify(pid, channel, payload1)
* == (pid, channel)
* == Notify(pid, channel, payload2)
* even when payload1 != payload2. We can probably live with that, but hashing
* makes things worse: hashability is a desirable property for a Notify, and
* to maintain compatibility we should put a notify object in the same bucket
* of a 2-item tuples... but we can't put all the payloads with the same
* (pid, channel) in the same bucket: it would be an extremely poor hash.
* So we maintain compatibility in the sense that notify without payload
* behave as 2-item tuples in term of hashability, but if a payload is present
* the (pid, channel) pair is no more equivalent as dict key to the Notify.
*/
static PyObject *
notify_richcompare(notifyObject *self, PyObject *other, int op)
{
PyObject *rv = NULL;
PyObject *tself = NULL;
PyObject *tother = NULL;
if (Py_TYPE(other) == ¬ifyType) {
if (!(tself = notify_astuple(self, 1))) { goto exit; }
if (!(tother = notify_astuple((notifyObject *)other, 1))) { goto exit; }
rv = PyObject_RichCompare(tself, tother, op);
}
else if (PyTuple_Check(other)) {
if (!(tself = notify_astuple(self, 0))) { goto exit; }
rv = PyObject_RichCompare(tself, other, op);
}
else {
Py_INCREF(Py_False);
rv = Py_False;
}
exit:
Py_XDECREF(tself);
Py_XDECREF(tother);
return rv;
}
示例3: PyObject_RichCompare
static PyObject *t_floatingtz_richcmp(t_floatingtz *self,
PyObject *other, int op)
{
if (PyObject_TypeCheck(other, &FloatingTZType))
{
t_tzinfo *tzi1 = self->tzinfo;
t_tzinfo *tzi2 = ((t_floatingtz *) other)->tzinfo;
return PyObject_RichCompare((PyObject *) (tzi1 ? tzi1 : _default),
(PyObject *) (tzi2 ? tzi2 : _default),
op);
}
if (PyObject_TypeCheck(other, &TZInfoType))
{
PyObject *s2 = PyObject_Str((PyObject *) ((t_tzinfo *) other)->tz);
PyObject *result = PyObject_RichCompare(FLOATING_TZNAME, s2, op);
Py_DECREF(s2);
return result;
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
示例4: pysqlite_row_richcompare
static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
{
if (opid != Py_EQ && opid != Py_NE) {
#if PY_MAJOR_VERSION < 3
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
#else
Py_RETURN_NOTIMPLEMENTED;
#endif
}
if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other;
PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
if ((opid == Py_EQ && res == Py_True)
|| (opid == Py_NE && res == Py_False)) {
Py_DECREF(res);
return PyObject_RichCompare(self->data, other->data, opid);
}
}
#if PY_MAJOR_VERSION < 3
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
#else
Py_RETURN_NOTIMPLEMENTED;
#endif
}
示例5: Match_richcompare
static PyObject * Match_richcompare(
PyObject *self,
PyObject *other,
int op)
{
PyObject* result = NULL;
Match *a = (Match *) self;
Match *b = (Match *) other;
if(PyObject_TypeCheck(other, &Match_Type))
{
switch(op)
{
case Py_EQ:
if (PyObject_RichCompareBool(a->rule, b->rule, Py_EQ) &&
PyObject_RichCompareBool(a->ns, b->ns, Py_EQ))
result = Py_True;
else
result = Py_False;
Py_INCREF(result);
break;
case Py_NE:
if (PyObject_RichCompareBool(a->rule, b->rule, Py_NE) ||
PyObject_RichCompareBool(a->ns, b->ns, Py_NE))
result = Py_True;
else
result = Py_False;
Py_INCREF(result);
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
if (PyObject_RichCompareBool(a->rule, b->rule, Py_EQ))
result = PyObject_RichCompare(a->ns, b->ns, op);
else
result = PyObject_RichCompare(a->rule, b->rule, op);
break;
}
}
else
{
result = PyErr_Format(
PyExc_TypeError,
"'Match' objects must be compared with objects of the same class");
}
return result;
}
示例6: PyObject_RichCompareBool
/* Return -1 if error; 1 if v op w; 0 if not (v op w). */
int
PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
{
PyObject *res;
int ok;
/* Quick result when objects are the same.
Guarantees that identity implies equality. */
if (v == w) {
if (op == Py_EQ)
return 1;
else if (op == Py_NE)
return 0;
}
res = PyObject_RichCompare(v, w, op);
if (res == NULL)
return -1;
if (PyBool_Check(res))
ok = (res == Py_True);
else
ok = PyObject_IsTrue(res);
Py_DECREF(res);
return ok;
}
示例7: Action_RichCompare
/* For backwards compatability we have to check the action code
* against an integer
* The first argument is always an Action object
*/
PyObject* Action_RichCompare(Action* obj1, PyObject* obj2, int method)
{
if (method == Py_EQ)
{
if (Action_Check(obj2))
{
// both are Action objects
Action* a2 = (Action*)obj2;
if (obj1->id == a2->id &&
obj1->buttonCode == a2->buttonCode &&
obj1->fAmount1 == a2->fAmount1 &&
obj1->fAmount2 == a2->fAmount2 &&
obj1->fRepeat == a2->fRepeat &&
obj1->strAction == a2->strAction)
{
Py_RETURN_TRUE;
}
else
{
Py_RETURN_FALSE;
}
}
else
{
// for backwards compatability in python scripts
PyObject* o1 = PyLong_FromLong(obj1->id);
return PyObject_RichCompare(o1, obj2, method);
}
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
示例8: proxy_richcompare
static PyObject *
proxy_richcompare(PyObject *proxy, PyObject *v, int op)
{
UNWRAP(proxy);
UNWRAP(v);
return PyObject_RichCompare(proxy, v, op);
}
示例9: Proxy__ENSURE_WRAPPED_OR_RETURN_NULL
static PyObject *Proxy_richcompare(ProxyObject *self,
PyObject *other, int opcode)
{
Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
return PyObject_RichCompare(self->wrapped, other, opcode);
}
示例10: Bar_richcompare
static PyObject* Bar_richcompare(BarObject *v, PyObject *w, int op) {
if (!Bar_Check(w)) {
switch (op) {
case Py_EQ: Py_RETURN_FALSE;
case Py_NE: Py_RETURN_FALSE;
default:
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
}
// Now we know it is a bar object.
BarObject *x = (BarObject *)w;
if (v->py_bc != x->py_bc) {
// "Inherit" the judgement of our containing objects.
return PyObject_RichCompare((PyObject*)v->py_bc, (PyObject*)x->py_bc, op);
}
// Now we know it is a bar object, and part of the same bar
// collection no less.
switch (op) {
case Py_EQ: if (v->index==x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
case Py_NE: if (v->index!=x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
case Py_LE: if (v->index<=x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
case Py_GE: if (v->index>=x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
case Py_LT: if (v->index< x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
case Py_GT: if (v->index> x->index) Py_RETURN_TRUE; else Py_RETURN_FALSE;
default:
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
}
示例11: pysqlite_row_richcompare
static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
{
if (opid != Py_EQ && opid != Py_NE)
Py_RETURN_NOTIMPLEMENTED;
if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other;
PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
if ((opid == Py_EQ && res == Py_True)
|| (opid == Py_NE && res == Py_False)) {
Py_DECREF(res);
return PyObject_RichCompare(self->data, other->data, opid);
}
}
Py_RETURN_NOTIMPLEMENTED;
}
示例12: slice_richcompare
static PyObject *
slice_richcompare(PyObject *v, PyObject *w, int op)
{
PyObject *t1;
PyObject *t2;
PyObject *res;
if (!PySlice_Check(v) || !PySlice_Check(w))
Py_RETURN_NOTIMPLEMENTED;
if (v == w) {
/* XXX Do we really need this shortcut?
There's a unit test for it, but is that fair? */
switch (op) {
case Py_EQ:
case Py_LE:
case Py_GE:
res = Py_True;
break;
default:
res = Py_False;
break;
}
Py_INCREF(res);
return res;
}
t1 = PyTuple_New(3);
if (t1 == NULL)
return NULL;
t2 = PyTuple_New(3);
if (t2 == NULL) {
Py_DECREF(t1);
return NULL;
}
PyTuple_SET_ITEM(t1, 0, ((PySliceObject *)v)->start);
PyTuple_SET_ITEM(t1, 1, ((PySliceObject *)v)->stop);
PyTuple_SET_ITEM(t1, 2, ((PySliceObject *)v)->step);
PyTuple_SET_ITEM(t2, 0, ((PySliceObject *)w)->start);
PyTuple_SET_ITEM(t2, 1, ((PySliceObject *)w)->stop);
PyTuple_SET_ITEM(t2, 2, ((PySliceObject *)w)->step);
res = PyObject_RichCompare(t1, t2, op);
PyTuple_SET_ITEM(t1, 0, NULL);
PyTuple_SET_ITEM(t1, 1, NULL);
PyTuple_SET_ITEM(t1, 2, NULL);
PyTuple_SET_ITEM(t2, 0, NULL);
PyTuple_SET_ITEM(t2, 1, NULL);
PyTuple_SET_ITEM(t2, 2, NULL);
Py_DECREF(t1);
Py_DECREF(t2);
return res;
}
示例13: namespace_richcompare
static PyObject *
namespace_richcompare(PyObject *self, PyObject *other, int op)
{
if (PyObject_TypeCheck(self, &_PyNamespace_Type) &&
PyObject_TypeCheck(other, &_PyNamespace_Type))
return PyObject_RichCompare(((_PyNamespaceObject *)self)->ns_dict,
((_PyNamespaceObject *)other)->ns_dict, op);
Py_RETURN_NOTIMPLEMENTED;
}
示例14: structseq_richcompare
static PyObject *
structseq_richcompare(PyObject *obj, PyObject *o2, int op)
{
PyObject *tup, *result;
tup = make_tuple((PyStructSequence*) obj);
result = PyObject_RichCompare(tup, o2, op);
Py_DECREF(tup);
return result;
}
示例15: complex_richcompare
static PyObject *
complex_richcompare(PyObject *v, PyObject *w, int op)
{
PyObject *res;
Py_complex i;
int equal;
if (op != Py_EQ && op != Py_NE) {
goto Unimplemented;
}
assert(PyComplex_Check(v));
TO_COMPLEX(v, i);
if (PyLong_Check(w)) {
/* Check for 0.0 imaginary part first to avoid the rich
* comparison when possible.
*/
if (i.imag == 0.0) {
PyObject *j, *sub_res;
j = PyFloat_FromDouble(i.real);
if (j == NULL)
return NULL;
sub_res = PyObject_RichCompare(j, w, op);
Py_DECREF(j);
return sub_res;
}
else {
equal = 0;
}
}
else if (PyFloat_Check(w)) {
equal = (i.real == PyFloat_AsDouble(w) && i.imag == 0.0);
}
else if (PyComplex_Check(w)) {
Py_complex j;
TO_COMPLEX(w, j);
equal = (i.real == j.real && i.imag == j.imag);
}
else {
goto Unimplemented;
}
if (equal == (op == Py_EQ))
res = Py_True;
else
res = Py_False;
Py_INCREF(res);
return res;
Unimplemented:
Py_RETURN_NOTIMPLEMENTED;
}