[issue11416] netrc module does not handle multiple entries for a single host
New submission from saffroy : I have a netrc file with two entries for the same host. The netrc module only returns the last entry. $ cat > .netrc machine host.com login foo password foo machine host.com login bar password bar $ python -c 'import netrc; print netrc.netrc()' machine host.com login 'bar' password 'bar' My Linux ftp clients (ftp, lftp) always use the first entry for a given host. Also lftp can use the password from the proper entry if I supply the host and login. With the netrc module in Python 2.6.6 (as tested on Debian Squeeze), I can only retrieve the last entry. -- components: Library (Lib) messages: 130193 nosy: saffroy priority: normal severity: normal status: open title: netrc module does not handle multiple entries for a single host type: behavior versions: Python 2.6 ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
saffroy added the comment: I could spend some time on a small patch. Here are the changes I would consider: - netrc.authenticators() could return the first entry matching a given host (now it returns the last) - it could also accept an extra parameter (with default=None), a login to select the right account/password for a given host - it could also return a list of entries (tuples) matching the supplied host (now it always returns only one tuple), or a new method could do that IMHO the last change would make the overall behaviour more consistent (BTW note the plural for "authenticators"), but it could also break existing apps. Comments? -- ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Changes by Jean-Marc Saffroy : Removed file: http://bugs.python.org/file21443/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Ping? A patch is available for review. -- ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: You are suggesting something like this, I suppose? --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -105,8 +105,8 @@ class netrc: def __repr__(self): """Dump the class data in the format of a .netrc file.""" rep = "" -for host in self.allhosts.keys(): -for attrs in self.allhosts[host]: +for (host, attrlist) in self.allhosts.items(): +for attrs in attrlist: rep = rep + "machine "+ host + "\n\tlogin " + repr(attrs[0]) + "\n" if attrs[1]: rep = rep + "account " + repr(attrs[1]) -- ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Patch slightly updated after Eric's comments. -- Added file: http://bugs.python.org/file22193/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Patch formatting changed to be more review-friendly (looks like MQ-style patch isn't?), otherwise same as 2011-05-30 16:14. -- Added file: http://bugs.python.org/file22194/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Eric: yes I can look into the asserts, but note I generated and tested my patch from a checkout of 2.6 (see my first report), so maybe that's why I didn't see any warning. -- ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Here is a patch against 2.7. -- Added file: http://bugs.python.org/file22195/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Additional patch for docstrings and documentation. Applies on top of previous patch. -- Added file: http://bugs.python.org/file22204/netrc-doc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: So I finally cooked a little patch for netrc.py in python 2.6. The patch extends netrc.authenticators() with an extra parameter to select a login name, but otherwise the behaviour remains the same (still returns the last entry for a given host). Lightly tested, works for me. -- keywords: +patch Added file: http://bugs.python.org/file21443/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy added the comment: Good that you mentioned the official tests, they let me see that netrc.hosts is actually part of the API, and my first patch broke it. Here is an updated patch, with extra tests. -- Added file: http://bugs.python.org/file21444/netrc.patch ___ Python tracker <http://bugs.python.org/issue11416> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
