home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / getpass.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  2.6 KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import sys
  5. __all__ = [
  6.     'getpass',
  7.     'getuser']
  8.  
  9. def unix_getpass(prompt = 'Password: '):
  10.     
  11.     try:
  12.         fd = sys.stdin.fileno()
  13.     except:
  14.         return default_getpass(prompt)
  15.  
  16.     old = termios.tcgetattr(fd)
  17.     new = old[:]
  18.     new[3] = new[3] & ~(termios.ECHO)
  19.     
  20.     try:
  21.         termios.tcsetattr(fd, termios.TCSADRAIN, new)
  22.         passwd = _raw_input(prompt)
  23.     finally:
  24.         termios.tcsetattr(fd, termios.TCSADRAIN, old)
  25.  
  26.     sys.stdout.write('\n')
  27.     return passwd
  28.  
  29.  
  30. def win_getpass(prompt = 'Password: '):
  31.     if sys.stdin is not sys.__stdin__:
  32.         return default_getpass(prompt)
  33.     
  34.     import msvcrt
  35.     for c in prompt:
  36.         msvcrt.putch(c)
  37.     
  38.     pw = ''
  39.     while 1:
  40.         c = msvcrt.getch()
  41.         if c == '\r' or c == '\n':
  42.             break
  43.         
  44.         if c == '\x03':
  45.             raise KeyboardInterrupt
  46.         
  47.         if c == '\x08':
  48.             pw = pw[:-1]
  49.         else:
  50.             pw = pw + c
  51.     msvcrt.putch('\r')
  52.     msvcrt.putch('\n')
  53.     return pw
  54.  
  55.  
  56. def default_getpass(prompt = 'Password: '):
  57.     print 'Warning: Problem with getpass. Passwords may be echoed.'
  58.     return _raw_input(prompt)
  59.  
  60.  
  61. def _raw_input(prompt = ''):
  62.     prompt = str(prompt)
  63.     if prompt:
  64.         sys.stdout.write(prompt)
  65.     
  66.     line = sys.stdin.readline()
  67.     if not line:
  68.         raise EOFError
  69.     
  70.     if line[-1] == '\n':
  71.         line = line[:-1]
  72.     
  73.     return line
  74.  
  75.  
  76. def getuser():
  77.     import os
  78.     for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
  79.         user = os.environ.get(name)
  80.         if user:
  81.             return user
  82.         
  83.     
  84.     import pwd
  85.     return pwd.getpwuid(os.getuid())[0]
  86.  
  87.  
  88. try:
  89.     import termios
  90. except ImportError:
  91.     
  92.     try:
  93.         import msvcrt
  94.     except ImportError:
  95.         
  96.         try:
  97.             from EasyDialogs import AskPassword
  98.         except ImportError:
  99.             getpass = default_getpass
  100.  
  101.         getpass = AskPassword
  102.  
  103.     getpass = win_getpass
  104.  
  105. getpass = unix_getpass
  106.