Commits

Jason R. Coombs  committed 60422ae Merge

Merged in msitarz/python-keyring-lib (pull request #22)

Handling user cancel in KWallet

  • Participants
  • Parent commits 8aeb01e, 006d6cd

Comments (0)

Files changed (4)

File keyring/backends/Gnome.py

                 password, True)
         except gnomekeyring.CancelledError:
             # The user pressed "Cancel" when prompted to unlock their keyring.
-            raise PasswordSetError("cancelled by user")
+            raise PasswordSetError("Cancelled by user")
 
     def delete_password(self, service, username):
         """Delete the password for the username of the service.
         except gnomekeyring.NoMatchError:
             raise PasswordDeleteError("Password not found")
         except gnomekeyring.CancelledError:
-            raise PasswordDeleteError("cancelled by user")
+            raise PasswordDeleteError("Cancelled by user")
 
     def _safe_string(self, source, encoding='utf-8'):
         """Convert unicode to string as gnomekeyring barfs on unicode"""

File keyring/backends/Google.py

     def _del_entry(self, keyring_dict, service, username):
         service_entries = keyring_dict.get(service)
         if not service_entries:
-            raise errors.PasswordDeleteError("no matching service")
+            raise errors.PasswordDeleteError("No matching service")
         try:
             del service_entries[username]
         except KeyError:
-            raise errors.PasswordDeleteError("not found")
+            raise errors.PasswordDeleteError("Not found")
         if not service_entries:
             del keyring_dict[service]
 

File keyring/backends/kwallet.py

 
 from keyring.backend import KeyringBackend
 from keyring.errors import PasswordDeleteError
+from keyring.errors import PasswordSetError
 
 try:
     from PyKDE4.kdeui import KWallet
         key = username + '@' + service
         network = KWallet.Wallet.NetworkWallet()
         wallet = open_kwallet()
+        if wallet is None:
+            # the user pressed "cancel" when prompted to unlock their keyring.
+            return None
         if wallet.keyDoesNotExist(network, 'Python', key):
             return None
 
         """Set password for the username of the service
         """
         wallet = open_kwallet()
+        if wallet is None:
+            # the user pressed "cancel" when prompted to unlock their keyring.
+            raise PasswordSetError("Cancelled by user")
         wallet.writePassword(username+'@'+service, password)
 
     def delete_password(self, service, username):
         """
         key = username + '@' + service
         wallet = open_kwallet()
+        if wallet is None:
+            # the user pressed "cancel" when prompted to unlock their keyring.
+            raise PasswordDeleteError("Cancelled by user")
         if wallet.keyDoesNotExist(wallet.walletName(), 'Python', key):
             raise PasswordDeleteError("Password not found")
         wallet.removeEntry(key)

File keyring/backends/pyfs.py

         try:
             self.config.remove_option(service, username)
         except configparser.NoSectionError:
-            raise errors.PasswordDeleteError('not found')
+            raise errors.PasswordDeleteError('Password not found')
         config_file = self._open('w')
         self.config.write(config_file)
         config_file.close()