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