diff --git a/python-types.c b/python-types.c index 28fb9f5..5685390 100644 --- a/python-types.c +++ b/python-types.c @@ -969,6 +969,38 @@ tgl_Peer_repr(tgl_Peer *self) return ret; } +PyObject * +tgl_Peer_RichCompare(PyObject *self, PyObject *other, int cmp) +{ + PyObject *result = NULL; + + if(!PyObject_TypeCheck(other, &tgl_PeerType)) { + result = Py_False; + } else { + if(((tgl_Peer*)self)->peer == NULL || + ((tgl_Peer*)other)->peer == NULL) { + result = Py_False; // If either object is not properly instantiated, compare is false + } else { + switch (cmp) { + case Py_EQ: + result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_True : Py_False; + break; + case Py_NE: + result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_False : Py_True; + break; + case Py_LE: + case Py_GE: + case Py_GT: + case Py_LT: + default: + Py_RETURN_NOTIMPLEMENTED; + } + } + } + Py_XINCREF(result); + return result; +} + PyTypeObject tgl_PeerType = { PyVarObject_HEAD_INIT(NULL, 0) @@ -994,7 +1026,7 @@ PyTypeObject tgl_PeerType = { "tgl Peer", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ - 0, /* tp_richcompare */ + (richcmpfunc)tgl_Peer_RichCompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */