Commits

pk...@debian.org  committed 303ef96

backends/gnome: add OperationalError with separate messages

  • Participants
  • Parent commits f413301

Comments (0)

Files changed (1)

File keyring/backends/gnome_keyring.c

 #include "Python.h"
 #include "keyring_util.h"
 
+static PyObject* OperationalError;
+
 static PyObject*
 gnome_keyring_password_get(PyObject *self, PyObject *args)
 {
                 "password_get() must be called as (servicename,username)");
         return NULL;
     }
-    if ((! dbus_bus_get(DBUS_BUS_SESSION,NULL)) || 
-            (!gnome_keyring_is_available())){
-        PyErr_Clear();
-        PyErr_SetString(PyExc_OSError, "Can't access the keyring right now");
+    if (!dbus_bus_get(DBUS_BUS_SESSION,NULL)){
+        PyErr_SetString(OperationalError, "Can't access DBUS session bus");
+        return NULL;
+    }
+    if (!gnome_keyring_is_available()){
+        PyErr_SetString(OperationalError, "GNOME Keyring is not available in this session");
         return NULL;
     }
 
 PyMODINIT_FUNC
 initgnome_keyring(void)
 {
+    PyObject* module;
+
     init_application_name();
-    Py_InitModule("gnome_keyring", gnome_keyring_methods);
+    module = Py_InitModule("gnome_keyring", gnome_keyring_methods);
+    if(module == NULL)
+        return;
+
+    OperationalError = PyErr_NewException("gnome_keyring.OperationalError", NULL, NULL);
+    Py_INCREF(OperationalError);
+    PyModule_AddObject(module, "OperationalError", OperationalError);
 }
+