libnetrc.tex 2.24 KB
Newer Older
1
\section{\module{netrc} ---
Fred Drake's avatar
Fred Drake committed
2
         netrc file processing}
3 4

\declaremodule{standard}{netrc}
Fred Drake's avatar
Fred Drake committed
5 6
% Note the \protect needed for \file... ;-(
\modulesynopsis{Loading of \protect\file{.netrc} files.}
7 8 9 10
\moduleauthor{Eric S. Raymond}{esr@snark.thyrsus.com}
\sectionauthor{Eric S. Raymond}{esr@snark.thyrsus.com}


11 12
\versionadded{1.5.2}

13 14
The \class{netrc} class parses and encapsulates the netrc file format
used by the \UNIX{} \program{ftp} program and other FTP clients.
15 16

\begin{classdesc}{netrc}{\optional{file}}
17
A \class{netrc} instance or subclass instance encapsulates data from 
18 19 20
a netrc file.  The initialization argument, if present, specifies the
file to parse.  If no argument is given, the file \file{.netrc} in the
user's home directory will be read.  Parse errors will raise
21 22
\exception{NetrcParseError} with diagnostic information including the
file name, line number, and terminating token.
23 24
\end{classdesc}

25 26 27 28 29 30 31 32
\begin{excdesc}{NetrcParseError}
Exception raised by the \class{netrc} class when syntactical errors
are encountered in source text.  Instances of this exception provide
three interesting attributes:  \member{msg} is a textual explanation
of the error, \member{filename} is the name of the source file, and
\member{lineno} gives the line number on which the error was found.
\end{excdesc}

33

34
\subsection{netrc Objects \label{netrc-objects}}
35 36 37

A \class{netrc} instance has the following methods:

38 39 40 41 42 43
\begin{methoddesc}{authenticators}{host}
Return a 3-tuple \code{(\var{login}, \var{account}, \var{password})}
of authenticators for \var{host}.  If the netrc file did not
contain an entry for the given host, return the tuple associated with
the `default' entry.  If neither matching host nor default entry is
available, return \code{None}.
44 45
\end{methoddesc}

46
\begin{methoddesc}{__repr__}{}
47 48 49 50 51 52 53
Dump the class data as a string in the format of a netrc file.
(This discards comments and may reorder the entries.)
\end{methoddesc}

Instances of \class{netrc} have public instance variables:

\begin{memberdesc}{hosts}
54
Dictionary mapping host names to \code{(\var{login}, \var{account},
55 56
\var{password})} tuples.  The `default' entry, if any, is represented
as a pseudo-host by that name.
57 58 59 60 61
\end{memberdesc}

\begin{memberdesc}{macros}
Dictionary mapping macro names to string lists.
\end{memberdesc}