src/eric7/DebugClients/Python/getpass.py

branch
eric7
changeset 9482
a2bc06a54d9d
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
--- a/src/eric7/DebugClients/Python/getpass.py	Sun Nov 06 11:22:39 2022 +0100
+++ b/src/eric7/DebugClients/Python/getpass.py	Mon Nov 07 17:19:58 2022 +0100
@@ -13,6 +13,13 @@
 is to provide a debugger compatible variant of the a.m. functions.
 """
 
+import os
+
+try:
+    import pwd
+except ImportError:
+    pwd = None
+
 __all__ = ["getpass", "getuser"]
 
 
@@ -28,17 +35,16 @@
     """
     # this is copied from the original getpass.py
 
-    import os
-
     for name in ("LOGNAME", "USER", "LNAME", "USERNAME"):
         user = os.environ.get(name)
         if user:
             return user
 
     # If this fails, the exception will "explain" why
-    import pwd
+    if pwd:
+        return pwd.getpwuid(os.getuid())[0]
 
-    return pwd.getpwuid(os.getuid())[0]
+    return "<unknown"
 
 
 def getpass(prompt="Password: ", stream=None):

eric ide

mercurial