summaryrefslogtreecommitdiff
path: root/Lib/platform.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py98
1 files changed, 60 insertions, 38 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index ad425a16c1..f3d2c42387 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -116,6 +116,8 @@ __version__ = '1.0.7'
import collections
import sys, os, re, subprocess
+import warnings
+
### Globals & Constants
# Determine the platform's /dev/null device
@@ -165,40 +167,39 @@ def libc_ver(executable=sys.executable, lib='', version='',
# here to work around problems with Cygwin not being
# able to open symlinks for reading
executable = os.path.realpath(executable)
- f = open(executable, 'rb')
- binary = f.read(chunksize)
- pos = 0
- while 1:
- 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)
- if not binary:
- break
- pos = 0
- continue
- 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:
- if lib != 'glibc':
- lib = 'glibc'
- version = glibcversion
- elif glibcversion > version:
- version = glibcversion
- elif so:
- if lib != 'glibc':
+ with open(executable, 'rb') as f:
+ binary = f.read(chunksize)
+ pos = 0
+ while 1:
+ 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)
+ if not binary:
+ break
+ pos = 0
+ continue
+ 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'
- if soversion and soversion > version:
- version = soversion
- if threads and version[-len(threads):] != threads:
- version = version + threads
- pos = m.end()
- f.close()
+ elif glibc:
+ if lib != 'glibc':
+ lib = 'glibc'
+ version = glibcversion
+ elif glibcversion > version:
+ version = glibcversion
+ elif so:
+ if lib != 'glibc':
+ lib = 'libc'
+ if soversion and soversion > version:
+ version = soversion
+ if threads and version[-len(threads):] != threads:
+ version = version + threads
+ pos = m.end()
return lib, version
def _dist_try_harder(distname, version, id):
@@ -300,6 +301,15 @@ def linux_distribution(distname='', version='', id='',
supported_dists=_supported_dists,
full_distribution_name=1):
+ import warnings
+ warnings.warn("dist() and linux_distribution() functions are deprecated "
+ "in Python 3.5 and will be removed in Python 3.7",
+ PendingDeprecationWarning, stacklevel=2)
+ return _linux_distribution(distname, version, id, supported_dists,
+ full_distribution_name)
+
+def _linux_distribution(distname, version, id, supported_dists,
+ full_distribution_name):
""" Tries to determine the name of the Linux OS distribution name.
@@ -366,9 +376,13 @@ def dist(distname='', version='', id='',
args given as parameters.
"""
- return linux_distribution(distname, version, id,
- supported_dists=supported_dists,
- full_distribution_name=0)
+ import warnings
+ warnings.warn("dist() and linux_distribution() functions are deprecated "
+ "in Python 3.5 and will be removed in Python 3.7",
+ PendingDeprecationWarning, stacklevel=2)
+ return _linux_distribution(distname, version, id,
+ supported_dists=supported_dists,
+ full_distribution_name=0)
def popen(cmd, mode='r', bufsize=-1):
@@ -428,7 +442,7 @@ def _syscmd_ver(system='', release='', version='',
# Try some common cmd strings
for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
try:
- pipe = popen(cmd)
+ pipe = os.popen(cmd)
info = pipe.read()
if pipe.close():
raise OSError('command failed')
@@ -1381,7 +1395,15 @@ def platform(aliased=0, terse=0):
elif system in ('Linux',):
# Linux based systems
- distname, distversion, distid = dist('')
+ with warnings.catch_warnings():
+ # see issue #1322 for more information
+ warnings.filterwarnings(
+ 'ignore',
+ 'dist\(\) and linux_distribution\(\) '
+ 'functions are deprecated .*',
+ PendingDeprecationWarning,
+ )
+ distname, distversion, distid = dist('')
if distname and not terse:
platform = _platform(system, release, machine, processor,
'with',