Commit 24d18354 authored by Jason R. Coombs's avatar Jason R. Coombs

Use context managers in pkg_resources

parent ec81e4dc
......@@ -1694,9 +1694,8 @@ class ZipProvider(EggProvider):
return False
# check that the contents match
zip_contents = self.loader.get_data(zip_path)
f = open(file_path, 'rb')
with open(file_path, 'rb') as f:
file_contents = f.read()
f.close()
return zip_contents == file_contents
def _get_eager_resources(self):
......@@ -1764,9 +1763,8 @@ class FileMetadata(EmptyProvider):
def get_metadata(self, name):
if name=='PKG-INFO':
f = open(self.path,'rU')
with open(self.path,'rU') as f:
metadata = f.read()
f.close()
return metadata
raise KeyError("No metadata except PKG-INFO is available")
......@@ -1889,11 +1887,8 @@ def find_on_path(importer, path_item, only=False):
for dist in dists:
yield dist
elif not only and lower.endswith('.egg-link'):
entry_file = open(os.path.join(path_item, entry))
try:
with open(os.path.join(path_item, entry)) as entry_file:
entry_lines = entry_file.readlines()
finally:
entry_file.close()
for line in entry_lines:
if not line.strip():
continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment