]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/as.c
python: Implement comparison of ASes
[people/ms/libloc.git] / src / python / as.c
index 3c74f9e90515cb1a1df28e723657e58c433e4ec4..ca0af47ab1e6b6ac79662a26f97b66cc27f3e421 100644 (file)
@@ -80,6 +80,29 @@ static PyObject* AS_get_name(ASObject* self) {
        return PyUnicode_FromString(name);
 }
 
+static PyObject* AS_richcompare(ASObject* self, ASObject* other, int op) {
+       int r = loc_as_cmp(self->as, other->as);
+
+       switch (op) {
+               case Py_EQ:
+                       if (r == 0)
+                               Py_RETURN_TRUE;
+
+                       Py_RETURN_FALSE;
+
+               case Py_LT:
+                       if (r < 0)
+                               Py_RETURN_TRUE;
+
+                       Py_RETURN_FALSE;
+
+               default:
+                       break;
+       }
+
+       Py_RETURN_NOTIMPLEMENTED;
+}
+
 static struct PyGetSetDef AS_getsetters[] = {
        {
                "name",
@@ -109,4 +132,5 @@ PyTypeObject ASType = {
        tp_doc:                 "AS object",
        tp_getset:              AS_getsetters,
        tp_repr:                (reprfunc)AS_repr,
+       tp_richcompare:         (richcmpfunc)AS_richcompare,
 };