bronx.net.netrc

An object-oriented interface to .netrc files.

This code has been extacted from Python 3.5 and two patches have been applied:

  • With this class, the user login taken into accout when looking for .netrc lines (see the login argument for the netrc.authenticators() method.

  • Password can be surrounded with simple or double quotes (for compatibility with the standard Linux FTP client).

Classes

class bronx.net.netrc.netrc(file=None)[source]

Bases: object

A netrc instance or subclass instance encapsulates data from a netrc file.

The initialisation argument, if present, specifies the file to parse. If no argument is given, the file .netrc in the user’s home directory will be read. Parse errors will raise NetrcParseError with diagnostic information including the file name, line number, and terminating token. If no argument is specified on a POSIX system, the presence of passwords in the .netrc file will raise a NetrcParseError if the file ownership or permissions are insecure (owned by a user other than the user running the process, or accessible for read or write by any other user). This implements security behavior equivalent to that of ftp and other programs that use .netrc.

hosts

Dictionary mapping host names to (login, account, password) tuples. The ‘default’ entry, if any, is represented as a pseudo-host by that name.

authenticators(host, login=None)[source]

Return a 3-tuple (login, account, password) of authenticators for 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 None.

When provided, the optional login argument selects a tuple with a matching user name.

Exceptions

exception bronx.net.netrc.NetrcParseError(msg, filename=None, lineno=None)[source]

Bases: Exception

Exception raised by the netrc class when syntactical errors are encountered in source text. Instances of this exception provide three interesting attributes: msg is a textual explanation of the error, filename is the name of the source file, and lineno gives the line number on which the error was found.