Commits

Marcin Kasperski  committed 4395bd1

#33 decode/recode passwords between local and unicode

  • Participants
  • Parent commits 64dc415

Comments (0)

Files changed (1)

File mercurial_keyring.py

     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)
+        password = keyring.get_password(KEYRING_SERVICE, pwdkey)
+        # Reverse recoding from next routine
+        if isinstance(password, unicode):
+            return encoding.tolocal(password.encode('utf-8'))
+        return password
     def _save_password_to_keyring(self, pwdkey, password):
+        # keyring in general expects unicode. Mercurial provides "local" encoding. See #33
+        password = encoding.fromlocal(password).decode('utf-8')
         keyring.set_password(KEYRING_SERVICE,
                              pwdkey, 
                              password)