Commit 24ca7992 authored by Michael Tremer's avatar Michael Tremer

python: Expose flags

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 4ef1761f
......@@ -115,5 +115,15 @@ PyMODINIT_FUNC PyInit_location(void) {
// Version
PyDict_SetItemString(d, "__version__", PyUnicode_FromString(VERSION));
// Add flags
if (PyModule_AddIntConstant(m, "FLAG_ANONYMOUS_PROXY", LOC_NETWORK_FLAG_ANONYMOUS_PROXY))
return NULL;
if (PyModule_AddIntConstant(m, "FLAG_SATELLITE_PROVIDER", LOC_NETWORK_FLAG_SATELLITE_PROVIDER))
return NULL;
if (PyModule_AddIntConstant(m, "FLAG_ANYCAST", LOC_NETWORK_FLAG_ANYCAST))
return NULL;
return m;
}
......@@ -126,6 +126,50 @@ static int Network_set_asn(NetworkObject* self, PyObject* value) {
return 0;
}
static PyObject* Network_has_flag(NetworkObject* self, PyObject* args) {
enum loc_network_flags flag = 0;
if (!PyArg_ParseTuple(args, "i", &flag))
return NULL;
if (loc_network_has_flag(self->network, flag))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject* Network_set_flag(NetworkObject* self, PyObject* args) {
enum loc_network_flags flag = 0;
if (!PyArg_ParseTuple(args, "i", &flag))
return NULL;
int r = loc_network_set_flag(self->network, flag);
if (r) {
// What exception to throw here?
return NULL;
}
Py_RETURN_NONE;
}
static struct PyMethodDef Network_methods[] = {
{
"has_flag",
(PyCFunction)Network_has_flag,
METH_VARARGS,
NULL,
},
{
"set_flag",
(PyCFunction)Network_set_flag,
METH_VARARGS,
NULL,
},
{ NULL },
};
static struct PyGetSetDef Network_getsetters[] = {
{
"asn",
......@@ -153,6 +197,7 @@ PyTypeObject NetworkType = {
.tp_dealloc = (destructor)Network_dealloc,
.tp_init = (initproc)Network_init,
.tp_doc = "Network object",
.tp_methods = Network_methods,
.tp_getset = Network_getsetters,
.tp_repr = (reprfunc)Network_repr,
.tp_str = (reprfunc)Network_str,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment