Commits

Marcin Kasperski committed 64dc415

Refactoring (factoring out actual keyring read/write in preparation for #33)

  • Participants
  • Parent commits db9e7c9

Comments (0)

Files changed (1)

File mercurial_keyring.py

 except:
     from mercurial.httprepo import passwordmgr
 from mercurial import mail
+from mercurial import encoding
 from urllib2 import AbstractBasicAuthHandler, AbstractDigestAuthHandler
 
 # mercurial.demandimport incompatibility workaround.
     def __init__(self):
         self.cache = dict()
     def get_http_password(self, url, username):
-        return keyring.get_password(KEYRING_SERVICE,
-                                    self._format_http_key(url, username))
+        return self._read_password_from_keyring(
+            self._format_http_key(url, username))
     def set_http_password(self, url, username, password):
-        keyring.set_password(KEYRING_SERVICE,
-                             self._format_http_key(url, username),
-                             password)
+        self._save_password_to_keyring(
+            self._format_http_key(url, username),
+            password)
     def clear_http_password(self, url, username):
         self.set_http_password(url, username, "")
     def _format_http_key(self, url, username):
         return "%s@@%s" % (username, url)
     def get_smtp_password(self, machine, port, username):
-        return keyring.get_password(
-            KEYRING_SERVICE,
+        return self._read_password_from_keyring(
             self._format_smtp_key(machine, port, username))
     def set_smtp_password(self, machine, port, username, password):
-        keyring.set_password(
-            KEYRING_SERVICE,
+        self._save_password_to_keyring(
             self._format_smtp_key(machine, port, username),
             password)
     def clear_smtp_password(self, machine, port, username):
         self.set_smtp_password(machine, port, username, "")
     def _format_smtp_key(self, machine, port, username):
         return "%s@@%s:%s" % (username, machine, str(port))
+    def _read_password_from_keyring(self, pwdkey):
+        return keyring.get_password(KEYRING_SERVICE, pwdkey)
+    def _save_password_to_keyring(self, pwdkey, password):
+        keyring.set_password(KEYRING_SERVICE,
+                             pwdkey, 
+                             password)
 
 password_store = PasswordStore()