From: Philip Jenvey Date: Thu, 28 May 2009 03:10:59 +0000 (+0000) Subject: explicitly close the file, merged from py3k X-Git-Tag: v2.7a1~1088 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80319a3a53dca3b816390fc87ac557d1e9e81e89;p=python explicitly close the file, merged from py3k --- diff --git a/Lib/netrc.py b/Lib/netrc.py index 5493d77d3e..723fc31d86 100644 --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -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: