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