summaryrefslogtreecommitdiffstats
path: root/Lib/netrc.py
diff options
context:
space:
mode:
authorPaul Prescod <prescod@prescod.net>2002-03-18 02:13:48 (GMT)
committerPaul Prescod <prescod@prescod.net>2002-03-18 02:13:48 (GMT)
commitb845f3b4dd2074b22eb2915ba4514bd2d5a87769 (patch)
tree4de27aa725770443af6826fa9c5671bb2dc3cb37 /Lib/netrc.py
parent10acc8f9e23e8b5afc39041387d768342464e658 (diff)
downloadcpython-b845f3b4dd2074b22eb2915ba4514bd2d5a87769.zip
cpython-b845f3b4dd2074b22eb2915ba4514bd2d5a87769.tar.gz
cpython-b845f3b4dd2074b22eb2915ba4514bd2d5a87769.tar.bz2
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.
Diffstat (limited to 'Lib/netrc.py')
-rw-r--r--Lib/netrc.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/netrc.py b/Lib/netrc.py
index 3f1c7c3..b78d4d8 100644
--- a/Lib/netrc.py
+++ b/Lib/netrc.py
@@ -22,7 +22,10 @@ class NetrcParseError(Exception):
class netrc:
def __init__(self, file=None):
if not file:
- file = os.path.join(os.environ['HOME'], ".netrc")
+ try:
+ file = os.path.join(os.environ['HOME'], ".netrc")
+ except KeyError:
+ raise IOError("Could not find .netrc: $HOME is not set")
fp = open(file)
self.hosts = {}
self.macros = {}