]> git.ipfire.org Git - location/libloc.git/blobdiff - src/python/database.c
importer: Drop EDROP as it has been merged into DROP
[location/libloc.git] / src / python / database.c
index 250750d5cf55c755cc41d69d0d6b027bf36cdd8b..d6ee4d02d0ed1d35fcf1ccc4244d25763e222cd3 100644 (file)
@@ -166,17 +166,32 @@ static PyObject* Database_get_as(DatabaseObject* self, PyObject* args) {
 }
 
 static PyObject* Database_get_country(DatabaseObject* self, PyObject* args) {
+       struct loc_country* country = NULL;
        const char* country_code = NULL;
 
        if (!PyArg_ParseTuple(args, "s", &country_code))
                return NULL;
 
-       struct loc_country* country;
+       // Fetch the country
        int r = loc_database_get_country(self->db, &country, country_code);
        if (r) {
-               Py_RETURN_NONE;
+               switch (errno) {
+                       case EINVAL:
+                               PyErr_SetString(PyExc_ValueError, "Invalid country code");
+                               break;
+
+                       default:
+                               PyErr_SetFromErrno(PyExc_OSError);
+                               break;
+               }
+
+               return NULL;
        }
 
+       // No result
+       if (!country)
+               Py_RETURN_NONE;
+
        PyObject* obj = new_country(&CountryType, country);
        loc_country_unref(country);