o w[ef @sdZddlZddlZddlZddlZddlZgdZGdddeZdddZ dd d Z dd d Z dddZ ddZ z ddlZejejfWn"eefyhzddlZWn eybe ZYYdSwe ZYdSwe ZdS)aUtilities to get a password and/or the current user name. getpass(prompt[, stream]) - Prompt for a password, with echo turned off. getuser() - Get the user name from the environment or password database. GetPassWarning - This UserWarning is issued when getpass() cannot prevent echoing of the password contents while reading. On Windows, the msvcrt module will be used. N)getpassgetuserGetPassWarningc@s eZdZdS)rN)__name__ __module__ __qualname__rr/usr/lib/python3.10/getpass.pyrs r Password: c Csd}t}z%tdtjtjB}t|d}||t |}|||s+|}Wn/t y[| zt j }WnttfyPd}t||}Ynwt j }|sYt j}Ynw|durzLt|}|dd}|dtjM<tj} ttdr| tjO} zt|| |t|||d}Wt|| ||n t|| ||wWntjy|dur||ur| t||}Ynw|d|WdS1swYdS)aPrompt for a password, with echo turned off. Args: prompt: Written on stream to ask for the input. Default: 'Password: ' stream: A writable file object to display the prompt. Defaults to the tty. If no tty is available defaults to sys.stderr. Returns: The seKr3t input. Raises: EOFError: If our input tty or stdin was closed. GetPassWarning: When we were unable to turn echo off on the input. Always restores terminal settings before returning. Nz/dev/ttyzw+TCSASOFT)input ) contextlib ExitStackosopenO_RDWRO_NOCTTYioFileIO enter_context TextIOWrapperOSErrorclosesysstdinfilenoAttributeError ValueErrorfallback_getpassstderrtermios tcgetattrECHO TCSAFLUSHhasattrr tcsetattr _raw_inputflusherrorwrite) promptstreampasswdstackfdttyr oldnewtcsetattr_flagsrrr unix_getpasssb             $r5cCstjtjur t||S|D]}t|q d} t}|dks$|dkr%n|dkr+t|dkr6|dd}n||}qtdtd|S) z:Prompt for password with echo off, using Windows getwch(). rN)rr __stdin__r msvcrtputwchgetwchKeyboardInterrupt)r,r-cpwrrr win_getpassas$    rCcCs0tjdtdd|s tj}td|dt||S)Nz%Can not control echo on the terminal.) stacklevelz&Warning: Password input may be echoed.)file)warningswarnrrr!printr()r,r-rrr r xs  r r6cCs|stj}|s tj}t|}|r7z||Wnty2||jd}||j}||Ynw| | }|s?t |ddkrK|dd}|S)Nreplacer;r) rr!rstrr+UnicodeEncodeErrorencodeencodingdecoder)readlineEOFError)r,r-r linerrr r(s(    r(cCs<dD]}tj|}|r|Sqddl}|tdS)zGet 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. )LOGNAMEUSERLNAMEUSERNAMErN)renvirongetpwdgetpwuidgetuid)nameuserrYrrr rs r)r N)r6NN)__doc__rrrrrG__all__ UserWarningrr5rCr r(rr"r#r' ImportErrorrr=rrrrr s2  D