Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 1 | \section{\module{netrc} --- |
Fred Drake | 39cddb7 | 1999-01-12 19:22:11 +0000 | [diff] [blame] | 2 | netrc file processing} |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{standard}{netrc} |
Fred Drake | 39cddb7 | 1999-01-12 19:22:11 +0000 | [diff] [blame] | 5 | % Note the \protect needed for \file... ;-( |
| 6 | \modulesynopsis{Loading of \protect\file{.netrc} files.} |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 7 | \moduleauthor{Eric S. Raymond}{esr@snark.thyrsus.com} |
| 8 | \sectionauthor{Eric S. Raymond}{esr@snark.thyrsus.com} |
| 9 | |
| 10 | |
Fred Drake | 292b9eb | 1998-12-22 18:40:50 +0000 | [diff] [blame] | 11 | \versionadded{1.5.2} |
| 12 | |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 13 | The \class{netrc} class parses and encapsulates the netrc file format |
| 14 | used by the \UNIX{} \program{ftp} program and other FTP clients. |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 15 | |
| 16 | \begin{classdesc}{netrc}{\optional{file}} |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 17 | A \class{netrc} instance or subclass instance encapsulates data from |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 18 | a netrc file. The initialization argument, if present, specifies the |
| 19 | file to parse. If no argument is given, the file \file{.netrc} in the |
| 20 | user's home directory will be read. Parse errors will raise |
Fred Drake | 990b0fe | 2001-03-06 06:55:18 +0000 | [diff] [blame] | 21 | \exception{NetrcParseError} with diagnostic information including the |
| 22 | file name, line number, and terminating token. |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 23 | \end{classdesc} |
| 24 | |
Fred Drake | 990b0fe | 2001-03-06 06:55:18 +0000 | [diff] [blame] | 25 | \begin{excdesc}{NetrcParseError} |
| 26 | Exception raised by the \class{netrc} class when syntactical errors |
| 27 | are encountered in source text. Instances of this exception provide |
| 28 | three interesting attributes: \member{msg} is a textual explanation |
| 29 | of the error, \member{filename} is the name of the source file, and |
| 30 | \member{lineno} gives the line number on which the error was found. |
| 31 | \end{excdesc} |
| 32 | |
Fred Drake | 806764b | 1999-04-23 17:03:21 +0000 | [diff] [blame] | 33 | |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 34 | \subsection{netrc Objects \label{netrc-objects}} |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 35 | |
| 36 | A \class{netrc} instance has the following methods: |
| 37 | |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 38 | \begin{methoddesc}{authenticators}{host} |
| 39 | Return a 3-tuple \code{(\var{login}, \var{account}, \var{password})} |
| 40 | of authenticators for \var{host}. If the netrc file did not |
| 41 | contain an entry for the given host, return the tuple associated with |
| 42 | the `default' entry. If neither matching host nor default entry is |
| 43 | available, return \code{None}. |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 44 | \end{methoddesc} |
| 45 | |
Fred Drake | 806764b | 1999-04-23 17:03:21 +0000 | [diff] [blame] | 46 | \begin{methoddesc}{__repr__}{} |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 47 | Dump the class data as a string in the format of a netrc file. |
| 48 | (This discards comments and may reorder the entries.) |
| 49 | \end{methoddesc} |
| 50 | |
| 51 | Instances of \class{netrc} have public instance variables: |
| 52 | |
| 53 | \begin{memberdesc}{hosts} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 54 | Dictionary mapping host names to \code{(\var{login}, \var{account}, |
Fred Drake | 1189fa9 | 1998-12-22 18:24:13 +0000 | [diff] [blame] | 55 | \var{password})} tuples. The `default' entry, if any, is represented |
| 56 | as a pseudo-host by that name. |
Guido van Rossum | 5e97c9d | 1998-12-22 05:18:24 +0000 | [diff] [blame] | 57 | \end{memberdesc} |
| 58 | |
| 59 | \begin{memberdesc}{macros} |
| 60 | Dictionary mapping macro names to string lists. |
| 61 | \end{memberdesc} |
Skip Montanaro | 1bd1d85 | 2003-04-23 20:22:12 +0000 | [diff] [blame] | 62 | |
Skip Montanaro | 54a234a | 2003-04-23 20:35:14 +0000 | [diff] [blame] | 63 | \note{Passwords are limited to a subset of the ASCII character set. |
| 64 | Versions of this module prior to 2.3 were extremely limited. Starting with |
| 65 | 2.3, all ASCII punctuation is allowed in passwords. However, note that |
| 66 | whitespace and non-printable characters are not allowed in passwords. This |
| 67 | is a limitation of the way the .netrc file is parsed and may be removed in |
| 68 | the future.} |