]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Impement setting the name of an AS
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 14:29:50 +0000 (14:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 14:29:50 +0000 (14:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/as.c

index ca0af47ab1e6b6ac79662a26f97b66cc27f3e421..3b2864871f04917442255fa9e9e71ec2126ded5a 100644 (file)
@@ -80,6 +80,21 @@ static PyObject* AS_get_name(ASObject* self) {
        return PyUnicode_FromString(name);
 }
 
        return PyUnicode_FromString(name);
 }
 
+static int AS_set_name(ASObject* self, PyObject* args) {
+       const char* name = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &name))
+               return -1;
+
+       int r = loc_as_set_name(self->as, name);
+       if (r) {
+               PyErr_Format(PyExc_ValueError, "Could not set name: %s", name);
+               return r;
+       }
+
+       return 0;
+}
+
 static PyObject* AS_richcompare(ASObject* self, ASObject* other, int op) {
        int r = loc_as_cmp(self->as, other->as);
 
 static PyObject* AS_richcompare(ASObject* self, ASObject* other, int op) {
        int r = loc_as_cmp(self->as, other->as);
 
@@ -107,7 +122,7 @@ static struct PyGetSetDef AS_getsetters[] = {
        {
                "name",
                (getter)AS_get_name,
        {
                "name",
                (getter)AS_get_name,
-               NULL,
+               (setter)AS_set_name,
                NULL,
                NULL,
        },
                NULL,
                NULL,
        },