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:
objectA
netrcinstance 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
.netrcin the user’s home directory will be read. Parse errors will raiseNetrcParseErrorwith 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.netrcfile will raise aNetrcParseErrorif 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, returnNone.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:
ExceptionException raised by the
netrcclass when syntactical errors are encountered in source text. Instances of this exception provide three interesting attributes:msgis a textual explanation of the error,filenameis the name of the source file, andlinenogives the line number on which the error was found.