blob: c7573f9155c19f787028ab721b7de85add303836 [file] [log] [blame]
Fred Drake1189fa91998-12-22 18:24:13 +00001\section{\module{netrc} ---
Fred Drake39cddb71999-01-12 19:22:11 +00002 netrc file processing}
Fred Drake1189fa91998-12-22 18:24:13 +00003
4\declaremodule{standard}{netrc}
Fred Drake39cddb71999-01-12 19:22:11 +00005% Note the \protect needed for \file... ;-(
6\modulesynopsis{Loading of \protect\file{.netrc} files.}
Fred Drake1189fa91998-12-22 18:24:13 +00007\moduleauthor{Eric S. Raymond}{esr@snark.thyrsus.com}
8\sectionauthor{Eric S. Raymond}{esr@snark.thyrsus.com}
9
10
Fred Drake292b9eb1998-12-22 18:40:50 +000011\versionadded{1.5.2}
12
Fred Drake1189fa91998-12-22 18:24:13 +000013The \class{netrc} class parses and encapsulates the netrc file format
14used by the \UNIX{} \program{ftp} program and other FTP clients.
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000015
16\begin{classdesc}{netrc}{\optional{file}}
Thomas Woutersf8316632000-07-16 19:01:10 +000017A \class{netrc} instance or subclass instance encapsulates data from
Fred Drake1189fa91998-12-22 18:24:13 +000018a netrc file. The initialization argument, if present, specifies the
19file to parse. If no argument is given, the file \file{.netrc} in the
20user's home directory will be read. Parse errors will raise
Fred Drake990b0fe2001-03-06 06:55:18 +000021\exception{NetrcParseError} with diagnostic information including the
22file name, line number, and terminating token.
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000023\end{classdesc}
24
Fred Drake990b0fe2001-03-06 06:55:18 +000025\begin{excdesc}{NetrcParseError}
26Exception raised by the \class{netrc} class when syntactical errors
27are encountered in source text. Instances of this exception provide
28three interesting attributes: \member{msg} is a textual explanation
29of 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 Drake806764b1999-04-23 17:03:21 +000033
Fred Drake1189fa91998-12-22 18:24:13 +000034\subsection{netrc Objects \label{netrc-objects}}
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000035
36A \class{netrc} instance has the following methods:
37
Fred Drake1189fa91998-12-22 18:24:13 +000038\begin{methoddesc}{authenticators}{host}
39Return a 3-tuple \code{(\var{login}, \var{account}, \var{password})}
40of authenticators for \var{host}. If the netrc file did not
41contain an entry for the given host, return the tuple associated with
42the `default' entry. If neither matching host nor default entry is
43available, return \code{None}.
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000044\end{methoddesc}
45
Fred Drake806764b1999-04-23 17:03:21 +000046\begin{methoddesc}{__repr__}{}
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000047Dump 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
51Instances of \class{netrc} have public instance variables:
52
53\begin{memberdesc}{hosts}
Fred Drake38e5d272000-04-03 20:13:55 +000054Dictionary mapping host names to \code{(\var{login}, \var{account},
Fred Drake1189fa91998-12-22 18:24:13 +000055\var{password})} tuples. The `default' entry, if any, is represented
56as a pseudo-host by that name.
Guido van Rossum5e97c9d1998-12-22 05:18:24 +000057\end{memberdesc}
58
59\begin{memberdesc}{macros}
60Dictionary mapping macro names to string lists.
61\end{memberdesc}