]> git.ipfire.org Git - location/libloc.git/commitdiff
python: Implement comparison of ASes
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 14:25:34 +0000 (14:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 14:25:34 +0000 (14:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libloc.sym
src/python/as.c

index 47e8f69d99cdf905283b936cdccae3b95c57740d..25fe5f5836c0c21fee2a7beb53ea876a815ea4e5 100644 (file)
@@ -1,6 +1,7 @@
 LIBLOC_PRIVATE {
 global:
        # AS
+       loc_as_cmp;
        loc_as_get_name;
        loc_as_get_number;
        loc_as_new;
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,
 };