[Python-checkins] r72972 - python/trunk/Lib/netrc.py

philip.jenvey python-checkins at python.org
Thu May 28 05:10:59 CEST 2009


Author: philip.jenvey
Date: Thu May 28 05:10:59 2009
New Revision: 72972

Log:
explicitly close the file, merged from py3k


Modified:
   python/trunk/Lib/netrc.py

Modified: python/trunk/Lib/netrc.py
==============================================================================
--- python/trunk/Lib/netrc.py	(original)
+++ python/trunk/Lib/netrc.py	Thu May 28 05:10:59 2009
@@ -26,9 +26,12 @@
                 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 = {}
+        with open(file) as fp:
+            self._parse(file, fp)
+
+    def _parse(self, file, fp):
         lexer = shlex.shlex(fp)
         lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
         while 1:


More information about the Python-checkins mailing list