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