mň
­fIc           @   só   d  Z  d k Z d d g Z d d  Z d d  Z d d  Z d d	  Z d
   Z y d k Z e i	 e i
 f Wnu e e f j
 oc y d k Z WnF e j
 o: y d k l Z Wn e j
 o e Z qä Xe Z qď Xe Z n Xe Z d S(   s)  Utilities to get a password and/or the current user name.

getpass(prompt) - prompt for a password, with echo turned off
getuser() - get the user name from the environment or password database

On Windows, the msvcrt module will be used.
On the Mac EasyDialogs.AskPassword is used, if available.

Nt   getpasst   getusers
   Password: c         C   s§   y t  i i   } Wn t |   Sn Xt i |  } | } | d t i
 @| d <z& t i | t i |  t |   } Wd t i | t i |  Xt  i i d  | S(   sX   Prompt for a password, with echo turned off.

    Restore terminal settings at end.
    i   Ns   
(   t   syst   stdint   filenot   fdt   default_getpasst   promptt   termiost	   tcgetattrt   oldt   newt   ECHOt	   tcsetattrt	   TCSADRAINt
   _raw_inputt   passwdt   stdoutt   write(   R   R
   R   R   R   (    (    t$   /mit/python/lib/python2.4/getpass.pyt   unix_getpass   s      c         C   sŰ   t  i t  i j	 o t |   Sn d k } x |  D] } | i |  q1 Wd } xl | i	   } | d j p | d j o Pn | d j o
 t
  n | d j o | d  } qQ | | } qQ W| i d  | i d  | S(	   s9   Prompt for password with echo off, using Windows getch().Nt    i   s   s   
s   s   i˙˙˙˙(   R   R   t	   __stdin__R   R   t   msvcrtt   ct   putcht   pwt   getcht   KeyboardInterrupt(   R   R   R   R   (    (    R   t   win_getpass+   s*     	   
c         C   s   d GHt  |   S(   Ns7   Warning: Problem with getpass. Passwords may be echoed.(   R   R   (   R   (    (    R   R   B   s    R   c         C   sj   t  |   }  |  o t i i |   n t i i   } | p
 t  n | d d j o | d  } n | S(   Ni˙˙˙˙s   
(	   t   strR   R   R   R   R   t   readlinet   linet   EOFError(   R   R    (    (    R   R   G   s    
c          C   s[   d k  } x/ d D]' } | i i |  } | o | Sq q Wd k }  |  i | i    d S(   sÂ   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.

    Nt   LOGNAMEt   USERt   LNAMEt   USERNAMEi    (   R"   R#   R$   R%   (   t   ost   namet   environt   gett   usert   pwdt   getpwuidt   getuid(   R+   R&   R'   R*   (    (    R   R   U   s     	 	(   s   AskPassword(   t   __doc__R   t   __all__R   R   R   R   R   R   R	   R   t   ImportErrort   AttributeErrorR   t   EasyDialogst   AskPasswordR    (   R   R    R/   R   R   R   R   R   R   R   R3   (    (    R   t   ?	   s*   			