[Python-checkins] cpython (merge 3.5 -> default): Issue #22636: Merge ctypes.util from 3.5

martin.panter python-checkins at python.org
Tue Jun 14 00:40:31 EDT 2016


https://hg.python.org/cpython/rev/a6a36bb6ee50
changeset: 101999:a6a36bb6ee50
parent: 101997:5899b2925b91
parent: 101998:96d297e9a8a8
user: Martin Panter <vadmium+py at gmail.com>
date: Tue Jun 14 04:31:14 2016 +0000
summary:
 Issue #22636: Merge ctypes.util from 3.5
files:
 Lib/ctypes/util.py | 54 ++++++++++++++++++++++-----------
 1 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -115,10 +115,13 @@
 env = dict(os.environ)
 env['LC_ALL'] = 'C'
 env['LANG'] = 'C'
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
+ try:
+ proc = subprocess.Popen(args,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ env=env)
+ except OSError: # E.g. bad executable
+ return None
 with proc:
 trace = proc.stdout.read()
 finally:
@@ -140,9 +143,12 @@
 if not f:
 return None
 
- proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
- stdout=subprocess.PIPE,
- stderr=subprocess.DEVNULL)
+ try:
+ proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL)
+ except OSError: # E.g. command not found
+ return None
 with proc:
 data = proc.stdout.read()
 res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
@@ -159,9 +165,12 @@
 # objdump is not available, give up
 return None
 
- proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
- stdout=subprocess.PIPE,
- stderr=subprocess.DEVNULL)
+ try:
+ proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL)
+ except OSError: # E.g. bad executable
+ return None
 with proc:
 dump = proc.stdout.read()
 res = re.search(br'\sSONAME\s+([^\s]+)', dump)
@@ -187,11 +196,15 @@
 expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
 expr = os.fsencode(expr)
 
- proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
- stdout=subprocess.PIPE,
- stderr=subprocess.DEVNULL)
- with proc:
- data = proc.stdout.read()
+ try:
+ proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL)
+ except OSError: # E.g. command not found
+ data = b''
+ else:
+ with proc:
+ data = proc.stdout.read()
 
 res = re.findall(expr, data)
 if not res:
@@ -214,10 +227,13 @@
 args = ('/usr/bin/crle',)
 
 paths = None
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.DEVNULL,
- env=env)
+ try:
+ proc = subprocess.Popen(args,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL,
+ env=env)
+ except OSError: # E.g. bad executable
+ return None
 with proc:
 for line in proc.stdout:
 line = line.strip()
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /