
    Rhf                         d Z ddlZddlZddlZddlZddlZg dZ G d de      ZddZ	ddZ
ddZdd	Zd
 Z	 ddlZej                  ej                   f e	Zy# eef$ r 	 ddlZe
ZY y# e$ r eZY Y yw xY ww xY w)a  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.

    N)getpassgetuserGetPassWarningc                       e Zd Zy)r   N)__name__
__module____qualname__     /usr/lib/python3.12/getpass.pyr   r      s    r   r   c                    d}t        j                         5 }	 t        j                  dt        j                  t        j
                  z        }t        j                  |d      }|j                  |       t        j                  |      }|j                  |       |s|}|	 t'        j(                  |      }|dd }|dxx   t&        j*                   z  cc<   t&        j,                  }	t/        t&        d      r|	t&        j0                  z  }		 t'        j2                  ||	|       t5        | ||      }t'        j2                  ||	|       |j7                          	 |j;                  d       |cddd       S # t        $ ry |j                          	 t        j                  j                         }n## t        t         f$ r d}t#        | |      }Y nw xY wt        j                  }|st        j$                  }Y Ww xY w# t'        j2                  ||	|       |j7                          w xY w# t&        j8                  $ r' | ||ur|j                          t#        | |      }Y w xY w# 1 sw Y   yxY w)a  Prompt 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/ttyzw+   TCSASOFT)input
)
contextlib	ExitStackosopenO_RDWRO_NOCTTYioFileIOenter_contextTextIOWrapperOSErrorclosesysstdinfilenoAttributeError
ValueErrorfallback_getpassstderrtermios	tcgetattrECHO	TCSAFLUSHhasattrr   	tcsetattr
_raw_inputflusherrorwrite)
promptstreampasswdstackfdttyr   oldnewtcsetattr_flagss
             r   unix_getpassr8      s    F				 15	$RYYr{{%:;B))B%C$$$S)E& >:''+!fA7<<-'")"3"37J/#w'7'77O#%%b/3?'eDF%%b/3?LLN 	Tc1 1  
	$KKM:YY%%'"J/ :)&&9: IIE
	$0 %%b/3?LLN== 
:%  &KKM)&&9
:I1 1s   I#BE5I#"A)H&%G:1'H&I#5G7F.-G7.GG7G%G73I#6G77I#:)H##H&&6I I#I  I##I,c                 f   t         j                  t         j                  urt        | |      S | D ]  }t	        j
                  |        d}	 t	        j                         }|dk(  s|dk(  rn|dk(  rt        |dk(  r|dd }n||z   };t	        j
                  d       t	        j
                  d       |S )z:Prompt for password with echo off, using Windows getwch(). r   N)r   r   	__stdin__r#   msvcrtputwchgetwchKeyboardInterrupt)r/   r0   cpws       r   win_getpassrF   a   s    
yy%// a	B
MMO9T	;##9CRBaB  MM$
MM$Ir   c                     t        j                  dt        d       |st        j                  }t        d|       t        | |      S )Nz%Can not control echo on the terminal.   )
stacklevelz&Warning: Password input may be echoed.)file)warningswarnr   r   r$   printr+   )r/   r0   s     r   r#   r#   x   s:    MM9> 	
2@ff%%r   c                    |st         j                  }|st         j                  }t        |       } | r"	 |j	                  |        |j                          |j                         }|st        |d   dk(  r|d d }|S # t
        $ rK | j                  |j                  d      } | j                  |j                        } |j	                  |        Y w xY w)Nreplacer>   r   )r   r$   r   strr.   UnicodeEncodeErrorencodeencodingdecoder,   readlineEOFError)r/   r0   r   lines       r   r+   r+      s    		[F	!LL  	>>DBx4CRyK " 	!]]6??I>F]]6??3FLL 		!s   A; ;ACCc                      dD ]'  } t         j                  j                  |       }|s%|c S  ddl}|j	                  t        j
                               d   S )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.

    )LOGNAMEUSERLNAMEUSERNAMEr   N)r   environgetpwdgetpwuidgetuid)nameuserr_   s      r   r   r      sL     9 zz~~d#K <<		$Q''r   )z
Password: N)r:   NN)__doc__r   r   r   r   rK   __all__UserWarningr   r8   rF   r#   r+   r   r%   r&   r*   r   ImportErrorr!   r@   r
   r   r   <module>rh      s   
   	 	 
 
0 ([ 'AH.&2($ w((( G 	^$    #"#s/   A A8!A)%A8)A40A83A44A8