/Doc/library/netrc.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 76 lines · 45 code · 31 blank · 0 comment · 0 complexity · 952a908d6e94d09cd51ba2fea04d87f1 MD5 · raw file

  1. :mod:`netrc` --- netrc file processing
  2. ======================================
  3. .. module:: netrc
  4. :synopsis: Loading of .netrc files.
  5. .. moduleauthor:: Eric S. Raymond <esr@snark.thyrsus.com>
  6. .. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com>
  7. .. versionadded:: 1.5.2
  8. The :class:`netrc` class parses and encapsulates the netrc file format used by
  9. the Unix :program:`ftp` program and other FTP clients.
  10. .. class:: netrc([file])
  11. A :class:`netrc` instance or subclass instance encapsulates data from a netrc
  12. file. The initialization argument, if present, specifies the file to parse. If
  13. no argument is given, the file :file:`.netrc` in the user's home directory will
  14. be read. Parse errors will raise :exc:`NetrcParseError` with diagnostic
  15. information including the file name, line number, and terminating token.
  16. .. exception:: NetrcParseError
  17. Exception raised by the :class:`netrc` class when syntactical errors are
  18. encountered in source text. Instances of this exception provide three
  19. interesting attributes: :attr:`msg` is a textual explanation of the error,
  20. :attr:`filename` is the name of the source file, and :attr:`lineno` gives the
  21. line number on which the error was found.
  22. .. _netrc-objects:
  23. netrc Objects
  24. -------------
  25. A :class:`netrc` instance has the following methods:
  26. .. method:: netrc.authenticators(host)
  27. Return a 3-tuple ``(login, account, password)`` of authenticators for *host*.
  28. If the netrc file did not contain an entry for the given host, return the tuple
  29. associated with the 'default' entry. If neither matching host nor default entry
  30. is available, return ``None``.
  31. .. method:: netrc.__repr__()
  32. Dump the class data as a string in the format of a netrc file. (This discards
  33. comments and may reorder the entries.)
  34. Instances of :class:`netrc` have public instance variables:
  35. .. attribute:: netrc.hosts
  36. Dictionary mapping host names to ``(login, account, password)`` tuples. The
  37. 'default' entry, if any, is represented as a pseudo-host by that name.
  38. .. attribute:: netrc.macros
  39. Dictionary mapping macro names to string lists.
  40. .. note::
  41. Passwords are limited to a subset of the ASCII character set. Versions of
  42. this module prior to 2.3 were extremely limited. Starting with 2.3, all
  43. ASCII punctuation is allowed in passwords. However, note that whitespace and
  44. non-printable characters are not allowed in passwords. This is a limitation
  45. of the way the .netrc file is parsed and may be removed in the future.