blob: 3f38cbce7ad2337b33705921f1f36b251b1a302c [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
Raymond Hettinger469271d2011-01-27 20:38:46 +000010**Source code:** :source:`Lib/netrc.py`
11
12--------------
Georg Brandl116aa622007-08-15 14:28:22 +000013
Georg Brandl116aa622007-08-15 14:28:22 +000014The :class:`netrc` class parses and encapsulates the netrc file format used by
15the Unix :program:`ftp` program and other FTP clients.
16
17
18.. class:: netrc([file])
19
20 A :class:`netrc` instance or subclass instance encapsulates data from a netrc
21 file. The initialization argument, if present, specifies the file to parse. If
22 no argument is given, the file :file:`.netrc` in the user's home directory will
23 be read. Parse errors will raise :exc:`NetrcParseError` with diagnostic
24 information including the file name, line number, and terminating token.
25
26
27.. exception:: NetrcParseError
28
29 Exception raised by the :class:`netrc` class when syntactical errors are
30 encountered in source text. Instances of this exception provide three
31 interesting attributes: :attr:`msg` is a textual explanation of the error,
32 :attr:`filename` is the name of the source file, and :attr:`lineno` gives the
33 line number on which the error was found.
34
35
36.. _netrc-objects:
37
38netrc Objects
39-------------
40
41A :class:`netrc` instance has the following methods:
42
43
44.. method:: netrc.authenticators(host)
45
46 Return a 3-tuple ``(login, account, password)`` of authenticators for *host*.
47 If the netrc file did not contain an entry for the given host, return the tuple
48 associated with the 'default' entry. If neither matching host nor default entry
49 is available, return ``None``.
50
51
52.. method:: netrc.__repr__()
53
54 Dump the class data as a string in the format of a netrc file. (This discards
55 comments and may reorder the entries.)
56
57Instances of :class:`netrc` have public instance variables:
58
59
60.. attribute:: netrc.hosts
61
62 Dictionary mapping host names to ``(login, account, password)`` tuples. The
63 'default' entry, if any, is represented as a pseudo-host by that name.
64
65
66.. attribute:: netrc.macros
67
68 Dictionary mapping macro names to string lists.
69
70.. note::
71
Georg Brandle6bcc912008-05-12 18:05:20 +000072 Passwords are limited to a subset of the ASCII character set. All ASCII
73 punctuation is allowed in passwords, however, note that whitespace and
Georg Brandl116aa622007-08-15 14:28:22 +000074 non-printable characters are not allowed in passwords. This is a limitation
75 of the way the .netrc file is parsed and may be removed in the future.
76