Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/getpass.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZddlZddlZddlZdddgZdefd��YZddd�Zddd	�Z	ddd
�Z
dddd�Zd
�Zddd�Z
y ddlZejejfWn�eefk
rejdkryddlZWnek
re
Zq|Xe
Zq�yddlZWnEek
ruyddlmZWnek
rke
Zq|XeZq�Xe	ZnXeZdS(s�Utilities 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.
On the Mac EasyDialogs.AskPassword is used, if available.

i�NtgetpasstgetusertGetPassWarningcBseZRS((t__name__t
__module__(((s/sys/lib/python2.7/getpass.pyRss
Password: c
Cs�d}d}yJtjdtjtjB�}tj|dd�}|}|sU|}nWnjtk
r�}ytjj	�}Wn&t
tfk
r�t||�}nXtj}|s�tj
}q�nX|dk	r�d}y�tj|�}|}|dctjM<tj}	ttd�r*|	tjO}	nz,tj||	|�t||d|�}Wdtj||	|�|j�XWq�tjk
r�}|dk	r��n~~t||�}q�Xn|jd�|S(	sPrompt 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.
    s/dev/ttysw+iitTCSASOFTtinputNs
(tNonetostopentO_RDWRtO_NOCTTYtfdopentEnvironmentErrortsyststdintfilenotAttributeErrort
ValueErrortfallback_getpasststderrttermiost	tcgetattrtECHOt	TCSAFLUSHthasattrRt	tcsetattrt
_raw_inputtflushterrortwrite(
tprompttstreamtfdtttyRtetpasswdtoldtnewttcsetattr_flags((s/sys/lib/python2.7/getpass.pytunix_getpasssJ
		
cCs�tjtjk	rt||�Sddl}x|D]}|j|�q2Wd}xc|j�}|dksv|dkrzPn|dkr�t�n|dkr�|d }qR||}qR|jd�|jd�|S(s9Prompt for password with echo off, using Windows getch().i�Nts
s
ss(RRt	__stdin__RtmsvcrttputchtgetchtKeyboardInterrupt(RR R+tctpw((s/sys/lib/python2.7/getpass.pytwin_getpassYs$

	



cCs?tjdtdd�|s(tj}n|dIJt||�S(Ns%Can not control echo on the terminal.t
stacklevelis&Warning: Password input may be echoed.(twarningstwarnRRRR(RR ((s/sys/lib/python2.7/getpass.pyRps
R)cCs�|stj}n|s$tj}nt|�}|rP|j|�|j�n|j�}|skt�n|ddkr�|d }n|S(Ni�s
(RRRtstrRRtreadlinetEOFError(RR Rtline((s/sys/lib/python2.7/getpass.pyRys

	
cCs\ddl}x*dD]"}|jj|�}|r|SqWddl}|j|j��dS(	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.

    i�NtLOGNAMEtUSERtLNAMEtUSERNAMEi(R9R:R;R<(Rtenvirontgettpwdtgetpwuidtgetuid(RtnametuserR?((s/sys/lib/python2.7/getpass.pyR�s
c	Cs7d	}tjdtj�}tjdtj�}tj|d�}d	}y.tjdtj�}tj|dd�}Wntk
r�d	}nX|d	kr�t|�r�tj||d�}n|j	�}|ddkr�d }ntj|dd�}|j
�|r3tj|dd�}tj
|�n|S(
sPrompt 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
              /dev/cons.
    Returns:
      The seKr3t input.
    Raises:
      EOFError: If our input cons or stdin was closed.
      GetPassWarning: When we were unable to turn echo off on the input.
      OSError: If input or output cons are closed or consctl fails.

    Always restores terminal settings before returning.
    s	/dev/constrs/dev/consctltrawonii�s
trawoffN(Rtplan9R	tOREADtOWRITERtpwritetOSErrortlenR6tclose(	RR R$tfdintfdouttconstctltnntn((s/sys/lib/python2.7/getpass.pyt
plan9_getpass�s*



RG(tAskPassword(t__doc__RRR3t__all__tUserWarningRRR(R1RRRRTRRRtImportErrorRtplatformRGRR+tEasyDialogsRU(((s/sys/lib/python2.7/getpass.pyt<module>s:$?		)

	






Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].