summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-07 11:26:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-07 11:26:59 (GMT)
commitba7c226095703f63c78b00e56f1db8d99ac3a54a (patch)
treefb28601ee220f3dea93066c09625e5fc86716b13
parent978b9d2a27fe0d787a21465e8728dab48ca57e83 (diff)
downloadcpython-ba7c226095703f63c78b00e56f1db8d99ac3a54a.zip
cpython-ba7c226095703f63c78b00e56f1db8d99ac3a54a.tar.gz
cpython-ba7c226095703f63c78b00e56f1db8d99ac3a54a.tar.bz2
Make platform.libc_ver() less slow
-rwxr-xr-xLib/platform.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 0cb0a4f..a14639e 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -130,15 +130,15 @@ except AttributeError:
### Platform specific APIs
-_libc_search = re.compile(r'(__libc_init)'
- '|'
- '(GLIBC_([0-9.]+))'
- '|'
- '(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
+_libc_search = re.compile(b'(__libc_init)'
+ b'|'
+ b'(GLIBC_([0-9.]+))'
+ b'|'
+ br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
def libc_ver(executable=sys.executable,lib='',version='',
- chunksize=2048):
+ chunksize=16384):
""" Tries to determine the libc version that the file executable
(which defaults to the Python interpreter) is linked against.
@@ -159,17 +159,22 @@ def libc_ver(executable=sys.executable,lib='',version='',
# able to open symlinks for reading
executable = os.path.realpath(executable)
f = open(executable,'rb')
- binary = f.read(chunksize).decode('latin-1')
+ binary = f.read(chunksize)
pos = 0
while 1:
- m = _libc_search.search(binary,pos)
+ if b'libc' in binary or b'GLIBC' in binary:
+ m = _libc_search.search(binary,pos)
+ else:
+ m = None
if not m:
- binary = f.read(chunksize).decode('latin-1')
+ binary = f.read(chunksize)
if not binary:
break
pos = 0
continue
- libcinit,glibc,glibcversion,so,threads,soversion = m.groups()
+ libcinit,glibc,glibcversion,so,threads,soversion = [
+ s.decode('latin1') if s is not None else s
+ for s in m.groups()]
if libcinit and not lib:
lib = 'libc'
elif glibc: