sutupud avatar sutupud committed 2b13127

Fixed: freezing when calling open_kwallet twice without a QApplication

Comments (0)

Files changed (2)

keyring/backend.py

             # The user pressed "Cancel" when prompted to unlock their keyring.
             raise PasswordSetError()
 
+kwallet = None
+
 def open_kwallet(kwallet_module=None, qt_module=None):
+
+    global kwallet
+    if not kwallet is None:
+        return kwallet
+
     # Allow for the injection of module-like objects for testing purposes.
     if kwallet_module is None:
         kwallet_module = KWallet.Wallet
             app.exit()
 
 
-kwallet = None
 try:
     from PyKDE4.kdeui import KWallet
     from PyQt4 import QtGui
 except ImportError:
-    kwallet = False
+    kwallet_support = False
 else:
-    kwallet = True
+    kwallet_support = True
 
 
 class KDEKWallet(KeyringBackend):
     """KDE KWallet"""
 
-    wallet = None
-
-    def get_wallet(self):
-        if self.wallet != None:
-            return self.wallet
-        else:
-            self.wallet = open_kwallet();
-            return self.wallet
-
     def supported(self):
-        if kwallet and os.environ.has_key('KDE_SESSION_UID'):
+        if kwallet_support and os.environ.has_key('KDE_SESSION_UID'):
             return 1
-        elif kwallet:
+        elif kwallet_support:
             return 0
         else:
             return -1
         """
         key = username + '@' + service
         network = KWallet.Wallet.NetworkWallet()
-        wallet = self.get_wallet()
+        wallet = open_kwallet()
         if wallet.keyDoesNotExist(network, 'Python', key):
             return None
 
     def set_password(self, service, username, password):
         """Set password for the username of the service
         """
-        wallet=self.get_wallet()
+        wallet=open_kwallet()
         wallet.writePassword(username+'@'+service, password)
 
 class BasicFileKeyring(KeyringBackend):

keyring/tests/test_backend.py

     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(OSXKeychainTestCase))
     suite.addTest(unittest.makeSuite(GnomeKeyringTestCase))
+    suite.addTest(unittest.makeSuite(KDEWalletCanceledTestCase))
     suite.addTest(unittest.makeSuite(KDEKWalletTestCase))
     suite.addTest(unittest.makeSuite(KDEKWalletInQApplication))
-    suite.addTest(unittest.makeSuite(KDEWalletCanceledTestCase))
     suite.addTest(unittest.makeSuite(UncryptedFileKeyringTestCase))
     suite.addTest(unittest.makeSuite(CryptedFileKeyringTestCase))
     suite.addTest(unittest.makeSuite(Win32CryptoKeyringTestCase))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.