]> granicus.if.org Git - python/commitdiff
explicitly close the file, merged from py3k
authorPhilip Jenvey <pjenvey@underboss.org>
Thu, 28 May 2009 03:10:59 +0000 (03:10 +0000)
committerPhilip Jenvey <pjenvey@underboss.org>
Thu, 28 May 2009 03:10:59 +0000 (03:10 +0000)
Lib/netrc.py

index 5493d77d3e805da491b365dc8f1b246fe8d3eefe..723fc31d86fe52addacaac14551bdfa185ebccf8 100644 (file)
@@ -26,9 +26,12 @@ class netrc:
                 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: