This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arsyee
Recipients Frew Schmidt, Yuri.Bochkarev, arsyee, berker.peksag, brian.curtin, eric.araujo, luc, r.david.murray, rhettinger, saffroy
Date 2020-01-04.17:55:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578160531.01.0.70346062648.issue11416@roundup.psfhosted.org>
In-reply-to
Content
Just for further clarification on how .netrc is supposed to work, I tested some other implementations. Sorry if this comment gets too long, but it seems netrc is not really a standardized solution.

In my last comment I referred curl and wget, but of course the original implementation is ftp (which points to the netrc manual). The manual itself doesn't talk about priorities, but all the mentioned 3 tools are in common in that they take the first entry if the same machine is in the netrc file multiple times.

When trying to force using the second entry, though, breaks this consistency quickly: none of the above tools seem to support a query with host and login name provided.
ftp: doesn't support providing a user name from shell (and doesn't use netrc when opening a connection interactively)
curl: if username is provided, it interactively asks for a password and uses that (which may be an issue on my end, as source code suggested there is a login-based lookup)
wget: if username is provided without a password, it doesn't send a auth information at all (also wget doesn't send default auth information for http, which behavior can be altered somehow)

Actually these results suprised me, as I remembered I used host+login based lookup previously. And the answer was git clone via https: git's implementation is exactly what I would expect:
* if only host is provided, the first entry is used
* if both host and login is provided, it looks up the password for the appropriate login
* if no matching machine entry can be found, it uses the default entry
* it also supports login matching for the default entry

I'm about the send a pull request with my understanding on how netrc should work. Of course all comments are welcome, and I'm happy to alter the implementation (or break it up to smaller pieces if necessary). My priorities were:

* Not to break backward compatibility.
* Provide a way to consistently pick up the first entry, without the need to make modifications in all of the dependent libraries (see doc change).
* __repr__() had a bug: for the default entry, it gives 'machine default', instead of 'default'.
* another bug: 'machine default' is actually not supported, as the netrc.hosts dictionary cannot make a difference between the default entry and a machine called default (this has a partial fixed)

As r.david.murray mentioned, the hosts dictionary should probably be deprecated.
History
Date User Action Args
2020-01-04 17:55:31arsyeesetrecipients: + arsyee, rhettinger, eric.araujo, r.david.murray, brian.curtin, saffroy, berker.peksag, Yuri.Bochkarev, luc, Frew Schmidt
2020-01-04 17:55:31arsyeesetmessageid: <1578160531.01.0.70346062648.issue11416@roundup.psfhosted.org>
2020-01-04 17:55:30arsyeelinkissue11416 messages
2020-01-04 17:55:30arsyeecreate