Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b845f3b

Browse files
author
Paul Prescod
committed
netrc will now raise a more predictable exception when $HOME is not set
(as it is often not on Windows). The code was always designed so that it would raise an IOError if there was no .netrc. But if there was no $HOME it would return a KeyError which would be somewhat unexpected for code that didn't know the algorithm it used to find .netrc. The particular code that triggered this problem for me was ftpmirror.py which handled the IOError gracefully, but not the KeyError.
1 parent 10acc8f commit b845f3b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/netrc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def __str__(self):
2222
class netrc:
2323
def __init__(self, file=None):
2424
if not file:
25-
file = os.path.join(os.environ['HOME'], ".netrc")
25+
try:
26+
file = os.path.join(os.environ['HOME'], ".netrc")
27+
except KeyError:
28+
raise IOError("Could not find .netrc: $HOME is not set")
2629
fp = open(file)
2730
self.hosts = {}
2831
self.macros = {}

0 commit comments

Comments
 (0)