[Python-checkins] CVS: python/dist/src/Lib netrc.py,1.12,1.13

Paul Prescod prescod@users.sourceforge.net
Sun, 17 Mar 2002 18:13:50 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv20396

Modified Files:
	netrc.py 
Log Message:
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.


Index: netrc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/netrc.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** netrc.py	15 Apr 2001 12:51:42 -0000	1.12
--- netrc.py	18 Mar 2002 02:13:48 -0000	1.13
***************
*** 23,27 ****
      def __init__(self, file=None):
          if not file:
!             file = os.path.join(os.environ['HOME'], ".netrc")
          fp = open(file)
          self.hosts = {}
--- 23,30 ----
      def __init__(self, file=None):
          if not file:
!             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 = {}