]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/network.c
python: Add script to lookup database from command line
[people/ms/libloc.git] / src / python / network.c
index f36b3393ff177747b77c762337cab04dea2f1b9d..9ee50671b98bc674a9255ee81e0c77467910f3df 100644 (file)
@@ -71,6 +71,15 @@ static PyObject* Network_repr(NetworkObject* self) {
        return obj;
 }
 
+static PyObject* Network_str(NetworkObject* self) {
+       char* network = loc_network_str(self->network);
+
+       PyObject* obj = PyUnicode_FromString(network);
+       free(network);
+
+       return obj;
+}
+
 static PyObject* Network_get_country_code(NetworkObject* self) {
        const char* country_code = loc_network_get_country_code(self->network);
 
@@ -83,7 +92,8 @@ static int Network_set_country_code(NetworkObject* self, PyObject* value) {
        int r = loc_network_set_country_code(self->network, country_code);
        if (r) {
                if (r == -EINVAL)
-                       PyErr_SetString(PyExc_ValueError, "Invalid country code");
+                       PyErr_Format(PyExc_ValueError,
+                               "Invalid country code: %s", country_code);
 
                return -1;
        }
@@ -145,4 +155,5 @@ PyTypeObject NetworkType = {
        tp_doc:                 "Network object",
        tp_getset:              Network_getsetters,
        tp_repr:                (reprfunc)Network_repr,
+       tp_str:                 (reprfunc)Network_str,
 };