diff options
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-x | Lib/platform.py | 110 |
1 files changed, 18 insertions, 92 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index e04bcb4..172722e 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: @@ -357,92 +362,13 @@ def dist(distname='',version='',id='', supported_dists=supported_dists, full_distribution_name=0) -class _popen: - - """ Fairly portable (alternative) popen implementation. - - This is mostly needed in case os.popen() is not available, or - doesn't work as advertised, e.g. in Win9X GUI programs like - PythonWin or IDLE. - - Writing to the pipe is currently not supported. - - """ - tmpfile = '' - pipe = None - bufsize = None - mode = 'r' - - def __init__(self,cmd,mode='r',bufsize=None): - - if mode != 'r': - raise ValueError('popen()-emulation only supports read mode') - import tempfile - self.tmpfile = tmpfile = tempfile.mktemp() - os.system(cmd + ' > %s' % tmpfile) - self.pipe = open(tmpfile,'rb') - self.bufsize = bufsize - self.mode = mode - - def read(self): - - return self.pipe.read() - - def readlines(self): - - if self.bufsize is not None: - return self.pipe.readlines() - - def close(self, - - remove=os.unlink,error=os.error): - - if self.pipe: - rc = self.pipe.close() - else: - rc = 255 - if self.tmpfile: - try: - remove(self.tmpfile) - except error: - pass - return rc - - # Alias - __del__ = close - def popen(cmd, mode='r', bufsize=-1): """ Portable popen() interface. """ - # Find a working popen implementation preferring win32pipe.popen - # over os.popen over _popen - popen = None - if os.environ.get('OS','') == 'Windows_NT': - # On NT win32pipe should work; on Win9x it hangs due to bugs - # in the MS C lib (see MS KnowledgeBase article Q150956) - try: - import win32pipe - except ImportError: - pass - else: - popen = win32pipe.popen - if popen is None: - if hasattr(os,'popen'): - popen = os.popen - # Check whether it works... it doesn't in GUI programs - # on Windows platforms - if sys.platform == 'win32': # XXX Others too ? - try: - popen('') - except os.error: - popen = _popen - else: - popen = _popen - if bufsize is None: - return popen(cmd,mode) - else: - return popen(cmd,mode,bufsize) + import warnings + warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2) + return os.popen(cmd, mode, bufsize) def _norm_version(version, build=''): |