tarek  committed ccefe7e

added experimental support for getpass module

  • Participants
  • Parent commits 4a551ed
  • Branches default

Comments (0)

Files changed (3)

File keyring/

 logger = logging.getLogger('keyring')
 from core import set_keyring, get_keyring, set_password, get_password
+from keyring.getpassbackend import get_password

File keyring/

 import os
 import sys
-import getpass
 import ConfigParser
         password = None
         while 1:
             if not password:
+                import getpass
                 password = getpass.getpass()
                 password2 = getpass.getpass('Password (again): ')
                 if password != password2:
         print "Please input your password for the keyring"
+        import getpass
         password = getpass.getpass()
         if not self._auth(password):

File keyring/

+"""Specific support for getpass."""
+import os
+import pwd
+from keyring.core import get_password as original_get_password
+def get_default_user():
+    """Get the username from the environment or password database.
+    First try various environment variables, then the password
+    database.  This works on Windows as long as USERNAME is set.
+    """
+    for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
+        user = os.environ.get(name)
+        if user:
+            return user
+    return pwd.getpwuid(os.getuid())[0]
+def get_password(prompt='Password: ', stream=None,
+                           service_name='Python',
+                           username=get_default_user()):
+    return original_get_password(service_name, username)