From: Michael Tremer Date: Fri, 29 Dec 2017 14:25:34 +0000 (+0000) Subject: python: Implement comparison of ASes X-Git-Tag: 0.9.0~146 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=63e2ce175069bac5a18cda79c59265fb0515338c python: Implement comparison of ASes Signed-off-by: Michael Tremer --- diff --git a/src/libloc.sym b/src/libloc.sym index 47e8f69..25fe5f5 100644 --- a/src/libloc.sym +++ b/src/libloc.sym @@ -1,6 +1,7 @@ LIBLOC_PRIVATE { global: # AS + loc_as_cmp; loc_as_get_name; loc_as_get_number; loc_as_new; diff --git a/src/python/as.c b/src/python/as.c index 3c74f9e..ca0af47 100644 --- a/src/python/as.c +++ b/src/python/as.c @@ -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, };