diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index f5cb52cb474..5b2ff1b497b 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -243,33 +243,6 @@ Mac OS Platform Unix Platforms -------------- - -.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...)) - - This is another name for :func:`linux_distribution`. - - .. deprecated-removed:: 3.5 3.8 - See alternative like the `distro `_ package. - -.. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1) - - Tries to determine the name of the Linux OS distribution name. - - ``supported_dists`` may be given to define the set of Linux distributions to - look for. It defaults to a list of currently supported Linux distributions - identified by their release file name. - - If ``full_distribution_name`` is true (default), the full distribution read - from the OS is returned. Otherwise the short name taken from - ``supported_dists`` is used. - - Returns a tuple ``(distname,version,id)`` which defaults to the args given as - parameters. ``id`` is the item in parentheses after the version number. It - is usually the version codename. - - .. deprecated-removed:: 3.5 3.8 - See alternative like the `distro `_ package. - .. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048) Tries to determine the libc version against which the file executable (defaults diff --git a/Lib/platform.py b/Lib/platform.py index 20f9817f4ff..6051f2b5901 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -132,10 +132,6 @@ except AttributeError: # Standard Unix uses /dev/null DEV_NULL = '/dev/null' -# Directory to search for configuration information on Unix. -# Constant used by test_platform to test linux_distribution(). -_UNIXCONFDIR = '/etc' - ### Platform specific APIs _libc_search = re.compile(b'(__libc_init)' @@ -249,138 +245,6 @@ def _dist_try_harder(distname, version, id): return distname, version, id -_release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII) -_lsb_release_version = re.compile(r'(.+)' - r' release ' - r'([\d.]+)' - r'[^(]*(?:\((.+)\))?', re.ASCII) -_release_version = re.compile(r'([^0-9]+)' - r'(?: release )?' - r'([\d.]+)' - r'[^(]*(?:\((.+)\))?', re.ASCII) - -# See also http://www.novell.com/coolsolutions/feature/11251.html -# and http://linuxmafia.com/faq/Admin/release-files.html -# and http://data.linux-ntfs.org/rpm/whichrpm -# and http://www.die.net/doc/linux/man/man1/lsb_release.1.html - -_supported_dists = ( - 'SuSE', 'debian', 'fedora', 'redhat', 'centos', - 'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo', - 'UnitedLinux', 'turbolinux', 'arch', 'mageia') - -def _parse_release_file(firstline): - - # Default to empty 'version' and 'id' strings. Both defaults are used - # when 'firstline' is empty. 'id' defaults to empty when an id can not - # be deduced. - version = '' - id = '' - - # Parse the first line - m = _lsb_release_version.match(firstline) - if m is not None: - # LSB format: "distro release x.x (codename)" - return tuple(m.groups()) - - # Pre-LSB format: "distro x.x (codename)" - m = _release_version.match(firstline) - if m is not None: - return tuple(m.groups()) - - # Unknown format... take the first two words - l = firstline.strip().split() - if l: - version = l[0] - if len(l) > 1: - id = l[1] - return '', version, id - -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", DeprecationWarning, 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. - - The function first looks for a distribution release file in - /etc and then reverts to _dist_try_harder() in case no - suitable files are found. - - supported_dists may be given to define the set of Linux - distributions to look for. It defaults to a list of currently - supported Linux distributions identified by their release file - name. - - If full_distribution_name is true (default), the full - distribution read from the OS is returned. Otherwise the short - name taken from supported_dists is used. - - Returns a tuple (distname, version, id) which default to the - args given as parameters. - - """ - try: - etc = os.listdir(_UNIXCONFDIR) - except OSError: - # Probably not a Unix system - return distname, version, id - etc.sort() - for file in etc: - m = _release_filename.match(file) - if m is not None: - _distname, dummy = m.groups() - if _distname in supported_dists: - distname = _distname - break - else: - return _dist_try_harder(distname, version, id) - - # Read the first line - with open(os.path.join(_UNIXCONFDIR, file), 'r', - encoding='utf-8', errors='surrogateescape') as f: - firstline = f.readline() - _distname, _version, _id = _parse_release_file(firstline) - - if _distname and full_distribution_name: - distname = _distname - if _version: - version = _version - if _id: - id = _id - return distname, version, id - -# To maintain backwards compatibility: - -def dist(distname='', version='', id='', - - supported_dists=_supported_dists): - - """ Tries to determine the name of the Linux OS distribution name. - - The function first looks for a distribution release file in - /etc and then reverts to _dist_try_harder() in case no - suitable files are found. - - Returns a tuple (distname, version, id) which default to the - args given as parameters. - - """ - import warnings - warnings.warn("dist() and linux_distribution() functions are deprecated " - "in Python 3.5", DeprecationWarning, stacklevel=2) - return _linux_distribution(distname, version, id, - supported_dists=supported_dists, - full_distribution_name=0) - def popen(cmd, mode='r', bufsize=-1): """ Portable popen() interface. @@ -1338,26 +1202,11 @@ def platform(aliased=0, terse=0): platform = _platform(system, release, version, csd) elif system in ('Linux',): - # Linux based systems - with warnings.catch_warnings(): - # see issue #1322 for more information - warnings.filterwarnings( - 'ignore', - r'dist\(\) and linux_distribution\(\) ' - 'functions are deprecated .*', - DeprecationWarning, - ) - distname, distversion, distid = dist('') - if distname and not terse: - platform = _platform(system, release, machine, processor, - 'with', - distname, distversion, distid) - else: - # If the distribution name is unknown check for libc vs. glibc - libcname, libcversion = libc_ver(sys.executable) - platform = _platform(system, release, machine, processor, - 'with', - libcname+libcversion) + # check for libc vs. glibc + libcname, libcversion = libc_ver(sys.executable) + platform = _platform(system, release, machine, processor, + 'with', + libcname+libcversion) elif system == 'Java': # Java platforms r, v, vminfo, (os_name, os_version, os_arch) = java_ver() diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 5f1e28a5d95..7e3e40114b4 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -259,16 +259,6 @@ class PlatformTest(unittest.TestCase): self.assertEqual(cpid, pid) self.assertEqual(sts, 0) - def test_dist(self): - with warnings.catch_warnings(): - warnings.filterwarnings( - 'ignore', - r'dist\(\) and linux_distribution\(\) ' - 'functions are deprecated .*', - PendingDeprecationWarning, - ) - res = platform.dist() - def test_libc_ver(self): import os if os.path.isdir(sys.executable) and \ @@ -279,23 +269,6 @@ class PlatformTest(unittest.TestCase): executable = sys.executable res = platform.libc_ver(executable) - def test_parse_release_file(self): - - for input, output in ( - # Examples of release file contents: - ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')), - ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')), - ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')), - ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')), - ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')), - ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')), - ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')), - ('CentOS release 4', ('CentOS', '4', None)), - ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')), - ('', ('', '', '')), # If there's nothing there. - ): - self.assertEqual(platform._parse_release_file(input), output) - def test_popen(self): mswindows = (sys.platform == "win32") @@ -328,43 +301,5 @@ class PlatformTest(unittest.TestCase): returncode = ret >> 8 self.assertEqual(returncode, len(data)) - def test_linux_distribution_encoding(self): - # Issue #17429 - with tempfile.TemporaryDirectory() as tempdir: - filename = os.path.join(tempdir, 'fedora-release') - with open(filename, 'w', encoding='utf-8') as f: - f.write('Fedora release 19 (Schr\xf6dinger\u2019s Cat)\n') - - with mock.patch('platform._UNIXCONFDIR', tempdir): - with warnings.catch_warnings(): - warnings.filterwarnings( - 'ignore', - r'dist\(\) and linux_distribution\(\) ' - 'functions are deprecated .*', - PendingDeprecationWarning, - ) - distname, version, distid = platform.linux_distribution() - - self.assertEqual(distname, 'Fedora') - self.assertEqual(version, '19') - self.assertEqual(distid, 'Schr\xf6dinger\u2019s Cat') - - -class DeprecationTest(unittest.TestCase): - - def test_dist_deprecation(self): - with self.assertWarns(DeprecationWarning) as cm: - platform.dist() - self.assertEqual(str(cm.warning), - 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5') - - def test_linux_distribution_deprecation(self): - with self.assertWarns(DeprecationWarning) as cm: - platform.linux_distribution() - self.assertEqual(str(cm.warning), - 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5') - if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 36580d55b9e..71380797748 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -181,22 +181,6 @@ def asn1time(cert_time): return cert_time -# Issue #9415: Ubuntu hijacks their OpenSSL and forcefully disables SSLv2 -def skip_if_broken_ubuntu_ssl(func): - if hasattr(ssl, 'PROTOCOL_SSLv2'): - @functools.wraps(func) - def f(*args, **kwargs): - try: - ssl.SSLContext(ssl.PROTOCOL_SSLv2) - except ssl.SSLError: - if (ssl.OPENSSL_VERSION_INFO == (0, 9, 8, 15, 15) and - platform.linux_distribution() == ('debian', 'squeeze/sid', '')): - raise unittest.SkipTest("Patched Ubuntu OpenSSL breaks behaviour") - return func(*args, **kwargs) - return f - else: - return func - needs_sni = unittest.skipUnless(ssl.HAS_SNI, "SNI support needed for this test") @@ -975,7 +959,6 @@ class BasicSocketTests(unittest.TestCase): class ContextTests(unittest.TestCase): - @skip_if_broken_ubuntu_ssl def test_constructor(self): for protocol in PROTOCOLS: ssl.SSLContext(protocol) @@ -984,7 +967,6 @@ class ContextTests(unittest.TestCase): self.assertRaises(ValueError, ssl.SSLContext, -1) self.assertRaises(ValueError, ssl.SSLContext, 42) - @skip_if_broken_ubuntu_ssl def test_protocol(self): for proto in PROTOCOLS: ctx = ssl.SSLContext(proto) @@ -1018,7 +1000,6 @@ class ContextTests(unittest.TestCase): self.assertIn('AES256-GCM-SHA384', names) self.assertIn('AES128-GCM-SHA256', names) - @skip_if_broken_ubuntu_ssl def test_options(self): ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) # OP_ALL | OP_NO_SSLv2 | OP_NO_SSLv3 is the default value @@ -1333,7 +1314,6 @@ class ContextTests(unittest.TestCase): with self.assertRaises(ssl.SSLError) as cm: ctx.load_dh_params(CERTFILE) - @skip_if_broken_ubuntu_ssl def test_session_stats(self): for proto in PROTOCOLS: ctx = ssl.SSLContext(proto) @@ -2554,7 +2534,6 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success, class ThreadedTests(unittest.TestCase): - @skip_if_broken_ubuntu_ssl def test_echo(self): """Basic test of an SSL client connecting to a server""" if support.verbose: @@ -2923,7 +2902,6 @@ class ThreadedTests(unittest.TestCase): self.assertIn(msg, repr(e)) self.assertIn('certificate verify failed', repr(e)) - @skip_if_broken_ubuntu_ssl @unittest.skipUnless(hasattr(ssl, 'PROTOCOL_SSLv2'), "OpenSSL is compiled without SSLv2 support") def test_protocol_sslv2(self): @@ -2947,7 +2925,6 @@ class ThreadedTests(unittest.TestCase): try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_TLS, False, client_options=ssl.OP_NO_TLSv1) - @skip_if_broken_ubuntu_ssl def test_PROTOCOL_TLS(self): """Connecting to an SSLv23 server with various client options""" if support.verbose: @@ -2987,7 +2964,6 @@ class ThreadedTests(unittest.TestCase): server_options=ssl.OP_NO_TLSv1) - @skip_if_broken_ubuntu_ssl @unittest.skipUnless(hasattr(ssl, 'PROTOCOL_SSLv3'), "OpenSSL is compiled without SSLv3 support") def test_protocol_sslv3(self): @@ -3007,7 +2983,6 @@ class ThreadedTests(unittest.TestCase): try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLS, False, client_options=ssl.OP_NO_SSLv2) - @skip_if_broken_ubuntu_ssl def test_protocol_tlsv1(self): """Connecting to a TLSv1 server with various client options""" if support.verbose: @@ -3022,7 +2997,6 @@ class ThreadedTests(unittest.TestCase): try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLS, False, client_options=ssl.OP_NO_TLSv1) - @skip_if_broken_ubuntu_ssl @unittest.skipUnless(hasattr(ssl, "PROTOCOL_TLSv1_1"), "TLS version 1.1 not supported.") def test_protocol_tlsv1_1(self): @@ -3042,7 +3016,6 @@ class ThreadedTests(unittest.TestCase): try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1, False) try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_1, False) - @skip_if_broken_ubuntu_ssl @unittest.skipUnless(hasattr(ssl, "PROTOCOL_TLSv1_2"), "TLS version 1.2 not supported.") def test_protocol_tlsv1_2(self): @@ -4087,24 +4060,16 @@ def test_main(verbose=False): if support.verbose: import warnings plats = { - 'Linux': platform.linux_distribution, 'Mac': platform.mac_ver, 'Windows': platform.win32_ver, } - with warnings.catch_warnings(): - warnings.filterwarnings( - 'ignore', - r'dist\(\) and linux_distribution\(\) ' - 'functions are deprecated .*', - PendingDeprecationWarning, - ) - for name, func in plats.items(): - plat = func() - if plat and plat[0]: - plat = '%s %r' % (name, plat) - break - else: - plat = repr(platform.platform()) + for name, func in plats.items(): + plat = func() + if plat and plat[0]: + plat = '%s %r' % (name, plat) + break + else: + plat = repr(platform.platform()) print("test_ssl: testing with %r %r" % (ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)) print(" under %s" % plat) diff --git a/Misc/NEWS.d/next/Library/2018-05-15-13-49-13.bpo-28167.p4RdQt.rst b/Misc/NEWS.d/next/Library/2018-05-15-13-49-13.bpo-28167.p4RdQt.rst new file mode 100644 index 00000000000..0079c8a09ce --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-05-15-13-49-13.bpo-28167.p4RdQt.rst @@ -0,0 +1 @@ +Remove platform.linux_distribution, which was deprecated since 3.5.