diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2014-05-17 22:19:13 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-05-17 22:19:13 -0400 |
| commit | e17c29d129d4d6ef7a4290f5b819099338e13d11 (patch) | |
| tree | 1e51e525f9e1fde125efe1a5cc3f1a16ac0e024e | |
| parent | 65704b309b1791c07522917fe2979a4a949c9f84 (diff) | |
| download | python-setuptools-bitbucket-e17c29d129d4d6ef7a4290f5b819099338e13d11.tar.gz | |
Use context managers in pkg_resources
| -rw-r--r-- | pkg_resources.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index ba03f628..4c28d72c 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -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') - file_contents = f.read() - f.close() + with open(file_path, 'rb') as f: + file_contents = f.read() 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') - metadata = f.read() - f.close() + with open(self.path,'rU') as f: + metadata = f.read() 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 |
