summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/ctypes/util.py')
-rw-r--r--Lib/ctypes/util.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 054c511..0cf2076 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -102,9 +102,8 @@ elif os.name == "posix":
finally:
try:
os.unlink(ccout)
- except OSError as e:
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
+ pass
if rv == 10:
raise OSError('gcc or cc command not found')
res = re.search(expr, trace)
@@ -133,8 +132,10 @@ elif os.name == "posix":
cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
"objdump -p -j .dynamic 2>/dev/null " + f
f = os.popen(cmd)
- dump = f.read()
- rv = f.close()
+ try:
+ dump = f.read()
+ finally:
+ rv = f.close()
if rv == 10:
raise OSError('objdump command not found')
res = re.search(r'\sSONAME\s+([^\s]+)', dump)
@@ -177,10 +178,11 @@ elif os.name == "posix":
else:
cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null'
- for line in os.popen(cmd).readlines():
- line = line.strip()
- if line.startswith('Default Library Path (ELF):'):
- paths = line.split()[4]
+ with contextlib.closing(os.popen(cmd)) as f:
+ for line in f.readlines():
+ line = line.strip()
+ if line.startswith('Default Library Path (ELF):'):
+ paths = line.split()[4]
if not paths:
return None