diff options
| author | Julian Andres Klode <jak@debian.org> | 2011-04-06 11:15:47 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2011-04-06 11:15:47 +0200 |
| commit | 5ad927a38cad08a2d79f327e7bb3cc46316fa6a4 (patch) | |
| tree | 0ad729e5abaeaa66923883251587695ea2e4c00c /apt/package.py | |
| parent | b766dc001aeea1c18b0c17c1d5029673ef539ef0 (diff) | |
| download | python-apt-5ad927a38cad08a2d79f327e7bb3cc46316fa6a4.tar.gz | |
all: Fix all instances of ResourceWarning about unclosed files
Diffstat (limited to 'apt/package.py')
| -rw-r--r-- | apt/package.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/apt/package.py b/apt/package.py index d7d5d167..54ef1c01 100644 --- a/apt/package.py +++ b/apt/package.py @@ -50,9 +50,9 @@ __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record', def _file_is_same(path, size, md5): """Return ``True`` if the file is the same.""" - if (os.path.exists(path) and os.path.getsize(path) == size and - apt_pkg.md5sum(open(path)) == md5): - return True + if os.path.exists(path) and os.path.getsize(path) == size: + with open(path) as fobj: + return apt_pkg.md5sum(fobj) == md5 class FetchError(Exception): @@ -994,11 +994,8 @@ class Package(object): """ path = "/var/lib/dpkg/info/%s.list" % self.name try: - file_list = open(path, "rb") - try: + with open(path, "rb") as file_list: return file_list.read().decode("utf-8").split(u"\n") - finally: - file_list.close() except EnvironmentError: return [] @@ -1104,6 +1101,7 @@ class Package(object): # Check if the download was canceled if cancel_lock and cancel_lock.isSet(): return u"" + # FIXME: python3.2: Should be closed manually changelog_file = urllib2.urlopen(uri) # do only get the lines that are new changelog = u"" |
