/Doc/library/getpass.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 51 lines · 35 code · 16 blank · 0 comment · 0 complexity · cf39c67a30fc3cf0565ca244240f2c9e MD5 · raw file

  1. :mod:`getpass` --- Portable password input
  2. ==========================================
  3. .. module:: getpass
  4. :synopsis: Portable reading of passwords and retrieval of the userid.
  5. .. moduleauthor:: Piers Lauder <piers@cs.su.oz.au>
  6. .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
  7. .. Windows (& Mac?) support by Guido van Rossum.
  8. The :mod:`getpass` module provides two functions:
  9. .. function:: getpass([prompt[, stream]])
  10. Prompt the user for a password without echoing. The user is prompted using the
  11. string *prompt*, which defaults to ``'Password: '``. On Unix, the prompt is
  12. written to the file-like object *stream*. *stream* defaults to the
  13. controlling terminal (/dev/tty) or if that is unavailable to ``sys.stderr``
  14. (this argument is ignored on Windows).
  15. If echo free input is unavailable getpass() falls back to printing
  16. a warning message to *stream* and reading from ``sys.stdin`` and
  17. issuing a :exc:`GetPassWarning`.
  18. Availability: Macintosh, Unix, Windows.
  19. .. versionchanged:: 2.5
  20. The *stream* parameter was added.
  21. .. versionchanged:: 2.6
  22. On Unix it defaults to using /dev/tty before falling back
  23. to ``sys.stdin`` and ``sys.stderr``.
  24. .. note::
  25. If you call getpass from within IDLE, the input may be done in the
  26. terminal you launched IDLE from rather than the idle window itself.
  27. .. exception:: GetPassWarning
  28. A :exc:`UserWarning` subclass issued when password input may be echoed.
  29. .. function:: getuser()
  30. Return the "login name" of the user. Availability: Unix, Windows.
  31. This function checks the environment variables :envvar:`LOGNAME`,
  32. :envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and returns
  33. the value of the first one which is set to a non-empty string. If none are set,
  34. the login name from the password database is returned on systems which support
  35. the :mod:`pwd` module, otherwise, an exception is raised.