]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/database.c
python: Fix errors for Database.lookup()
[people/ms/libloc.git] / src / python / database.c
index de450448e7f752b2855732663b6ddfb81c7bd06c..250750d5cf55c755cc41d69d0d6b027bf36cdd8b 100644 (file)
@@ -199,18 +199,21 @@ static PyObject* Database_lookup(DatabaseObject* self, PyObject* args) {
                loc_network_unref(network);
 
                return obj;
+       }
 
        // Nothing found
-       } else if (r == 1) {
+       if (!errno)
                Py_RETURN_NONE;
 
-       // Invalid input
-       } else if (r == -EINVAL) {
-               PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address);
-               return NULL;
+       // Handle any errors
+       switch (errno) {
+               case EINVAL:
+                       PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address);
+
+               default:
+                       PyErr_SetFromErrno(PyExc_OSError);
        }
 
-       // Unexpected error
        return NULL;
 }