Commit cfe1aefc authored by Elvis Pranskevichus's avatar Elvis Pranskevichus Committed by Éric Araujo

bpo-31681: Make sure pkgutil.get_data closes files properly (#3875)

Also remove an obsolete note about
backward compat with old Pythons.
parent cc4b6f1c
"""Utilities to support packages.""" """Utilities to support packages."""
# NOTE: This module must remain compatible with Python 2.3, as it is shared
# by setuptools for distribution with Python 2.3 and up.
import os import os
import sys import sys
import imp import imp
...@@ -252,7 +249,8 @@ class ImpLoader: ...@@ -252,7 +249,8 @@ class ImpLoader:
return mod return mod
def get_data(self, pathname): def get_data(self, pathname):
return open(pathname, "rb").read() with open(pathname, "rb") as file:
return file.read()
def _reopen(self): def _reopen(self):
if self.file and self.file.closed: if self.file and self.file.closed:
......
Fix pkgutil.get_data to avoid leaking open files.
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